]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9.1-3.11.1-201309221838.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.11.1-201309221838.patch
CommitLineData
4be55bd6
PK
1diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2index b89a739..79768fb 100644
3--- a/Documentation/dontdiff
4+++ b/Documentation/dontdiff
5@@ -2,9 +2,11 @@
6 *.aux
7 *.bin
8 *.bz2
9+*.c.[012]*.*
10 *.cis
11 *.cpio
12 *.csp
13+*.dbg
14 *.dsp
15 *.dvi
16 *.elf
17@@ -14,6 +16,7 @@
18 *.gcov
19 *.gen.S
20 *.gif
21+*.gmo
22 *.grep
23 *.grp
24 *.gz
25@@ -48,14 +51,17 @@
26 *.tab.h
27 *.tex
28 *.ver
29+*.vim
30 *.xml
31 *.xz
32 *_MODULES
33+*_reg_safe.h
34 *_vga16.c
35 *~
36 \#*#
37 *.9
38-.*
39+.[^g]*
40+.gen*
41 .*.d
42 .mm
43 53c700_d.h
44@@ -69,9 +75,11 @@ Image
45 Module.markers
46 Module.symvers
47 PENDING
48+PERF*
49 SCCS
50 System.map*
51 TAGS
52+TRACEEVENT-CFLAGS
53 aconf
54 af_names.h
55 aic7*reg.h*
56@@ -80,6 +88,7 @@ aic7*seq.h*
57 aicasm
58 aicdb.h*
59 altivec*.c
60+ashldi3.S
61 asm-offsets.h
62 asm_offsets.h
63 autoconf.h*
64@@ -92,19 +101,24 @@ bounds.h
65 bsetup
66 btfixupprep
67 build
68+builtin-policy.h
69 bvmlinux
70 bzImage*
71 capability_names.h
72 capflags.c
73 classlist.h*
74+clut_vga16.c
75+common-cmds.h
76 comp*.log
77 compile.h*
78 conf
79 config
80 config-*
81 config_data.h*
82+config.c
83 config.mak
84 config.mak.autogen
85+config.tmp
86 conmakehash
87 consolemap_deftbl.c*
88 cpustr.h
89@@ -115,9 +129,11 @@ devlist.h*
90 dnotify_test
91 docproc
92 dslm
93+dtc-lexer.lex.c
94 elf2ecoff
95 elfconfig.h*
96 evergreen_reg_safe.h
97+exception_policy.conf
98 fixdep
99 flask.h
100 fore200e_mkfirm
101@@ -125,12 +141,15 @@ fore200e_pca_fw.c*
102 gconf
103 gconf.glade.h
104 gen-devlist
105+gen-kdb_cmds.c
106 gen_crc32table
107 gen_init_cpio
108 generated
109 genheaders
110 genksyms
111 *_gray256.c
112+hash
113+hid-example
114 hpet_example
115 hugepage-mmap
116 hugepage-shm
117@@ -145,14 +164,14 @@ int32.c
118 int4.c
119 int8.c
120 kallsyms
121-kconfig
122+kern_constants.h
123 keywords.c
124 ksym.c*
125 ksym.h*
126 kxgettext
127 lex.c
128 lex.*.c
129-linux
130+lib1funcs.S
131 logo_*.c
132 logo_*_clut224.c
133 logo_*_mono.c
134@@ -162,14 +181,15 @@ mach-types.h
135 machtypes.h
136 map
137 map_hugetlb
138-media
139 mconf
140+mdp
141 miboot*
142 mk_elfconfig
143 mkboot
144 mkbugboot
145 mkcpustr
146 mkdep
147+mkpiggy
148 mkprep
149 mkregtable
150 mktables
151@@ -185,6 +205,8 @@ oui.c*
152 page-types
153 parse.c
154 parse.h
155+parse-events*
156+pasyms.h
157 patches*
158 pca200e.bin
159 pca200e_ecd.bin2
160@@ -194,6 +216,7 @@ perf-archive
161 piggyback
162 piggy.gzip
163 piggy.S
164+pmu-*
165 pnmtologo
166 ppc_defs.h*
167 pss_boot.h
168@@ -203,7 +226,10 @@ r200_reg_safe.h
169 r300_reg_safe.h
170 r420_reg_safe.h
171 r600_reg_safe.h
172+realmode.lds
173+realmode.relocs
174 recordmcount
175+regdb.c
176 relocs
177 rlim_names.h
178 rn50_reg_safe.h
179@@ -213,8 +239,12 @@ series
180 setup
181 setup.bin
182 setup.elf
183+signing_key*
184+size_overflow_hash.h
185 sImage
186+slabinfo
187 sm_tbl*
188+sortextable
189 split-include
190 syscalltab.h
191 tables.c
192@@ -224,6 +254,7 @@ tftpboot.img
193 timeconst.h
194 times.h*
195 trix_boot.h
196+user_constants.h
197 utsrelease.h*
198 vdso-syms.lds
199 vdso.lds
200@@ -235,13 +266,17 @@ vdso32.lds
201 vdso32.so.dbg
202 vdso64.lds
203 vdso64.so.dbg
204+vdsox32.lds
205+vdsox32-syms.lds
206 version.h*
207 vmImage
208 vmlinux
209 vmlinux-*
210 vmlinux.aout
211 vmlinux.bin.all
212+vmlinux.bin.bz2
213 vmlinux.lds
214+vmlinux.relocs
215 vmlinuz
216 voffset.h
217 vsyscall.lds
218@@ -249,9 +284,12 @@ vsyscall_32.lds
219 wanxlfw.inc
220 uImage
221 unifdef
222+utsrelease.h
223 wakeup.bin
224 wakeup.elf
225 wakeup.lds
226+x509*
227 zImage*
228 zconf.hash.c
229+zconf.lex.c
230 zoffset.h
231diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
232index 7f9d4f5..6d1afd6 100644
233--- a/Documentation/kernel-parameters.txt
234+++ b/Documentation/kernel-parameters.txt
235@@ -976,6 +976,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
236 Format: <unsigned int> such that (rxsize & ~0x1fffc0) == 0.
237 Default: 1024
238
239+ grsec_proc_gid= [GRKERNSEC_PROC_USERGROUP] Chooses GID to
240+ ignore grsecurity's /proc restrictions
241+
242+
243 hashdist= [KNL,NUMA] Large hashes allocated during boot
244 are distributed across NUMA nodes. Defaults on
245 for 64-bit NUMA, off otherwise.
246@@ -1932,6 +1936,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
247 noexec=on: enable non-executable mappings (default)
248 noexec=off: disable non-executable mappings
249
250+ nopcid [X86-64]
251+ Disable PCID (Process-Context IDentifier) even if it
252+ is supported by the processor.
253+
254 nosmap [X86]
255 Disable SMAP (Supervisor Mode Access Prevention)
256 even if it is supported by processor.
257@@ -2199,6 +2207,25 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
258 the specified number of seconds. This is to be used if
259 your oopses keep scrolling off the screen.
260
261+ pax_nouderef [X86] disables UDEREF. Most likely needed under certain
262+ virtualization environments that don't cope well with the
263+ expand down segment used by UDEREF on X86-32 or the frequent
264+ page table updates on X86-64.
265+
266+ pax_sanitize_slab=
267+ 0/1 to disable/enable slab object sanitization (enabled by
268+ default).
269+
270+ pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
271+
272+ pax_extra_latent_entropy
273+ Enable a very simple form of latent entropy extraction
274+ from the first 4GB of memory as the bootmem allocator
275+ passes the memory pages to the buddy allocator.
276+
277+ pax_weakuderef [X86-64] enables the weaker but faster form of UDEREF
278+ when the processor supports PCID.
279+
280 pcbit= [HW,ISDN]
281
282 pcd. [PARIDE]
283diff --git a/Makefile b/Makefile
284index efd2396..682975d 100644
285--- a/Makefile
286+++ b/Makefile
287@@ -241,8 +241,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
288
289 HOSTCC = gcc
290 HOSTCXX = g++
291-HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
292-HOSTCXXFLAGS = -O2
293+HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
294+HOSTCFLAGS += $(call cc-option, -Wno-empty-body)
295+HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
296
297 # Decide whether to build built-in, modular, or both.
298 # Normally, just do built-in.
299@@ -414,8 +415,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
300 # Rules shared between *config targets and build targets
301
302 # Basic helpers built in scripts/
303-PHONY += scripts_basic
304-scripts_basic:
305+PHONY += scripts_basic gcc-plugins
306+scripts_basic: gcc-plugins
307 $(Q)$(MAKE) $(build)=scripts/basic
308 $(Q)rm -f .tmp_quiet_recordmcount
309
310@@ -576,6 +577,65 @@ else
311 KBUILD_CFLAGS += -O2
312 endif
313
314+ifndef DISABLE_PAX_PLUGINS
315+ifeq ($(call cc-ifversion, -ge, 0408, y), y)
316+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
317+else
318+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
319+endif
320+ifneq ($(PLUGINCC),)
321+ifdef CONFIG_PAX_CONSTIFY_PLUGIN
322+CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
323+endif
324+ifdef CONFIG_PAX_MEMORY_STACKLEAK
325+STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
326+STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
327+endif
328+ifdef CONFIG_KALLOCSTAT_PLUGIN
329+KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
330+endif
331+ifdef CONFIG_PAX_KERNEXEC_PLUGIN
332+KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
333+KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
334+KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
335+endif
336+ifdef CONFIG_CHECKER_PLUGIN
337+ifeq ($(call cc-ifversion, -ge, 0406, y), y)
338+CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
339+endif
340+endif
341+COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
342+ifdef CONFIG_PAX_SIZE_OVERFLOW
343+SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
344+endif
345+ifdef CONFIG_PAX_LATENT_ENTROPY
346+LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
347+endif
348+ifdef CONFIG_PAX_MEMORY_STRUCTLEAK
349+STRUCTLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/structleak_plugin.so -DSTRUCTLEAK_PLUGIN
350+endif
351+GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
352+GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
353+GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS) $(STRUCTLEAK_PLUGIN_CFLAGS)
354+GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
355+export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN
356+ifeq ($(KBUILD_EXTMOD),)
357+gcc-plugins:
358+ $(Q)$(MAKE) $(build)=tools/gcc
359+else
360+gcc-plugins: ;
361+endif
362+else
363+gcc-plugins:
364+ifeq ($(call cc-ifversion, -ge, 0405, y), y)
365+ $(error Your gcc installation does not support plugins. If the necessary headers for plugin support are missing, they should be installed. On Debian, apt-get install gcc-<ver>-plugin-dev. If you choose to ignore this error and lessen the improvements provided by this patch, re-run make with the DISABLE_PAX_PLUGINS=y argument.))
366+else
367+ $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
368+endif
369+ $(Q)echo "PAX_MEMORY_STACKLEAK, constification, PAX_LATENT_ENTROPY and other features will be less secure. PAX_SIZE_OVERFLOW will not be active."
370+endif
371+endif
372+
373 include $(srctree)/arch/$(SRCARCH)/Makefile
374
375 ifdef CONFIG_READABLE_ASM
376@@ -733,7 +793,7 @@ export mod_sign_cmd
377
378
379 ifeq ($(KBUILD_EXTMOD),)
380-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
381+core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
382
383 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
384 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
385@@ -782,6 +842,8 @@ endif
386
387 # The actual objects are generated when descending,
388 # make sure no implicit rule kicks in
389+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
390+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
391 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
392
393 # Handle descending into subdirectories listed in $(vmlinux-dirs)
394@@ -791,7 +853,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
395 # Error messages still appears in the original language
396
397 PHONY += $(vmlinux-dirs)
398-$(vmlinux-dirs): prepare scripts
399+$(vmlinux-dirs): gcc-plugins prepare scripts
400 $(Q)$(MAKE) $(build)=$@
401
402 # Store (new) KERNELRELEASE string in include/config/kernel.release
403@@ -835,6 +897,7 @@ prepare0: archprepare FORCE
404 $(Q)$(MAKE) $(build)=.
405
406 # All the preparing..
407+prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
408 prepare: prepare0
409
410 # Generate some files
411@@ -942,6 +1005,8 @@ all: modules
412 # using awk while concatenating to the final file.
413
414 PHONY += modules
415+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
416+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
417 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
418 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
419 @$(kecho) ' Building modules, stage 2.';
420@@ -957,7 +1022,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
421
422 # Target to prepare building external modules
423 PHONY += modules_prepare
424-modules_prepare: prepare scripts
425+modules_prepare: gcc-plugins prepare scripts
426
427 # Target to install modules
428 PHONY += modules_install
429@@ -1023,7 +1088,7 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
430 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
431 signing_key.priv signing_key.x509 x509.genkey \
432 extra_certificates signing_key.x509.keyid \
433- signing_key.x509.signer
434+ signing_key.x509.signer tools/gcc/size_overflow_hash.h
435
436 # clean - Delete most, but leave enough to build external modules
437 #
438@@ -1063,6 +1128,7 @@ distclean: mrproper
439 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
440 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
441 -o -name '.*.rej' \
442+ -o -name '.*.rej' -o -name '*.so' \
443 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
444 -type f -print | xargs rm -f
445
446@@ -1224,6 +1290,8 @@ PHONY += $(module-dirs) modules
447 $(module-dirs): crmodverdir $(objtree)/Module.symvers
448 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
449
450+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
451+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
452 modules: $(module-dirs)
453 @$(kecho) ' Building modules, stage 2.';
454 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
455@@ -1363,17 +1431,21 @@ else
456 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
457 endif
458
459-%.s: %.c prepare scripts FORCE
460+%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
461+%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
462+%.s: %.c gcc-plugins prepare scripts FORCE
463 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
464 %.i: %.c prepare scripts FORCE
465 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
466-%.o: %.c prepare scripts FORCE
467+%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
468+%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
469+%.o: %.c gcc-plugins prepare scripts FORCE
470 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
471 %.lst: %.c prepare scripts FORCE
472 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
473-%.s: %.S prepare scripts FORCE
474+%.s: %.S gcc-plugins prepare scripts FORCE
475 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
476-%.o: %.S prepare scripts FORCE
477+%.o: %.S gcc-plugins prepare scripts FORCE
478 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
479 %.symtypes: %.c prepare scripts FORCE
480 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
481@@ -1383,11 +1455,15 @@ endif
482 $(cmd_crmodverdir)
483 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
484 $(build)=$(build-dir)
485-%/: prepare scripts FORCE
486+%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
487+%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
488+%/: gcc-plugins prepare scripts FORCE
489 $(cmd_crmodverdir)
490 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
491 $(build)=$(build-dir)
492-%.ko: prepare scripts FORCE
493+%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
494+%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
495+%.ko: gcc-plugins prepare scripts FORCE
496 $(cmd_crmodverdir)
497 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
498 $(build)=$(build-dir) $(@:.ko=.o)
499diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
500index 78b03ef..da28a51 100644
501--- a/arch/alpha/include/asm/atomic.h
502+++ b/arch/alpha/include/asm/atomic.h
503@@ -292,6 +292,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
504 #define atomic_dec(v) atomic_sub(1,(v))
505 #define atomic64_dec(v) atomic64_sub(1,(v))
506
507+#define atomic64_read_unchecked(v) atomic64_read(v)
508+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
509+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
510+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
511+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
512+#define atomic64_inc_unchecked(v) atomic64_inc(v)
513+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
514+#define atomic64_dec_unchecked(v) atomic64_dec(v)
515+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
516+
517 #define smp_mb__before_atomic_dec() smp_mb()
518 #define smp_mb__after_atomic_dec() smp_mb()
519 #define smp_mb__before_atomic_inc() smp_mb()
520diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
521index ad368a9..fbe0f25 100644
522--- a/arch/alpha/include/asm/cache.h
523+++ b/arch/alpha/include/asm/cache.h
524@@ -4,19 +4,19 @@
525 #ifndef __ARCH_ALPHA_CACHE_H
526 #define __ARCH_ALPHA_CACHE_H
527
528+#include <linux/const.h>
529
530 /* Bytes per L1 (data) cache line. */
531 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
532-# define L1_CACHE_BYTES 64
533 # define L1_CACHE_SHIFT 6
534 #else
535 /* Both EV4 and EV5 are write-through, read-allocate,
536 direct-mapped, physical.
537 */
538-# define L1_CACHE_BYTES 32
539 # define L1_CACHE_SHIFT 5
540 #endif
541
542+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
543 #define SMP_CACHE_BYTES L1_CACHE_BYTES
544
545 #endif
546diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
547index 968d999..d36b2df 100644
548--- a/arch/alpha/include/asm/elf.h
549+++ b/arch/alpha/include/asm/elf.h
550@@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
551
552 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
553
554+#ifdef CONFIG_PAX_ASLR
555+#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
556+
557+#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
558+#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
559+#endif
560+
561 /* $0 is set by ld.so to a pointer to a function which might be
562 registered using atexit. This provides a mean for the dynamic
563 linker to call DT_FINI functions for shared libraries that have
564diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
565index bc2a0da..8ad11ee 100644
566--- a/arch/alpha/include/asm/pgalloc.h
567+++ b/arch/alpha/include/asm/pgalloc.h
568@@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
569 pgd_set(pgd, pmd);
570 }
571
572+static inline void
573+pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
574+{
575+ pgd_populate(mm, pgd, pmd);
576+}
577+
578 extern pgd_t *pgd_alloc(struct mm_struct *mm);
579
580 static inline void
581diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
582index d8f9b7e..f6222fa 100644
583--- a/arch/alpha/include/asm/pgtable.h
584+++ b/arch/alpha/include/asm/pgtable.h
585@@ -102,6 +102,17 @@ struct vm_area_struct;
586 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
587 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
588 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
589+
590+#ifdef CONFIG_PAX_PAGEEXEC
591+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
592+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
593+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
594+#else
595+# define PAGE_SHARED_NOEXEC PAGE_SHARED
596+# define PAGE_COPY_NOEXEC PAGE_COPY
597+# define PAGE_READONLY_NOEXEC PAGE_READONLY
598+#endif
599+
600 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
601
602 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
603diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
604index 2fd00b7..cfd5069 100644
605--- a/arch/alpha/kernel/module.c
606+++ b/arch/alpha/kernel/module.c
607@@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
608
609 /* The small sections were sorted to the end of the segment.
610 The following should definitely cover them. */
611- gp = (u64)me->module_core + me->core_size - 0x8000;
612+ gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
613 got = sechdrs[me->arch.gotsecindex].sh_addr;
614
615 for (i = 0; i < n; i++) {
616diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
617index 1402fcc..0b1abd2 100644
618--- a/arch/alpha/kernel/osf_sys.c
619+++ b/arch/alpha/kernel/osf_sys.c
620@@ -1298,10 +1298,11 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
621 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
622
623 static unsigned long
624-arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
625- unsigned long limit)
626+arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
627+ unsigned long limit, unsigned long flags)
628 {
629 struct vm_unmapped_area_info info;
630+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
631
632 info.flags = 0;
633 info.length = len;
634@@ -1309,6 +1310,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
635 info.high_limit = limit;
636 info.align_mask = 0;
637 info.align_offset = 0;
638+ info.threadstack_offset = offset;
639 return vm_unmapped_area(&info);
640 }
641
642@@ -1341,20 +1343,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
643 merely specific addresses, but regions of memory -- perhaps
644 this feature should be incorporated into all ports? */
645
646+#ifdef CONFIG_PAX_RANDMMAP
647+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
648+#endif
649+
650 if (addr) {
651- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
652+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
653 if (addr != (unsigned long) -ENOMEM)
654 return addr;
655 }
656
657 /* Next, try allocating at TASK_UNMAPPED_BASE. */
658- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
659- len, limit);
660+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
661+
662 if (addr != (unsigned long) -ENOMEM)
663 return addr;
664
665 /* Finally, try allocating in low memory. */
666- addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
667+ addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
668
669 return addr;
670 }
671diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
672index 0c4132d..88f0d53 100644
673--- a/arch/alpha/mm/fault.c
674+++ b/arch/alpha/mm/fault.c
675@@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
676 __reload_thread(pcb);
677 }
678
679+#ifdef CONFIG_PAX_PAGEEXEC
680+/*
681+ * PaX: decide what to do with offenders (regs->pc = fault address)
682+ *
683+ * returns 1 when task should be killed
684+ * 2 when patched PLT trampoline was detected
685+ * 3 when unpatched PLT trampoline was detected
686+ */
687+static int pax_handle_fetch_fault(struct pt_regs *regs)
688+{
689+
690+#ifdef CONFIG_PAX_EMUPLT
691+ int err;
692+
693+ do { /* PaX: patched PLT emulation #1 */
694+ unsigned int ldah, ldq, jmp;
695+
696+ err = get_user(ldah, (unsigned int *)regs->pc);
697+ err |= get_user(ldq, (unsigned int *)(regs->pc+4));
698+ err |= get_user(jmp, (unsigned int *)(regs->pc+8));
699+
700+ if (err)
701+ break;
702+
703+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
704+ (ldq & 0xFFFF0000U) == 0xA77B0000U &&
705+ jmp == 0x6BFB0000U)
706+ {
707+ unsigned long r27, addr;
708+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
709+ unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
710+
711+ addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
712+ err = get_user(r27, (unsigned long *)addr);
713+ if (err)
714+ break;
715+
716+ regs->r27 = r27;
717+ regs->pc = r27;
718+ return 2;
719+ }
720+ } while (0);
721+
722+ do { /* PaX: patched PLT emulation #2 */
723+ unsigned int ldah, lda, br;
724+
725+ err = get_user(ldah, (unsigned int *)regs->pc);
726+ err |= get_user(lda, (unsigned int *)(regs->pc+4));
727+ err |= get_user(br, (unsigned int *)(regs->pc+8));
728+
729+ if (err)
730+ break;
731+
732+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
733+ (lda & 0xFFFF0000U) == 0xA77B0000U &&
734+ (br & 0xFFE00000U) == 0xC3E00000U)
735+ {
736+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
737+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
738+ unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
739+
740+ regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
741+ regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
742+ return 2;
743+ }
744+ } while (0);
745+
746+ do { /* PaX: unpatched PLT emulation */
747+ unsigned int br;
748+
749+ err = get_user(br, (unsigned int *)regs->pc);
750+
751+ if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
752+ unsigned int br2, ldq, nop, jmp;
753+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
754+
755+ addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
756+ err = get_user(br2, (unsigned int *)addr);
757+ err |= get_user(ldq, (unsigned int *)(addr+4));
758+ err |= get_user(nop, (unsigned int *)(addr+8));
759+ err |= get_user(jmp, (unsigned int *)(addr+12));
760+ err |= get_user(resolver, (unsigned long *)(addr+16));
761+
762+ if (err)
763+ break;
764+
765+ if (br2 == 0xC3600000U &&
766+ ldq == 0xA77B000CU &&
767+ nop == 0x47FF041FU &&
768+ jmp == 0x6B7B0000U)
769+ {
770+ regs->r28 = regs->pc+4;
771+ regs->r27 = addr+16;
772+ regs->pc = resolver;
773+ return 3;
774+ }
775+ }
776+ } while (0);
777+#endif
778+
779+ return 1;
780+}
781+
782+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
783+{
784+ unsigned long i;
785+
786+ printk(KERN_ERR "PAX: bytes at PC: ");
787+ for (i = 0; i < 5; i++) {
788+ unsigned int c;
789+ if (get_user(c, (unsigned int *)pc+i))
790+ printk(KERN_CONT "???????? ");
791+ else
792+ printk(KERN_CONT "%08x ", c);
793+ }
794+ printk("\n");
795+}
796+#endif
797
798 /*
799 * This routine handles page faults. It determines the address,
800@@ -133,8 +251,29 @@ retry:
801 good_area:
802 si_code = SEGV_ACCERR;
803 if (cause < 0) {
804- if (!(vma->vm_flags & VM_EXEC))
805+ if (!(vma->vm_flags & VM_EXEC)) {
806+
807+#ifdef CONFIG_PAX_PAGEEXEC
808+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
809+ goto bad_area;
810+
811+ up_read(&mm->mmap_sem);
812+ switch (pax_handle_fetch_fault(regs)) {
813+
814+#ifdef CONFIG_PAX_EMUPLT
815+ case 2:
816+ case 3:
817+ return;
818+#endif
819+
820+ }
821+ pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
822+ do_group_exit(SIGKILL);
823+#else
824 goto bad_area;
825+#endif
826+
827+ }
828 } else if (!cause) {
829 /* Allow reads even for write-only mappings */
830 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
831diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
832index 43594d5..da71e62 100644
833--- a/arch/arm/Kconfig
834+++ b/arch/arm/Kconfig
835@@ -1791,7 +1791,7 @@ config ALIGNMENT_TRAP
836
837 config UACCESS_WITH_MEMCPY
838 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
839- depends on MMU
840+ depends on MMU && !PAX_MEMORY_UDEREF
841 default y if CPU_FEROCEON
842 help
843 Implement faster copy_to_user and clear_user methods for CPU
844diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
845index da1c77d..2ee6056 100644
846--- a/arch/arm/include/asm/atomic.h
847+++ b/arch/arm/include/asm/atomic.h
848@@ -17,17 +17,35 @@
849 #include <asm/barrier.h>
850 #include <asm/cmpxchg.h>
851
852+#ifdef CONFIG_GENERIC_ATOMIC64
853+#include <asm-generic/atomic64.h>
854+#endif
855+
856 #define ATOMIC_INIT(i) { (i) }
857
858 #ifdef __KERNEL__
859
860+#define _ASM_EXTABLE(from, to) \
861+" .pushsection __ex_table,\"a\"\n"\
862+" .align 3\n" \
863+" .long " #from ", " #to"\n" \
864+" .popsection"
865+
866 /*
867 * On ARM, ordinary assignment (str instruction) doesn't clear the local
868 * strex/ldrex monitor on some implementations. The reason we can use it for
869 * atomic_set() is the clrex or dummy strex done on every exception return.
870 */
871 #define atomic_read(v) (*(volatile int *)&(v)->counter)
872+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
873+{
874+ return v->counter;
875+}
876 #define atomic_set(v,i) (((v)->counter) = (i))
877+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
878+{
879+ v->counter = i;
880+}
881
882 #if __LINUX_ARM_ARCH__ >= 6
883
884@@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
885 int result;
886
887 __asm__ __volatile__("@ atomic_add\n"
888+"1: ldrex %1, [%3]\n"
889+" adds %0, %1, %4\n"
890+
891+#ifdef CONFIG_PAX_REFCOUNT
892+" bvc 3f\n"
893+"2: bkpt 0xf103\n"
894+"3:\n"
895+#endif
896+
897+" strex %1, %0, [%3]\n"
898+" teq %1, #0\n"
899+" bne 1b"
900+
901+#ifdef CONFIG_PAX_REFCOUNT
902+"\n4:\n"
903+ _ASM_EXTABLE(2b, 4b)
904+#endif
905+
906+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
907+ : "r" (&v->counter), "Ir" (i)
908+ : "cc");
909+}
910+
911+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
912+{
913+ unsigned long tmp;
914+ int result;
915+
916+ __asm__ __volatile__("@ atomic_add_unchecked\n"
917 "1: ldrex %0, [%3]\n"
918 " add %0, %0, %4\n"
919 " strex %1, %0, [%3]\n"
920@@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
921 smp_mb();
922
923 __asm__ __volatile__("@ atomic_add_return\n"
924+"1: ldrex %1, [%3]\n"
925+" adds %0, %1, %4\n"
926+
927+#ifdef CONFIG_PAX_REFCOUNT
928+" bvc 3f\n"
929+" mov %0, %1\n"
930+"2: bkpt 0xf103\n"
931+"3:\n"
932+#endif
933+
934+" strex %1, %0, [%3]\n"
935+" teq %1, #0\n"
936+" bne 1b"
937+
938+#ifdef CONFIG_PAX_REFCOUNT
939+"\n4:\n"
940+ _ASM_EXTABLE(2b, 4b)
941+#endif
942+
943+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
944+ : "r" (&v->counter), "Ir" (i)
945+ : "cc");
946+
947+ smp_mb();
948+
949+ return result;
950+}
951+
952+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
953+{
954+ unsigned long tmp;
955+ int result;
956+
957+ smp_mb();
958+
959+ __asm__ __volatile__("@ atomic_add_return_unchecked\n"
960 "1: ldrex %0, [%3]\n"
961 " add %0, %0, %4\n"
962 " strex %1, %0, [%3]\n"
963@@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
964 int result;
965
966 __asm__ __volatile__("@ atomic_sub\n"
967+"1: ldrex %1, [%3]\n"
968+" subs %0, %1, %4\n"
969+
970+#ifdef CONFIG_PAX_REFCOUNT
971+" bvc 3f\n"
972+"2: bkpt 0xf103\n"
973+"3:\n"
974+#endif
975+
976+" strex %1, %0, [%3]\n"
977+" teq %1, #0\n"
978+" bne 1b"
979+
980+#ifdef CONFIG_PAX_REFCOUNT
981+"\n4:\n"
982+ _ASM_EXTABLE(2b, 4b)
983+#endif
984+
985+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
986+ : "r" (&v->counter), "Ir" (i)
987+ : "cc");
988+}
989+
990+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
991+{
992+ unsigned long tmp;
993+ int result;
994+
995+ __asm__ __volatile__("@ atomic_sub_unchecked\n"
996 "1: ldrex %0, [%3]\n"
997 " sub %0, %0, %4\n"
998 " strex %1, %0, [%3]\n"
999@@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1000 smp_mb();
1001
1002 __asm__ __volatile__("@ atomic_sub_return\n"
1003-"1: ldrex %0, [%3]\n"
1004-" sub %0, %0, %4\n"
1005+"1: ldrex %1, [%3]\n"
1006+" subs %0, %1, %4\n"
1007+
1008+#ifdef CONFIG_PAX_REFCOUNT
1009+" bvc 3f\n"
1010+" mov %0, %1\n"
1011+"2: bkpt 0xf103\n"
1012+"3:\n"
1013+#endif
1014+
1015 " strex %1, %0, [%3]\n"
1016 " teq %1, #0\n"
1017 " bne 1b"
1018+
1019+#ifdef CONFIG_PAX_REFCOUNT
1020+"\n4:\n"
1021+ _ASM_EXTABLE(2b, 4b)
1022+#endif
1023+
1024 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1025 : "r" (&v->counter), "Ir" (i)
1026 : "cc");
1027@@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
1028 return oldval;
1029 }
1030
1031+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1032+{
1033+ unsigned long oldval, res;
1034+
1035+ smp_mb();
1036+
1037+ do {
1038+ __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1039+ "ldrex %1, [%3]\n"
1040+ "mov %0, #0\n"
1041+ "teq %1, %4\n"
1042+ "strexeq %0, %5, [%3]\n"
1043+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1044+ : "r" (&ptr->counter), "Ir" (old), "r" (new)
1045+ : "cc");
1046+ } while (res);
1047+
1048+ smp_mb();
1049+
1050+ return oldval;
1051+}
1052+
1053 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1054 {
1055 unsigned long tmp, tmp2;
1056@@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1057
1058 return val;
1059 }
1060+
1061+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1062+{
1063+ return atomic_add_return(i, v);
1064+}
1065+
1066 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1067+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1068+{
1069+ (void) atomic_add_return(i, v);
1070+}
1071
1072 static inline int atomic_sub_return(int i, atomic_t *v)
1073 {
1074@@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1075 return val;
1076 }
1077 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1078+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1079+{
1080+ (void) atomic_sub_return(i, v);
1081+}
1082
1083 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1084 {
1085@@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1086 return ret;
1087 }
1088
1089+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1090+{
1091+ return atomic_cmpxchg(v, old, new);
1092+}
1093+
1094 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1095 {
1096 unsigned long flags;
1097@@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1098 #endif /* __LINUX_ARM_ARCH__ */
1099
1100 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1101+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1102+{
1103+ return xchg(&v->counter, new);
1104+}
1105
1106 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1107 {
1108@@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1109 }
1110
1111 #define atomic_inc(v) atomic_add(1, v)
1112+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1113+{
1114+ atomic_add_unchecked(1, v);
1115+}
1116 #define atomic_dec(v) atomic_sub(1, v)
1117+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1118+{
1119+ atomic_sub_unchecked(1, v);
1120+}
1121
1122 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1123+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1124+{
1125+ return atomic_add_return_unchecked(1, v) == 0;
1126+}
1127 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1128 #define atomic_inc_return(v) (atomic_add_return(1, v))
1129+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1130+{
1131+ return atomic_add_return_unchecked(1, v);
1132+}
1133 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1134 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1135
1136@@ -241,6 +428,14 @@ typedef struct {
1137 u64 __aligned(8) counter;
1138 } atomic64_t;
1139
1140+#ifdef CONFIG_PAX_REFCOUNT
1141+typedef struct {
1142+ u64 __aligned(8) counter;
1143+} atomic64_unchecked_t;
1144+#else
1145+typedef atomic64_t atomic64_unchecked_t;
1146+#endif
1147+
1148 #define ATOMIC64_INIT(i) { (i) }
1149
1150 #ifdef CONFIG_ARM_LPAE
1151@@ -257,6 +452,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1152 return result;
1153 }
1154
1155+static inline u64 atomic64_read_unchecked(const atomic64_unchecked_t *v)
1156+{
1157+ u64 result;
1158+
1159+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1160+" ldrd %0, %H0, [%1]"
1161+ : "=&r" (result)
1162+ : "r" (&v->counter), "Qo" (v->counter)
1163+ );
1164+
1165+ return result;
1166+}
1167+
1168 static inline void atomic64_set(atomic64_t *v, u64 i)
1169 {
1170 __asm__ __volatile__("@ atomic64_set\n"
1171@@ -265,6 +473,15 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1172 : "r" (&v->counter), "r" (i)
1173 );
1174 }
1175+
1176+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1177+{
1178+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1179+" strd %2, %H2, [%1]"
1180+ : "=Qo" (v->counter)
1181+ : "r" (&v->counter), "r" (i)
1182+ );
1183+}
1184 #else
1185 static inline u64 atomic64_read(const atomic64_t *v)
1186 {
1187@@ -279,6 +496,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1188 return result;
1189 }
1190
1191+static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1192+{
1193+ u64 result;
1194+
1195+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1196+" ldrexd %0, %H0, [%1]"
1197+ : "=&r" (result)
1198+ : "r" (&v->counter), "Qo" (v->counter)
1199+ );
1200+
1201+ return result;
1202+}
1203+
1204 static inline void atomic64_set(atomic64_t *v, u64 i)
1205 {
1206 u64 tmp;
1207@@ -292,6 +522,21 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1208 : "r" (&v->counter), "r" (i)
1209 : "cc");
1210 }
1211+
1212+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1213+{
1214+ u64 tmp;
1215+
1216+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1217+"1: ldrexd %0, %H0, [%2]\n"
1218+" strexd %0, %3, %H3, [%2]\n"
1219+" teq %0, #0\n"
1220+" bne 1b"
1221+ : "=&r" (tmp), "=Qo" (v->counter)
1222+ : "r" (&v->counter), "r" (i)
1223+ : "cc");
1224+}
1225+
1226 #endif
1227
1228 static inline void atomic64_add(u64 i, atomic64_t *v)
1229@@ -302,6 +547,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1230 __asm__ __volatile__("@ atomic64_add\n"
1231 "1: ldrexd %0, %H0, [%3]\n"
1232 " adds %0, %0, %4\n"
1233+" adcs %H0, %H0, %H4\n"
1234+
1235+#ifdef CONFIG_PAX_REFCOUNT
1236+" bvc 3f\n"
1237+"2: bkpt 0xf103\n"
1238+"3:\n"
1239+#endif
1240+
1241+" strexd %1, %0, %H0, [%3]\n"
1242+" teq %1, #0\n"
1243+" bne 1b"
1244+
1245+#ifdef CONFIG_PAX_REFCOUNT
1246+"\n4:\n"
1247+ _ASM_EXTABLE(2b, 4b)
1248+#endif
1249+
1250+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1251+ : "r" (&v->counter), "r" (i)
1252+ : "cc");
1253+}
1254+
1255+static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1256+{
1257+ u64 result;
1258+ unsigned long tmp;
1259+
1260+ __asm__ __volatile__("@ atomic64_add_unchecked\n"
1261+"1: ldrexd %0, %H0, [%3]\n"
1262+" adds %0, %0, %4\n"
1263 " adc %H0, %H0, %H4\n"
1264 " strexd %1, %0, %H0, [%3]\n"
1265 " teq %1, #0\n"
1266@@ -313,12 +588,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1267
1268 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1269 {
1270- u64 result;
1271- unsigned long tmp;
1272+ u64 result, tmp;
1273
1274 smp_mb();
1275
1276 __asm__ __volatile__("@ atomic64_add_return\n"
1277+"1: ldrexd %1, %H1, [%3]\n"
1278+" adds %0, %1, %4\n"
1279+" adcs %H0, %H1, %H4\n"
1280+
1281+#ifdef CONFIG_PAX_REFCOUNT
1282+" bvc 3f\n"
1283+" mov %0, %1\n"
1284+" mov %H0, %H1\n"
1285+"2: bkpt 0xf103\n"
1286+"3:\n"
1287+#endif
1288+
1289+" strexd %1, %0, %H0, [%3]\n"
1290+" teq %1, #0\n"
1291+" bne 1b"
1292+
1293+#ifdef CONFIG_PAX_REFCOUNT
1294+"\n4:\n"
1295+ _ASM_EXTABLE(2b, 4b)
1296+#endif
1297+
1298+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1299+ : "r" (&v->counter), "r" (i)
1300+ : "cc");
1301+
1302+ smp_mb();
1303+
1304+ return result;
1305+}
1306+
1307+static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1308+{
1309+ u64 result;
1310+ unsigned long tmp;
1311+
1312+ smp_mb();
1313+
1314+ __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1315 "1: ldrexd %0, %H0, [%3]\n"
1316 " adds %0, %0, %4\n"
1317 " adc %H0, %H0, %H4\n"
1318@@ -342,6 +654,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1319 __asm__ __volatile__("@ atomic64_sub\n"
1320 "1: ldrexd %0, %H0, [%3]\n"
1321 " subs %0, %0, %4\n"
1322+" sbcs %H0, %H0, %H4\n"
1323+
1324+#ifdef CONFIG_PAX_REFCOUNT
1325+" bvc 3f\n"
1326+"2: bkpt 0xf103\n"
1327+"3:\n"
1328+#endif
1329+
1330+" strexd %1, %0, %H0, [%3]\n"
1331+" teq %1, #0\n"
1332+" bne 1b"
1333+
1334+#ifdef CONFIG_PAX_REFCOUNT
1335+"\n4:\n"
1336+ _ASM_EXTABLE(2b, 4b)
1337+#endif
1338+
1339+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1340+ : "r" (&v->counter), "r" (i)
1341+ : "cc");
1342+}
1343+
1344+static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1345+{
1346+ u64 result;
1347+ unsigned long tmp;
1348+
1349+ __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1350+"1: ldrexd %0, %H0, [%3]\n"
1351+" subs %0, %0, %4\n"
1352 " sbc %H0, %H0, %H4\n"
1353 " strexd %1, %0, %H0, [%3]\n"
1354 " teq %1, #0\n"
1355@@ -353,18 +695,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1356
1357 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1358 {
1359- u64 result;
1360- unsigned long tmp;
1361+ u64 result, tmp;
1362
1363 smp_mb();
1364
1365 __asm__ __volatile__("@ atomic64_sub_return\n"
1366-"1: ldrexd %0, %H0, [%3]\n"
1367-" subs %0, %0, %4\n"
1368-" sbc %H0, %H0, %H4\n"
1369+"1: ldrexd %1, %H1, [%3]\n"
1370+" subs %0, %1, %4\n"
1371+" sbcs %H0, %H1, %H4\n"
1372+
1373+#ifdef CONFIG_PAX_REFCOUNT
1374+" bvc 3f\n"
1375+" mov %0, %1\n"
1376+" mov %H0, %H1\n"
1377+"2: bkpt 0xf103\n"
1378+"3:\n"
1379+#endif
1380+
1381 " strexd %1, %0, %H0, [%3]\n"
1382 " teq %1, #0\n"
1383 " bne 1b"
1384+
1385+#ifdef CONFIG_PAX_REFCOUNT
1386+"\n4:\n"
1387+ _ASM_EXTABLE(2b, 4b)
1388+#endif
1389+
1390 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1391 : "r" (&v->counter), "r" (i)
1392 : "cc");
1393@@ -398,6 +754,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1394 return oldval;
1395 }
1396
1397+static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1398+{
1399+ u64 oldval;
1400+ unsigned long res;
1401+
1402+ smp_mb();
1403+
1404+ do {
1405+ __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1406+ "ldrexd %1, %H1, [%3]\n"
1407+ "mov %0, #0\n"
1408+ "teq %1, %4\n"
1409+ "teqeq %H1, %H4\n"
1410+ "strexdeq %0, %5, %H5, [%3]"
1411+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1412+ : "r" (&ptr->counter), "r" (old), "r" (new)
1413+ : "cc");
1414+ } while (res);
1415+
1416+ smp_mb();
1417+
1418+ return oldval;
1419+}
1420+
1421 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1422 {
1423 u64 result;
1424@@ -421,21 +801,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1425
1426 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1427 {
1428- u64 result;
1429- unsigned long tmp;
1430+ u64 result, tmp;
1431
1432 smp_mb();
1433
1434 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1435-"1: ldrexd %0, %H0, [%3]\n"
1436-" subs %0, %0, #1\n"
1437-" sbc %H0, %H0, #0\n"
1438+"1: ldrexd %1, %H1, [%3]\n"
1439+" subs %0, %1, #1\n"
1440+" sbcs %H0, %H1, #0\n"
1441+
1442+#ifdef CONFIG_PAX_REFCOUNT
1443+" bvc 3f\n"
1444+" mov %0, %1\n"
1445+" mov %H0, %H1\n"
1446+"2: bkpt 0xf103\n"
1447+"3:\n"
1448+#endif
1449+
1450 " teq %H0, #0\n"
1451-" bmi 2f\n"
1452+" bmi 4f\n"
1453 " strexd %1, %0, %H0, [%3]\n"
1454 " teq %1, #0\n"
1455 " bne 1b\n"
1456-"2:"
1457+"4:\n"
1458+
1459+#ifdef CONFIG_PAX_REFCOUNT
1460+ _ASM_EXTABLE(2b, 4b)
1461+#endif
1462+
1463 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1464 : "r" (&v->counter)
1465 : "cc");
1466@@ -458,13 +851,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1467 " teq %0, %5\n"
1468 " teqeq %H0, %H5\n"
1469 " moveq %1, #0\n"
1470-" beq 2f\n"
1471+" beq 4f\n"
1472 " adds %0, %0, %6\n"
1473-" adc %H0, %H0, %H6\n"
1474+" adcs %H0, %H0, %H6\n"
1475+
1476+#ifdef CONFIG_PAX_REFCOUNT
1477+" bvc 3f\n"
1478+"2: bkpt 0xf103\n"
1479+"3:\n"
1480+#endif
1481+
1482 " strexd %2, %0, %H0, [%4]\n"
1483 " teq %2, #0\n"
1484 " bne 1b\n"
1485-"2:"
1486+"4:\n"
1487+
1488+#ifdef CONFIG_PAX_REFCOUNT
1489+ _ASM_EXTABLE(2b, 4b)
1490+#endif
1491+
1492 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1493 : "r" (&v->counter), "r" (u), "r" (a)
1494 : "cc");
1495@@ -477,10 +882,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1496
1497 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1498 #define atomic64_inc(v) atomic64_add(1LL, (v))
1499+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1500 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1501+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1502 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1503 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1504 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1505+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1506 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1507 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1508 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1509diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1510index 75fe66b..ba3dee4 100644
1511--- a/arch/arm/include/asm/cache.h
1512+++ b/arch/arm/include/asm/cache.h
1513@@ -4,8 +4,10 @@
1514 #ifndef __ASMARM_CACHE_H
1515 #define __ASMARM_CACHE_H
1516
1517+#include <linux/const.h>
1518+
1519 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1520-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1521+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1522
1523 /*
1524 * Memory returned by kmalloc() may be used for DMA, so we must make
1525@@ -24,5 +26,6 @@
1526 #endif
1527
1528 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1529+#define __read_only __attribute__ ((__section__(".data..read_only")))
1530
1531 #endif
1532diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1533index 17d0ae8..014e350 100644
1534--- a/arch/arm/include/asm/cacheflush.h
1535+++ b/arch/arm/include/asm/cacheflush.h
1536@@ -116,7 +116,7 @@ struct cpu_cache_fns {
1537 void (*dma_unmap_area)(const void *, size_t, int);
1538
1539 void (*dma_flush_range)(const void *, const void *);
1540-};
1541+} __no_const;
1542
1543 /*
1544 * Select the calling method
1545diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1546index 6dcc164..b14d917 100644
1547--- a/arch/arm/include/asm/checksum.h
1548+++ b/arch/arm/include/asm/checksum.h
1549@@ -37,7 +37,19 @@ __wsum
1550 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1551
1552 __wsum
1553-csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1554+__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1555+
1556+static inline __wsum
1557+csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1558+{
1559+ __wsum ret;
1560+ pax_open_userland();
1561+ ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1562+ pax_close_userland();
1563+ return ret;
1564+}
1565+
1566+
1567
1568 /*
1569 * Fold a partial checksum without adding pseudo headers
1570diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1571index 4f009c1..466c59b 100644
1572--- a/arch/arm/include/asm/cmpxchg.h
1573+++ b/arch/arm/include/asm/cmpxchg.h
1574@@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1575
1576 #define xchg(ptr,x) \
1577 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1578+#define xchg_unchecked(ptr,x) \
1579+ ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1580
1581 #include <asm-generic/cmpxchg-local.h>
1582
1583diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1584index 6ddbe44..b5e38b1 100644
1585--- a/arch/arm/include/asm/domain.h
1586+++ b/arch/arm/include/asm/domain.h
1587@@ -48,18 +48,37 @@
1588 * Domain types
1589 */
1590 #define DOMAIN_NOACCESS 0
1591-#define DOMAIN_CLIENT 1
1592 #ifdef CONFIG_CPU_USE_DOMAINS
1593+#define DOMAIN_USERCLIENT 1
1594+#define DOMAIN_KERNELCLIENT 1
1595 #define DOMAIN_MANAGER 3
1596+#define DOMAIN_VECTORS DOMAIN_USER
1597 #else
1598+
1599+#ifdef CONFIG_PAX_KERNEXEC
1600 #define DOMAIN_MANAGER 1
1601+#define DOMAIN_KERNEXEC 3
1602+#else
1603+#define DOMAIN_MANAGER 1
1604+#endif
1605+
1606+#ifdef CONFIG_PAX_MEMORY_UDEREF
1607+#define DOMAIN_USERCLIENT 0
1608+#define DOMAIN_UDEREF 1
1609+#define DOMAIN_VECTORS DOMAIN_KERNEL
1610+#else
1611+#define DOMAIN_USERCLIENT 1
1612+#define DOMAIN_VECTORS DOMAIN_USER
1613+#endif
1614+#define DOMAIN_KERNELCLIENT 1
1615+
1616 #endif
1617
1618 #define domain_val(dom,type) ((type) << (2*(dom)))
1619
1620 #ifndef __ASSEMBLY__
1621
1622-#ifdef CONFIG_CPU_USE_DOMAINS
1623+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1624 static inline void set_domain(unsigned val)
1625 {
1626 asm volatile(
1627@@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1628 isb();
1629 }
1630
1631-#define modify_domain(dom,type) \
1632- do { \
1633- struct thread_info *thread = current_thread_info(); \
1634- unsigned int domain = thread->cpu_domain; \
1635- domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1636- thread->cpu_domain = domain | domain_val(dom, type); \
1637- set_domain(thread->cpu_domain); \
1638- } while (0)
1639-
1640+extern void modify_domain(unsigned int dom, unsigned int type);
1641 #else
1642 static inline void set_domain(unsigned val) { }
1643 static inline void modify_domain(unsigned dom, unsigned type) { }
1644diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1645index 56211f2..17e8a25 100644
1646--- a/arch/arm/include/asm/elf.h
1647+++ b/arch/arm/include/asm/elf.h
1648@@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1649 the loader. We need to make sure that it is out of the way of the program
1650 that it will "exec", and that there is sufficient room for the brk. */
1651
1652-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1653+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1654+
1655+#ifdef CONFIG_PAX_ASLR
1656+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1657+
1658+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1659+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1660+#endif
1661
1662 /* When the program starts, a1 contains a pointer to a function to be
1663 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1664@@ -126,10 +133,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1665 extern void elf_set_personality(const struct elf32_hdr *);
1666 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1667
1668-struct mm_struct;
1669-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1670-#define arch_randomize_brk arch_randomize_brk
1671-
1672 #ifdef CONFIG_MMU
1673 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1674 struct linux_binprm;
1675diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1676index de53547..52b9a28 100644
1677--- a/arch/arm/include/asm/fncpy.h
1678+++ b/arch/arm/include/asm/fncpy.h
1679@@ -81,7 +81,9 @@
1680 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1681 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1682 \
1683+ pax_open_kernel(); \
1684 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1685+ pax_close_kernel(); \
1686 flush_icache_range((unsigned long)(dest_buf), \
1687 (unsigned long)(dest_buf) + (size)); \
1688 \
1689diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1690index e42cf59..7b94b8f 100644
1691--- a/arch/arm/include/asm/futex.h
1692+++ b/arch/arm/include/asm/futex.h
1693@@ -50,6 +50,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1694 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1695 return -EFAULT;
1696
1697+ pax_open_userland();
1698+
1699 smp_mb();
1700 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1701 "1: ldrex %1, [%4]\n"
1702@@ -65,6 +67,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1703 : "cc", "memory");
1704 smp_mb();
1705
1706+ pax_close_userland();
1707+
1708 *uval = val;
1709 return ret;
1710 }
1711@@ -95,6 +99,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1712 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1713 return -EFAULT;
1714
1715+ pax_open_userland();
1716+
1717 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1718 "1: " TUSER(ldr) " %1, [%4]\n"
1719 " teq %1, %2\n"
1720@@ -105,6 +111,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1721 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1722 : "cc", "memory");
1723
1724+ pax_close_userland();
1725+
1726 *uval = val;
1727 return ret;
1728 }
1729@@ -127,6 +135,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1730 return -EFAULT;
1731
1732 pagefault_disable(); /* implies preempt_disable() */
1733+ pax_open_userland();
1734
1735 switch (op) {
1736 case FUTEX_OP_SET:
1737@@ -148,6 +157,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1738 ret = -ENOSYS;
1739 }
1740
1741+ pax_close_userland();
1742 pagefault_enable(); /* subsumes preempt_enable() */
1743
1744 if (!ret) {
1745diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1746index 83eb2f7..ed77159 100644
1747--- a/arch/arm/include/asm/kmap_types.h
1748+++ b/arch/arm/include/asm/kmap_types.h
1749@@ -4,6 +4,6 @@
1750 /*
1751 * This is the "bare minimum". AIO seems to require this.
1752 */
1753-#define KM_TYPE_NR 16
1754+#define KM_TYPE_NR 17
1755
1756 #endif
1757diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1758index 9e614a1..3302cca 100644
1759--- a/arch/arm/include/asm/mach/dma.h
1760+++ b/arch/arm/include/asm/mach/dma.h
1761@@ -22,7 +22,7 @@ struct dma_ops {
1762 int (*residue)(unsigned int, dma_t *); /* optional */
1763 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1764 const char *type;
1765-};
1766+} __do_const;
1767
1768 struct dma_struct {
1769 void *addr; /* single DMA address */
1770diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1771index 2fe141f..192dc01 100644
1772--- a/arch/arm/include/asm/mach/map.h
1773+++ b/arch/arm/include/asm/mach/map.h
1774@@ -27,13 +27,16 @@ struct map_desc {
1775 #define MT_MINICLEAN 6
1776 #define MT_LOW_VECTORS 7
1777 #define MT_HIGH_VECTORS 8
1778-#define MT_MEMORY 9
1779+#define MT_MEMORY_RWX 9
1780 #define MT_ROM 10
1781-#define MT_MEMORY_NONCACHED 11
1782+#define MT_MEMORY_NONCACHED_RX 11
1783 #define MT_MEMORY_DTCM 12
1784 #define MT_MEMORY_ITCM 13
1785 #define MT_MEMORY_SO 14
1786 #define MT_MEMORY_DMA_READY 15
1787+#define MT_MEMORY_RW 16
1788+#define MT_MEMORY_RX 17
1789+#define MT_MEMORY_NONCACHED_RW 18
1790
1791 #ifdef CONFIG_MMU
1792 extern void iotable_init(struct map_desc *, int);
1793diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1794index 12f71a1..04e063c 100644
1795--- a/arch/arm/include/asm/outercache.h
1796+++ b/arch/arm/include/asm/outercache.h
1797@@ -35,7 +35,7 @@ struct outer_cache_fns {
1798 #endif
1799 void (*set_debug)(unsigned long);
1800 void (*resume)(void);
1801-};
1802+} __no_const;
1803
1804 #ifdef CONFIG_OUTER_CACHE
1805
1806diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1807index 4355f0e..c229913 100644
1808--- a/arch/arm/include/asm/page.h
1809+++ b/arch/arm/include/asm/page.h
1810@@ -114,7 +114,7 @@ struct cpu_user_fns {
1811 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1812 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1813 unsigned long vaddr, struct vm_area_struct *vma);
1814-};
1815+} __no_const;
1816
1817 #ifdef MULTI_USER
1818 extern struct cpu_user_fns cpu_user;
1819diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1820index 943504f..c37a730 100644
1821--- a/arch/arm/include/asm/pgalloc.h
1822+++ b/arch/arm/include/asm/pgalloc.h
1823@@ -17,6 +17,7 @@
1824 #include <asm/processor.h>
1825 #include <asm/cacheflush.h>
1826 #include <asm/tlbflush.h>
1827+#include <asm/system_info.h>
1828
1829 #define check_pgt_cache() do { } while (0)
1830
1831@@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1832 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1833 }
1834
1835+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1836+{
1837+ pud_populate(mm, pud, pmd);
1838+}
1839+
1840 #else /* !CONFIG_ARM_LPAE */
1841
1842 /*
1843@@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1844 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1845 #define pmd_free(mm, pmd) do { } while (0)
1846 #define pud_populate(mm,pmd,pte) BUG()
1847+#define pud_populate_kernel(mm,pmd,pte) BUG()
1848
1849 #endif /* CONFIG_ARM_LPAE */
1850
1851@@ -126,6 +133,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1852 __free_page(pte);
1853 }
1854
1855+static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1856+{
1857+#ifdef CONFIG_ARM_LPAE
1858+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1859+#else
1860+ if (addr & SECTION_SIZE)
1861+ pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1862+ else
1863+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1864+#endif
1865+ flush_pmd_entry(pmdp);
1866+}
1867+
1868 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1869 pmdval_t prot)
1870 {
1871@@ -155,7 +175,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1872 static inline void
1873 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1874 {
1875- __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1876+ __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1877 }
1878 #define pmd_pgtable(pmd) pmd_page(pmd)
1879
1880diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1881index 5cfba15..f415e1a 100644
1882--- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1883+++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1884@@ -20,12 +20,15 @@
1885 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1886 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1887 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1888+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1889 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1890 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1891 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1892+
1893 /*
1894 * - section
1895 */
1896+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1897 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1898 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1899 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1900@@ -37,6 +40,7 @@
1901 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1902 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1903 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1904+#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1905
1906 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1907 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1908@@ -66,6 +70,7 @@
1909 * - extended small page/tiny page
1910 */
1911 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1912+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1913 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1914 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1915 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1916diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1917index f97ee02..cc9fe9e 100644
1918--- a/arch/arm/include/asm/pgtable-2level.h
1919+++ b/arch/arm/include/asm/pgtable-2level.h
1920@@ -126,6 +126,9 @@
1921 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1922 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1923
1924+/* Two-level page tables only have PXN in the PGD, not in the PTE. */
1925+#define L_PTE_PXN (_AT(pteval_t, 0))
1926+
1927 /*
1928 * These are the memory types, defined to be compatible with
1929 * pre-ARMv6 CPUs cacheable and bufferable bits: XXCB
1930diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1931index 626989f..9d67a33 100644
1932--- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1933+++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1934@@ -75,6 +75,7 @@
1935 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1936 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1937 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1938+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1939 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1940
1941 /*
1942diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1943index 5689c18..eea12f9 100644
1944--- a/arch/arm/include/asm/pgtable-3level.h
1945+++ b/arch/arm/include/asm/pgtable-3level.h
1946@@ -82,6 +82,7 @@
1947 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1948 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1949 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1950+#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1951 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1952 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
1953 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
1954@@ -95,6 +96,7 @@
1955 /*
1956 * To be used in assembly code with the upper page attributes.
1957 */
1958+#define L_PTE_PXN_HIGH (1 << (53 - 32))
1959 #define L_PTE_XN_HIGH (1 << (54 - 32))
1960 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
1961
1962diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
1963index 04aeb02..73b70dd 100644
1964--- a/arch/arm/include/asm/pgtable.h
1965+++ b/arch/arm/include/asm/pgtable.h
1966@@ -33,6 +33,9 @@
1967 #include <asm/pgtable-2level.h>
1968 #endif
1969
1970+#define ktla_ktva(addr) (addr)
1971+#define ktva_ktla(addr) (addr)
1972+
1973 /*
1974 * Just any arbitrary offset to the start of the vmalloc VM area: the
1975 * current 8MB value just means that there will be a 8MB "hole" after the
1976@@ -48,6 +51,9 @@
1977 #define LIBRARY_TEXT_START 0x0c000000
1978
1979 #ifndef __ASSEMBLY__
1980+extern pteval_t __supported_pte_mask;
1981+extern pmdval_t __supported_pmd_mask;
1982+
1983 extern void __pte_error(const char *file, int line, pte_t);
1984 extern void __pmd_error(const char *file, int line, pmd_t);
1985 extern void __pgd_error(const char *file, int line, pgd_t);
1986@@ -56,6 +62,48 @@ extern void __pgd_error(const char *file, int line, pgd_t);
1987 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
1988 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
1989
1990+#define __HAVE_ARCH_PAX_OPEN_KERNEL
1991+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
1992+
1993+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1994+#include <asm/domain.h>
1995+#include <linux/thread_info.h>
1996+#include <linux/preempt.h>
1997+
1998+static inline int test_domain(int domain, int domaintype)
1999+{
2000+ return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2001+}
2002+#endif
2003+
2004+#ifdef CONFIG_PAX_KERNEXEC
2005+static inline unsigned long pax_open_kernel(void) {
2006+#ifdef CONFIG_ARM_LPAE
2007+ /* TODO */
2008+#else
2009+ preempt_disable();
2010+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2011+ modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2012+#endif
2013+ return 0;
2014+}
2015+
2016+static inline unsigned long pax_close_kernel(void) {
2017+#ifdef CONFIG_ARM_LPAE
2018+ /* TODO */
2019+#else
2020+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2021+ /* DOMAIN_MANAGER = "client" under KERNEXEC */
2022+ modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2023+ preempt_enable_no_resched();
2024+#endif
2025+ return 0;
2026+}
2027+#else
2028+static inline unsigned long pax_open_kernel(void) { return 0; }
2029+static inline unsigned long pax_close_kernel(void) { return 0; }
2030+#endif
2031+
2032 /*
2033 * This is the lowest virtual address we can permit any user space
2034 * mapping to be mapped at. This is particularly important for
2035@@ -75,8 +123,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2036 /*
2037 * The pgprot_* and protection_map entries will be fixed up in runtime
2038 * to include the cachable and bufferable bits based on memory policy,
2039- * as well as any architecture dependent bits like global/ASID and SMP
2040- * shared mapping bits.
2041+ * as well as any architecture dependent bits like global/ASID, PXN,
2042+ * and SMP shared mapping bits.
2043 */
2044 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2045
2046@@ -260,7 +308,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2047 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2048 {
2049 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2050- L_PTE_NONE | L_PTE_VALID;
2051+ L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2052 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2053 return pte;
2054 }
2055diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h
2056index 5324c11..bcae5f0 100644
2057--- a/arch/arm/include/asm/proc-fns.h
2058+++ b/arch/arm/include/asm/proc-fns.h
2059@@ -75,7 +75,7 @@ extern struct processor {
2060 unsigned int suspend_size;
2061 void (*do_suspend)(void *);
2062 void (*do_resume)(void *);
2063-} processor;
2064+} __do_const processor;
2065
2066 #ifndef MULTI_CPU
2067 extern void cpu_proc_init(void);
2068diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2069index c4ae171..ea0c0c2 100644
2070--- a/arch/arm/include/asm/psci.h
2071+++ b/arch/arm/include/asm/psci.h
2072@@ -29,7 +29,7 @@ struct psci_operations {
2073 int (*cpu_off)(struct psci_power_state state);
2074 int (*cpu_on)(unsigned long cpuid, unsigned long entry_point);
2075 int (*migrate)(unsigned long cpuid);
2076-};
2077+} __no_const;
2078
2079 extern struct psci_operations psci_ops;
2080 extern struct smp_operations psci_smp_ops;
2081diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2082index a8cae71c..65dd797 100644
2083--- a/arch/arm/include/asm/smp.h
2084+++ b/arch/arm/include/asm/smp.h
2085@@ -110,7 +110,7 @@ struct smp_operations {
2086 int (*cpu_disable)(unsigned int cpu);
2087 #endif
2088 #endif
2089-};
2090+} __no_const;
2091
2092 /*
2093 * set platform specific SMP operations
2094diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2095index 2b8114f..8fe9bcf 100644
2096--- a/arch/arm/include/asm/thread_info.h
2097+++ b/arch/arm/include/asm/thread_info.h
2098@@ -77,9 +77,9 @@ struct thread_info {
2099 .flags = 0, \
2100 .preempt_count = INIT_PREEMPT_COUNT, \
2101 .addr_limit = KERNEL_DS, \
2102- .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2103- domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2104- domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2105+ .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2106+ domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2107+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2108 .restart_block = { \
2109 .fn = do_no_restart_syscall, \
2110 }, \
2111@@ -152,7 +152,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2112 #define TIF_SYSCALL_AUDIT 9
2113 #define TIF_SYSCALL_TRACEPOINT 10
2114 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2115-#define TIF_NOHZ 12 /* in adaptive nohz mode */
2116+/* within 8 bits of TIF_SYSCALL_TRACE
2117+ * to meet flexible second operand requirements
2118+ */
2119+#define TIF_GRSEC_SETXID 12
2120+#define TIF_NOHZ 13 /* in adaptive nohz mode */
2121 #define TIF_USING_IWMMXT 17
2122 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2123 #define TIF_RESTORE_SIGMASK 20
2124@@ -165,10 +169,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2125 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2126 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2127 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2128+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2129
2130 /* Checks for any syscall work in entry-common.S */
2131 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2132- _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2133+ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2134
2135 /*
2136 * Change these and you break ASM code in entry-common.S
2137diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2138index 7e1f760..de33b13 100644
2139--- a/arch/arm/include/asm/uaccess.h
2140+++ b/arch/arm/include/asm/uaccess.h
2141@@ -18,6 +18,7 @@
2142 #include <asm/domain.h>
2143 #include <asm/unified.h>
2144 #include <asm/compiler.h>
2145+#include <asm/pgtable.h>
2146
2147 #define VERIFY_READ 0
2148 #define VERIFY_WRITE 1
2149@@ -63,11 +64,38 @@ extern int __put_user_bad(void);
2150 static inline void set_fs(mm_segment_t fs)
2151 {
2152 current_thread_info()->addr_limit = fs;
2153- modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2154+ modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2155 }
2156
2157 #define segment_eq(a,b) ((a) == (b))
2158
2159+#define __HAVE_ARCH_PAX_OPEN_USERLAND
2160+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
2161+
2162+static inline void pax_open_userland(void)
2163+{
2164+
2165+#ifdef CONFIG_PAX_MEMORY_UDEREF
2166+ if (segment_eq(get_fs(), USER_DS)) {
2167+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2168+ modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2169+ }
2170+#endif
2171+
2172+}
2173+
2174+static inline void pax_close_userland(void)
2175+{
2176+
2177+#ifdef CONFIG_PAX_MEMORY_UDEREF
2178+ if (segment_eq(get_fs(), USER_DS)) {
2179+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2180+ modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2181+ }
2182+#endif
2183+
2184+}
2185+
2186 #define __addr_ok(addr) ({ \
2187 unsigned long flag; \
2188 __asm__("cmp %2, %0; movlo %0, #0" \
2189@@ -143,8 +171,12 @@ extern int __get_user_4(void *);
2190
2191 #define get_user(x,p) \
2192 ({ \
2193+ int __e; \
2194 might_fault(); \
2195- __get_user_check(x,p); \
2196+ pax_open_userland(); \
2197+ __e = __get_user_check(x,p); \
2198+ pax_close_userland(); \
2199+ __e; \
2200 })
2201
2202 extern int __put_user_1(void *, unsigned int);
2203@@ -188,8 +220,12 @@ extern int __put_user_8(void *, unsigned long long);
2204
2205 #define put_user(x,p) \
2206 ({ \
2207+ int __e; \
2208 might_fault(); \
2209- __put_user_check(x,p); \
2210+ pax_open_userland(); \
2211+ __e = __put_user_check(x,p); \
2212+ pax_close_userland(); \
2213+ __e; \
2214 })
2215
2216 #else /* CONFIG_MMU */
2217@@ -230,13 +266,17 @@ static inline void set_fs(mm_segment_t fs)
2218 #define __get_user(x,ptr) \
2219 ({ \
2220 long __gu_err = 0; \
2221+ pax_open_userland(); \
2222 __get_user_err((x),(ptr),__gu_err); \
2223+ pax_close_userland(); \
2224 __gu_err; \
2225 })
2226
2227 #define __get_user_error(x,ptr,err) \
2228 ({ \
2229+ pax_open_userland(); \
2230 __get_user_err((x),(ptr),err); \
2231+ pax_close_userland(); \
2232 (void) 0; \
2233 })
2234
2235@@ -312,13 +352,17 @@ do { \
2236 #define __put_user(x,ptr) \
2237 ({ \
2238 long __pu_err = 0; \
2239+ pax_open_userland(); \
2240 __put_user_err((x),(ptr),__pu_err); \
2241+ pax_close_userland(); \
2242 __pu_err; \
2243 })
2244
2245 #define __put_user_error(x,ptr,err) \
2246 ({ \
2247+ pax_open_userland(); \
2248 __put_user_err((x),(ptr),err); \
2249+ pax_close_userland(); \
2250 (void) 0; \
2251 })
2252
2253@@ -418,11 +462,44 @@ do { \
2254
2255
2256 #ifdef CONFIG_MMU
2257-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2258-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2259+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2260+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2261+
2262+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2263+{
2264+ unsigned long ret;
2265+
2266+ check_object_size(to, n, false);
2267+ pax_open_userland();
2268+ ret = ___copy_from_user(to, from, n);
2269+ pax_close_userland();
2270+ return ret;
2271+}
2272+
2273+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2274+{
2275+ unsigned long ret;
2276+
2277+ check_object_size(from, n, true);
2278+ pax_open_userland();
2279+ ret = ___copy_to_user(to, from, n);
2280+ pax_close_userland();
2281+ return ret;
2282+}
2283+
2284 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2285-extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2286+extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2287 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2288+
2289+static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2290+{
2291+ unsigned long ret;
2292+ pax_open_userland();
2293+ ret = ___clear_user(addr, n);
2294+ pax_close_userland();
2295+ return ret;
2296+}
2297+
2298 #else
2299 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2300 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2301@@ -431,6 +508,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2302
2303 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2304 {
2305+ if ((long)n < 0)
2306+ return n;
2307+
2308 if (access_ok(VERIFY_READ, from, n))
2309 n = __copy_from_user(to, from, n);
2310 else /* security hole - plug it */
2311@@ -440,6 +520,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2312
2313 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2314 {
2315+ if ((long)n < 0)
2316+ return n;
2317+
2318 if (access_ok(VERIFY_WRITE, to, n))
2319 n = __copy_to_user(to, from, n);
2320 return n;
2321diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2322index 5af0ed1..cea83883 100644
2323--- a/arch/arm/include/uapi/asm/ptrace.h
2324+++ b/arch/arm/include/uapi/asm/ptrace.h
2325@@ -92,7 +92,7 @@
2326 * ARMv7 groups of PSR bits
2327 */
2328 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2329-#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2330+#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2331 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2332 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2333
2334diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2335index 60d3b73..e5a0f22 100644
2336--- a/arch/arm/kernel/armksyms.c
2337+++ b/arch/arm/kernel/armksyms.c
2338@@ -53,7 +53,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2339
2340 /* networking */
2341 EXPORT_SYMBOL(csum_partial);
2342-EXPORT_SYMBOL(csum_partial_copy_from_user);
2343+EXPORT_SYMBOL(__csum_partial_copy_from_user);
2344 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2345 EXPORT_SYMBOL(__csum_ipv6_magic);
2346
2347@@ -89,9 +89,9 @@ EXPORT_SYMBOL(__memzero);
2348 #ifdef CONFIG_MMU
2349 EXPORT_SYMBOL(copy_page);
2350
2351-EXPORT_SYMBOL(__copy_from_user);
2352-EXPORT_SYMBOL(__copy_to_user);
2353-EXPORT_SYMBOL(__clear_user);
2354+EXPORT_SYMBOL(___copy_from_user);
2355+EXPORT_SYMBOL(___copy_to_user);
2356+EXPORT_SYMBOL(___clear_user);
2357
2358 EXPORT_SYMBOL(__get_user_1);
2359 EXPORT_SYMBOL(__get_user_2);
2360diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2361index 9cbe70c..a7b5e34 100644
2362--- a/arch/arm/kernel/entry-armv.S
2363+++ b/arch/arm/kernel/entry-armv.S
2364@@ -47,6 +47,87 @@
2365 9997:
2366 .endm
2367
2368+ .macro pax_enter_kernel
2369+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2370+ @ make aligned space for saved DACR
2371+ sub sp, sp, #8
2372+ @ save regs
2373+ stmdb sp!, {r1, r2}
2374+ @ read DACR from cpu_domain into r1
2375+ mov r2, sp
2376+ @ assume 8K pages, since we have to split the immediate in two
2377+ bic r2, r2, #(0x1fc0)
2378+ bic r2, r2, #(0x3f)
2379+ ldr r1, [r2, #TI_CPU_DOMAIN]
2380+ @ store old DACR on stack
2381+ str r1, [sp, #8]
2382+#ifdef CONFIG_PAX_KERNEXEC
2383+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2384+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2385+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2386+#endif
2387+#ifdef CONFIG_PAX_MEMORY_UDEREF
2388+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2389+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2390+#endif
2391+ @ write r1 to current_thread_info()->cpu_domain
2392+ str r1, [r2, #TI_CPU_DOMAIN]
2393+ @ write r1 to DACR
2394+ mcr p15, 0, r1, c3, c0, 0
2395+ @ instruction sync
2396+ instr_sync
2397+ @ restore regs
2398+ ldmia sp!, {r1, r2}
2399+#endif
2400+ .endm
2401+
2402+ .macro pax_open_userland
2403+#ifdef CONFIG_PAX_MEMORY_UDEREF
2404+ @ save regs
2405+ stmdb sp!, {r0, r1}
2406+ @ read DACR from cpu_domain into r1
2407+ mov r0, sp
2408+ @ assume 8K pages, since we have to split the immediate in two
2409+ bic r0, r0, #(0x1fc0)
2410+ bic r0, r0, #(0x3f)
2411+ ldr r1, [r0, #TI_CPU_DOMAIN]
2412+ @ set current DOMAIN_USER to DOMAIN_CLIENT
2413+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2414+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2415+ @ write r1 to current_thread_info()->cpu_domain
2416+ str r1, [r0, #TI_CPU_DOMAIN]
2417+ @ write r1 to DACR
2418+ mcr p15, 0, r1, c3, c0, 0
2419+ @ instruction sync
2420+ instr_sync
2421+ @ restore regs
2422+ ldmia sp!, {r0, r1}
2423+#endif
2424+ .endm
2425+
2426+ .macro pax_close_userland
2427+#ifdef CONFIG_PAX_MEMORY_UDEREF
2428+ @ save regs
2429+ stmdb sp!, {r0, r1}
2430+ @ read DACR from cpu_domain into r1
2431+ mov r0, sp
2432+ @ assume 8K pages, since we have to split the immediate in two
2433+ bic r0, r0, #(0x1fc0)
2434+ bic r0, r0, #(0x3f)
2435+ ldr r1, [r0, #TI_CPU_DOMAIN]
2436+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2437+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2438+ @ write r1 to current_thread_info()->cpu_domain
2439+ str r1, [r0, #TI_CPU_DOMAIN]
2440+ @ write r1 to DACR
2441+ mcr p15, 0, r1, c3, c0, 0
2442+ @ instruction sync
2443+ instr_sync
2444+ @ restore regs
2445+ ldmia sp!, {r0, r1}
2446+#endif
2447+ .endm
2448+
2449 .macro pabt_helper
2450 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2451 #ifdef MULTI_PABORT
2452@@ -89,11 +170,15 @@
2453 * Invalid mode handlers
2454 */
2455 .macro inv_entry, reason
2456+
2457+ pax_enter_kernel
2458+
2459 sub sp, sp, #S_FRAME_SIZE
2460 ARM( stmib sp, {r1 - lr} )
2461 THUMB( stmia sp, {r0 - r12} )
2462 THUMB( str sp, [sp, #S_SP] )
2463 THUMB( str lr, [sp, #S_LR] )
2464+
2465 mov r1, #\reason
2466 .endm
2467
2468@@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2469 .macro svc_entry, stack_hole=0
2470 UNWIND(.fnstart )
2471 UNWIND(.save {r0 - pc} )
2472+
2473+ pax_enter_kernel
2474+
2475 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2476+
2477 #ifdef CONFIG_THUMB2_KERNEL
2478 SPFIX( str r0, [sp] ) @ temporarily saved
2479 SPFIX( mov r0, sp )
2480@@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2481 ldmia r0, {r3 - r5}
2482 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2483 mov r6, #-1 @ "" "" "" ""
2484+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2485+ @ offset sp by 8 as done in pax_enter_kernel
2486+ add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2487+#else
2488 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2489+#endif
2490 SPFIX( addeq r2, r2, #4 )
2491 str r3, [sp, #-4]! @ save the "real" r0 copied
2492 @ from the exception stack
2493@@ -316,6 +410,9 @@ ENDPROC(__pabt_svc)
2494 .macro usr_entry
2495 UNWIND(.fnstart )
2496 UNWIND(.cantunwind ) @ don't unwind the user space
2497+
2498+ pax_enter_kernel_user
2499+
2500 sub sp, sp, #S_FRAME_SIZE
2501 ARM( stmib sp, {r1 - r12} )
2502 THUMB( stmia sp, {r0 - r12} )
2503@@ -415,7 +512,9 @@ __und_usr:
2504 tst r3, #PSR_T_BIT @ Thumb mode?
2505 bne __und_usr_thumb
2506 sub r4, r2, #4 @ ARM instr at LR - 4
2507+ pax_open_userland
2508 1: ldrt r0, [r4]
2509+ pax_close_userland
2510 #ifdef CONFIG_CPU_ENDIAN_BE8
2511 rev r0, r0 @ little endian instruction
2512 #endif
2513@@ -450,10 +549,14 @@ __und_usr_thumb:
2514 */
2515 .arch armv6t2
2516 #endif
2517+ pax_open_userland
2518 2: ldrht r5, [r4]
2519+ pax_close_userland
2520 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2521 blo __und_usr_fault_16 @ 16bit undefined instruction
2522+ pax_open_userland
2523 3: ldrht r0, [r2]
2524+ pax_close_userland
2525 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2526 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2527 orr r0, r0, r5, lsl #16
2528@@ -482,7 +585,8 @@ ENDPROC(__und_usr)
2529 */
2530 .pushsection .fixup, "ax"
2531 .align 2
2532-4: mov pc, r9
2533+4: pax_close_userland
2534+ mov pc, r9
2535 .popsection
2536 .pushsection __ex_table,"a"
2537 .long 1b, 4b
2538@@ -692,7 +796,7 @@ ENTRY(__switch_to)
2539 THUMB( str lr, [ip], #4 )
2540 ldr r4, [r2, #TI_TP_VALUE]
2541 ldr r5, [r2, #TI_TP_VALUE + 4]
2542-#ifdef CONFIG_CPU_USE_DOMAINS
2543+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2544 ldr r6, [r2, #TI_CPU_DOMAIN]
2545 #endif
2546 switch_tls r1, r4, r5, r3, r7
2547@@ -701,7 +805,7 @@ ENTRY(__switch_to)
2548 ldr r8, =__stack_chk_guard
2549 ldr r7, [r7, #TSK_STACK_CANARY]
2550 #endif
2551-#ifdef CONFIG_CPU_USE_DOMAINS
2552+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2553 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2554 #endif
2555 mov r5, r0
2556diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2557index 94104bf..e425391 100644
2558--- a/arch/arm/kernel/entry-common.S
2559+++ b/arch/arm/kernel/entry-common.S
2560@@ -10,18 +10,46 @@
2561
2562 #include <asm/unistd.h>
2563 #include <asm/ftrace.h>
2564+#include <asm/domain.h>
2565 #include <asm/unwind.h>
2566
2567+#include "entry-header.S"
2568+
2569 #ifdef CONFIG_NEED_RET_TO_USER
2570 #include <mach/entry-macro.S>
2571 #else
2572 .macro arch_ret_to_user, tmp1, tmp2
2573+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2574+ @ save regs
2575+ stmdb sp!, {r1, r2}
2576+ @ read DACR from cpu_domain into r1
2577+ mov r2, sp
2578+ @ assume 8K pages, since we have to split the immediate in two
2579+ bic r2, r2, #(0x1fc0)
2580+ bic r2, r2, #(0x3f)
2581+ ldr r1, [r2, #TI_CPU_DOMAIN]
2582+#ifdef CONFIG_PAX_KERNEXEC
2583+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2584+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2585+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2586+#endif
2587+#ifdef CONFIG_PAX_MEMORY_UDEREF
2588+ @ set current DOMAIN_USER to DOMAIN_UDEREF
2589+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2590+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2591+#endif
2592+ @ write r1 to current_thread_info()->cpu_domain
2593+ str r1, [r2, #TI_CPU_DOMAIN]
2594+ @ write r1 to DACR
2595+ mcr p15, 0, r1, c3, c0, 0
2596+ @ instruction sync
2597+ instr_sync
2598+ @ restore regs
2599+ ldmia sp!, {r1, r2}
2600+#endif
2601 .endm
2602 #endif
2603
2604-#include "entry-header.S"
2605-
2606-
2607 .align 5
2608 /*
2609 * This is the fast syscall return path. We do as little as
2610@@ -413,6 +441,12 @@ ENTRY(vector_swi)
2611 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
2612 #endif
2613
2614+ /*
2615+ * do this here to avoid a performance hit of wrapping the code above
2616+ * that directly dereferences userland to parse the SWI instruction
2617+ */
2618+ pax_enter_kernel_user
2619+
2620 adr tbl, sys_call_table @ load syscall table pointer
2621
2622 #if defined(CONFIG_OABI_COMPAT)
2623diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2624index de23a9b..94c37c4 100644
2625--- a/arch/arm/kernel/entry-header.S
2626+++ b/arch/arm/kernel/entry-header.S
2627@@ -184,6 +184,60 @@
2628 msr cpsr_c, \rtemp @ switch back to the SVC mode
2629 .endm
2630
2631+ .macro pax_enter_kernel_user
2632+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2633+ @ save regs
2634+ stmdb sp!, {r0, r1}
2635+ @ read DACR from cpu_domain into r1
2636+ mov r0, sp
2637+ @ assume 8K pages, since we have to split the immediate in two
2638+ bic r0, r0, #(0x1fc0)
2639+ bic r0, r0, #(0x3f)
2640+ ldr r1, [r0, #TI_CPU_DOMAIN]
2641+#ifdef CONFIG_PAX_MEMORY_UDEREF
2642+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2643+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2644+#endif
2645+#ifdef CONFIG_PAX_KERNEXEC
2646+ @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2647+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2648+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2649+#endif
2650+ @ write r1 to current_thread_info()->cpu_domain
2651+ str r1, [r0, #TI_CPU_DOMAIN]
2652+ @ write r1 to DACR
2653+ mcr p15, 0, r1, c3, c0, 0
2654+ @ instruction sync
2655+ instr_sync
2656+ @ restore regs
2657+ ldmia sp!, {r0, r1}
2658+#endif
2659+ .endm
2660+
2661+ .macro pax_exit_kernel
2662+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2663+ @ save regs
2664+ stmdb sp!, {r0, r1}
2665+ @ read old DACR from stack into r1
2666+ ldr r1, [sp, #(8 + S_SP)]
2667+ sub r1, r1, #8
2668+ ldr r1, [r1]
2669+
2670+ @ write r1 to current_thread_info()->cpu_domain
2671+ mov r0, sp
2672+ @ assume 8K pages, since we have to split the immediate in two
2673+ bic r0, r0, #(0x1fc0)
2674+ bic r0, r0, #(0x3f)
2675+ str r1, [r0, #TI_CPU_DOMAIN]
2676+ @ write r1 to DACR
2677+ mcr p15, 0, r1, c3, c0, 0
2678+ @ instruction sync
2679+ instr_sync
2680+ @ restore regs
2681+ ldmia sp!, {r0, r1}
2682+#endif
2683+ .endm
2684+
2685 #ifndef CONFIG_THUMB2_KERNEL
2686 .macro svc_exit, rpsr, irq = 0
2687 .if \irq != 0
2688@@ -203,6 +257,9 @@
2689 blne trace_hardirqs_off
2690 #endif
2691 .endif
2692+
2693+ pax_exit_kernel
2694+
2695 msr spsr_cxsf, \rpsr
2696 #if defined(CONFIG_CPU_V6)
2697 ldr r0, [sp]
2698@@ -266,6 +323,9 @@
2699 blne trace_hardirqs_off
2700 #endif
2701 .endif
2702+
2703+ pax_exit_kernel
2704+
2705 ldr lr, [sp, #S_SP] @ top of the stack
2706 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2707 clrex @ clear the exclusive monitor
2708diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2709index 918875d..cd5fa27 100644
2710--- a/arch/arm/kernel/fiq.c
2711+++ b/arch/arm/kernel/fiq.c
2712@@ -87,7 +87,10 @@ void set_fiq_handler(void *start, unsigned int length)
2713 void *base = vectors_page;
2714 unsigned offset = FIQ_OFFSET;
2715
2716+ pax_open_kernel();
2717 memcpy(base + offset, start, length);
2718+ pax_close_kernel();
2719+
2720 if (!cache_is_vipt_nonaliasing())
2721 flush_icache_range((unsigned long)base + offset, offset +
2722 length);
2723diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2724index 2c7cc1e..ab2e911 100644
2725--- a/arch/arm/kernel/head.S
2726+++ b/arch/arm/kernel/head.S
2727@@ -52,7 +52,9 @@
2728 .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
2729
2730 .macro pgtbl, rd, phys
2731- add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
2732+ mov \rd, #TEXT_OFFSET
2733+ sub \rd, #PG_DIR_SIZE
2734+ add \rd, \rd, \phys
2735 .endm
2736
2737 /*
2738@@ -432,7 +434,7 @@ __enable_mmu:
2739 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2740 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2741 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2742- domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2743+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2744 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2745 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2746 #endif
2747diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2748index 85c3fb6..b3068b1 100644
2749--- a/arch/arm/kernel/module.c
2750+++ b/arch/arm/kernel/module.c
2751@@ -37,12 +37,37 @@
2752 #endif
2753
2754 #ifdef CONFIG_MMU
2755-void *module_alloc(unsigned long size)
2756+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2757 {
2758+ if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2759+ return NULL;
2760 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2761- GFP_KERNEL, PAGE_KERNEL_EXEC, -1,
2762+ GFP_KERNEL, prot, -1,
2763 __builtin_return_address(0));
2764 }
2765+
2766+void *module_alloc(unsigned long size)
2767+{
2768+
2769+#ifdef CONFIG_PAX_KERNEXEC
2770+ return __module_alloc(size, PAGE_KERNEL);
2771+#else
2772+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2773+#endif
2774+
2775+}
2776+
2777+#ifdef CONFIG_PAX_KERNEXEC
2778+void module_free_exec(struct module *mod, void *module_region)
2779+{
2780+ module_free(mod, module_region);
2781+}
2782+
2783+void *module_alloc_exec(unsigned long size)
2784+{
2785+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2786+}
2787+#endif
2788 #endif
2789
2790 int
2791diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2792index 07314af..c46655c 100644
2793--- a/arch/arm/kernel/patch.c
2794+++ b/arch/arm/kernel/patch.c
2795@@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2796 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2797 int size;
2798
2799+ pax_open_kernel();
2800 if (thumb2 && __opcode_is_thumb16(insn)) {
2801 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2802 size = sizeof(u16);
2803@@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2804 *(u32 *)addr = insn;
2805 size = sizeof(u32);
2806 }
2807+ pax_close_kernel();
2808
2809 flush_icache_range((uintptr_t)(addr),
2810 (uintptr_t)(addr) + size);
2811diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2812index 94f6b05..efd7312 100644
2813--- a/arch/arm/kernel/process.c
2814+++ b/arch/arm/kernel/process.c
2815@@ -217,6 +217,7 @@ void machine_power_off(void)
2816
2817 if (pm_power_off)
2818 pm_power_off();
2819+ BUG();
2820 }
2821
2822 /*
2823@@ -230,7 +231,7 @@ void machine_power_off(void)
2824 * executing pre-reset code, and using RAM that the primary CPU's code wishes
2825 * to use. Implementing such co-ordination would be essentially impossible.
2826 */
2827-void machine_restart(char *cmd)
2828+__noreturn void machine_restart(char *cmd)
2829 {
2830 local_irq_disable();
2831 smp_send_stop();
2832@@ -253,8 +254,8 @@ void __show_regs(struct pt_regs *regs)
2833
2834 show_regs_print_info(KERN_DEFAULT);
2835
2836- print_symbol("PC is at %s\n", instruction_pointer(regs));
2837- print_symbol("LR is at %s\n", regs->ARM_lr);
2838+ printk("PC is at %pA\n", (void *)instruction_pointer(regs));
2839+ printk("LR is at %pA\n", (void *)regs->ARM_lr);
2840 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2841 "sp : %08lx ip : %08lx fp : %08lx\n",
2842 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2843@@ -422,12 +423,6 @@ unsigned long get_wchan(struct task_struct *p)
2844 return 0;
2845 }
2846
2847-unsigned long arch_randomize_brk(struct mm_struct *mm)
2848-{
2849- unsigned long range_end = mm->brk + 0x02000000;
2850- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2851-}
2852-
2853 #ifdef CONFIG_MMU
2854 #ifdef CONFIG_KUSER_HELPERS
2855 /*
2856@@ -443,7 +438,7 @@ static struct vm_area_struct gate_vma = {
2857
2858 static int __init gate_vma_init(void)
2859 {
2860- gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2861+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2862 return 0;
2863 }
2864 arch_initcall(gate_vma_init);
2865@@ -469,41 +464,16 @@ int in_gate_area_no_mm(unsigned long addr)
2866
2867 const char *arch_vma_name(struct vm_area_struct *vma)
2868 {
2869- return is_gate_vma(vma) ? "[vectors]" :
2870- (vma->vm_mm && vma->vm_start == vma->vm_mm->context.sigpage) ?
2871- "[sigpage]" : NULL;
2872+ return is_gate_vma(vma) ? "[vectors]" : NULL;
2873 }
2874
2875-static struct page *signal_page;
2876-extern struct page *get_signal_page(void);
2877-
2878 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
2879 {
2880 struct mm_struct *mm = current->mm;
2881- unsigned long addr;
2882- int ret;
2883-
2884- if (!signal_page)
2885- signal_page = get_signal_page();
2886- if (!signal_page)
2887- return -ENOMEM;
2888
2889 down_write(&mm->mmap_sem);
2890- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
2891- if (IS_ERR_VALUE(addr)) {
2892- ret = addr;
2893- goto up_fail;
2894- }
2895-
2896- ret = install_special_mapping(mm, addr, PAGE_SIZE,
2897- VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
2898- &signal_page);
2899-
2900- if (ret == 0)
2901- mm->context.sigpage = addr;
2902-
2903- up_fail:
2904+ mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
2905 up_write(&mm->mmap_sem);
2906- return ret;
2907+ return 0;
2908 }
2909 #endif
2910diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
2911index 4693188..4596c5e 100644
2912--- a/arch/arm/kernel/psci.c
2913+++ b/arch/arm/kernel/psci.c
2914@@ -24,7 +24,7 @@
2915 #include <asm/opcodes-virt.h>
2916 #include <asm/psci.h>
2917
2918-struct psci_operations psci_ops;
2919+struct psci_operations psci_ops __read_only;
2920
2921 static int (*invoke_psci_fn)(u32, u32, u32, u32);
2922
2923diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2924index 0dd3b79..e018f64 100644
2925--- a/arch/arm/kernel/ptrace.c
2926+++ b/arch/arm/kernel/ptrace.c
2927@@ -929,10 +929,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
2928 return current_thread_info()->syscall;
2929 }
2930
2931+#ifdef CONFIG_GRKERNSEC_SETXID
2932+extern void gr_delayed_cred_worker(void);
2933+#endif
2934+
2935 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
2936 {
2937 current_thread_info()->syscall = scno;
2938
2939+#ifdef CONFIG_GRKERNSEC_SETXID
2940+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2941+ gr_delayed_cred_worker();
2942+#endif
2943+
2944 /* Do the secure computing check first; failures should be fast. */
2945 if (secure_computing(scno) == -1)
2946 return -1;
2947diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2948index afc2489..6372bc8 100644
2949--- a/arch/arm/kernel/setup.c
2950+++ b/arch/arm/kernel/setup.c
2951@@ -98,21 +98,23 @@ EXPORT_SYMBOL(system_serial_high);
2952 unsigned int elf_hwcap __read_mostly;
2953 EXPORT_SYMBOL(elf_hwcap);
2954
2955+pteval_t __supported_pte_mask __read_only;
2956+pmdval_t __supported_pmd_mask __read_only;
2957
2958 #ifdef MULTI_CPU
2959-struct processor processor __read_mostly;
2960+struct processor processor;
2961 #endif
2962 #ifdef MULTI_TLB
2963-struct cpu_tlb_fns cpu_tlb __read_mostly;
2964+struct cpu_tlb_fns cpu_tlb __read_only;
2965 #endif
2966 #ifdef MULTI_USER
2967-struct cpu_user_fns cpu_user __read_mostly;
2968+struct cpu_user_fns cpu_user __read_only;
2969 #endif
2970 #ifdef MULTI_CACHE
2971-struct cpu_cache_fns cpu_cache __read_mostly;
2972+struct cpu_cache_fns cpu_cache __read_only;
2973 #endif
2974 #ifdef CONFIG_OUTER_CACHE
2975-struct outer_cache_fns outer_cache __read_mostly;
2976+struct outer_cache_fns outer_cache __read_only;
2977 EXPORT_SYMBOL(outer_cache);
2978 #endif
2979
2980@@ -245,9 +247,13 @@ static int __get_cpu_architecture(void)
2981 asm("mrc p15, 0, %0, c0, c1, 4"
2982 : "=r" (mmfr0));
2983 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
2984- (mmfr0 & 0x000000f0) >= 0x00000030)
2985+ (mmfr0 & 0x000000f0) >= 0x00000030) {
2986 cpu_arch = CPU_ARCH_ARMv7;
2987- else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2988+ if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
2989+ __supported_pte_mask |= L_PTE_PXN;
2990+ __supported_pmd_mask |= PMD_PXNTABLE;
2991+ }
2992+ } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2993 (mmfr0 & 0x000000f0) == 0x00000020)
2994 cpu_arch = CPU_ARCH_ARMv6;
2995 else
2996@@ -571,7 +577,7 @@ static void __init setup_processor(void)
2997 __cpu_architecture = __get_cpu_architecture();
2998
2999 #ifdef MULTI_CPU
3000- processor = *list->proc;
3001+ memcpy((void *)&processor, list->proc, sizeof processor);
3002 #endif
3003 #ifdef MULTI_TLB
3004 cpu_tlb = *list->tlb;
3005diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3006index ab33042..11248a8 100644
3007--- a/arch/arm/kernel/signal.c
3008+++ b/arch/arm/kernel/signal.c
3009@@ -45,8 +45,6 @@ static const unsigned long sigreturn_codes[7] = {
3010 MOV_R7_NR_RT_SIGRETURN, SWI_SYS_RT_SIGRETURN, SWI_THUMB_RT_SIGRETURN,
3011 };
3012
3013-static unsigned long signal_return_offset;
3014-
3015 #ifdef CONFIG_CRUNCH
3016 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3017 {
3018@@ -411,8 +409,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3019 * except when the MPU has protected the vectors
3020 * page from PL0
3021 */
3022- retcode = mm->context.sigpage + signal_return_offset +
3023- (idx << 2) + thumb;
3024+ retcode = mm->context.sigpage + (idx << 2) + thumb;
3025 } else
3026 #endif
3027 {
3028@@ -616,33 +613,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3029 } while (thread_flags & _TIF_WORK_MASK);
3030 return 0;
3031 }
3032-
3033-struct page *get_signal_page(void)
3034-{
3035- unsigned long ptr;
3036- unsigned offset;
3037- struct page *page;
3038- void *addr;
3039-
3040- page = alloc_pages(GFP_KERNEL, 0);
3041-
3042- if (!page)
3043- return NULL;
3044-
3045- addr = page_address(page);
3046-
3047- /* Give the signal return code some randomness */
3048- offset = 0x200 + (get_random_int() & 0x7fc);
3049- signal_return_offset = offset;
3050-
3051- /*
3052- * Copy signal return handlers into the vector page, and
3053- * set sigreturn to be a pointer to these.
3054- */
3055- memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3056-
3057- ptr = (unsigned long)addr + offset;
3058- flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3059-
3060- return page;
3061-}
3062diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3063index 2dc1934..ecf0e21 100644
3064--- a/arch/arm/kernel/smp.c
3065+++ b/arch/arm/kernel/smp.c
3066@@ -71,7 +71,7 @@ enum ipi_msg_type {
3067
3068 static DECLARE_COMPLETION(cpu_running);
3069
3070-static struct smp_operations smp_ops;
3071+static struct smp_operations smp_ops __read_only;
3072
3073 void __init smp_set_ops(struct smp_operations *ops)
3074 {
3075diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3076index ab517fc..9adf2fa 100644
3077--- a/arch/arm/kernel/traps.c
3078+++ b/arch/arm/kernel/traps.c
3079@@ -55,7 +55,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3080 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3081 {
3082 #ifdef CONFIG_KALLSYMS
3083- printk("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3084+ printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3085 #else
3086 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3087 #endif
3088@@ -257,6 +257,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3089 static int die_owner = -1;
3090 static unsigned int die_nest_count;
3091
3092+extern void gr_handle_kernel_exploit(void);
3093+
3094 static unsigned long oops_begin(void)
3095 {
3096 int cpu;
3097@@ -299,6 +301,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3098 panic("Fatal exception in interrupt");
3099 if (panic_on_oops)
3100 panic("Fatal exception");
3101+
3102+ gr_handle_kernel_exploit();
3103+
3104 if (signr)
3105 do_exit(signr);
3106 }
3107@@ -592,7 +597,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3108 * The user helper at 0xffff0fe0 must be used instead.
3109 * (see entry-armv.S for details)
3110 */
3111+ pax_open_kernel();
3112 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3113+ pax_close_kernel();
3114 }
3115 return 0;
3116
3117@@ -849,7 +856,11 @@ void __init early_trap_init(void *vectors_base)
3118 kuser_init(vectors_base);
3119
3120 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3121- modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3122+
3123+#ifndef CONFIG_PAX_MEMORY_UDEREF
3124+ modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3125+#endif
3126+
3127 #else /* ifndef CONFIG_CPU_V7M */
3128 /*
3129 * on V7-M there is no need to copy the vector table to a dedicated
3130diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3131index 7bcee5c..64c9c5f 100644
3132--- a/arch/arm/kernel/vmlinux.lds.S
3133+++ b/arch/arm/kernel/vmlinux.lds.S
3134@@ -8,7 +8,11 @@
3135 #include <asm/thread_info.h>
3136 #include <asm/memory.h>
3137 #include <asm/page.h>
3138-
3139+
3140+#ifdef CONFIG_PAX_KERNEXEC
3141+#include <asm/pgtable.h>
3142+#endif
3143+
3144 #define PROC_INFO \
3145 . = ALIGN(4); \
3146 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3147@@ -90,6 +94,11 @@ SECTIONS
3148 _text = .;
3149 HEAD_TEXT
3150 }
3151+
3152+#ifdef CONFIG_PAX_KERNEXEC
3153+ . = ALIGN(1<<SECTION_SHIFT);
3154+#endif
3155+
3156 .text : { /* Real text segment */
3157 _stext = .; /* Text and read-only data */
3158 __exception_text_start = .;
3159@@ -112,6 +121,8 @@ SECTIONS
3160 ARM_CPU_KEEP(PROC_INFO)
3161 }
3162
3163+ _etext = .; /* End of text section */
3164+
3165 RO_DATA(PAGE_SIZE)
3166
3167 . = ALIGN(4);
3168@@ -142,7 +153,9 @@ SECTIONS
3169
3170 NOTES
3171
3172- _etext = .; /* End of text and rodata section */
3173+#ifdef CONFIG_PAX_KERNEXEC
3174+ . = ALIGN(1<<SECTION_SHIFT);
3175+#endif
3176
3177 #ifndef CONFIG_XIP_KERNEL
3178 . = ALIGN(PAGE_SIZE);
3179@@ -220,6 +233,11 @@ SECTIONS
3180 . = PAGE_OFFSET + TEXT_OFFSET;
3181 #else
3182 __init_end = .;
3183+
3184+#ifdef CONFIG_PAX_KERNEXEC
3185+ . = ALIGN(1<<SECTION_SHIFT);
3186+#endif
3187+
3188 . = ALIGN(THREAD_SIZE);
3189 __data_loc = .;
3190 #endif
3191diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3192index 741f66a..8a5615c 100644
3193--- a/arch/arm/kvm/arm.c
3194+++ b/arch/arm/kvm/arm.c
3195@@ -56,7 +56,7 @@ static unsigned long hyp_default_vectors;
3196 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3197
3198 /* The VMID used in the VTTBR */
3199-static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3200+static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3201 static u8 kvm_next_vmid;
3202 static DEFINE_SPINLOCK(kvm_vmid_lock);
3203
3204@@ -392,7 +392,7 @@ void force_vm_exit(const cpumask_t *mask)
3205 */
3206 static bool need_new_vmid_gen(struct kvm *kvm)
3207 {
3208- return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3209+ return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3210 }
3211
3212 /**
3213@@ -425,7 +425,7 @@ static void update_vttbr(struct kvm *kvm)
3214
3215 /* First user of a new VMID generation? */
3216 if (unlikely(kvm_next_vmid == 0)) {
3217- atomic64_inc(&kvm_vmid_gen);
3218+ atomic64_inc_unchecked(&kvm_vmid_gen);
3219 kvm_next_vmid = 1;
3220
3221 /*
3222@@ -442,7 +442,7 @@ static void update_vttbr(struct kvm *kvm)
3223 kvm_call_hyp(__kvm_flush_vm_context);
3224 }
3225
3226- kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3227+ kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3228 kvm->arch.vmid = kvm_next_vmid;
3229 kvm_next_vmid++;
3230
3231diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3232index 14a0d98..7771a7d 100644
3233--- a/arch/arm/lib/clear_user.S
3234+++ b/arch/arm/lib/clear_user.S
3235@@ -12,14 +12,14 @@
3236
3237 .text
3238
3239-/* Prototype: int __clear_user(void *addr, size_t sz)
3240+/* Prototype: int ___clear_user(void *addr, size_t sz)
3241 * Purpose : clear some user memory
3242 * Params : addr - user memory address to clear
3243 * : sz - number of bytes to clear
3244 * Returns : number of bytes NOT cleared
3245 */
3246 ENTRY(__clear_user_std)
3247-WEAK(__clear_user)
3248+WEAK(___clear_user)
3249 stmfd sp!, {r1, lr}
3250 mov r2, #0
3251 cmp r1, #4
3252@@ -44,7 +44,7 @@ WEAK(__clear_user)
3253 USER( strnebt r2, [r0])
3254 mov r0, #0
3255 ldmfd sp!, {r1, pc}
3256-ENDPROC(__clear_user)
3257+ENDPROC(___clear_user)
3258 ENDPROC(__clear_user_std)
3259
3260 .pushsection .fixup,"ax"
3261diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3262index 66a477a..bee61d3 100644
3263--- a/arch/arm/lib/copy_from_user.S
3264+++ b/arch/arm/lib/copy_from_user.S
3265@@ -16,7 +16,7 @@
3266 /*
3267 * Prototype:
3268 *
3269- * size_t __copy_from_user(void *to, const void *from, size_t n)
3270+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
3271 *
3272 * Purpose:
3273 *
3274@@ -84,11 +84,11 @@
3275
3276 .text
3277
3278-ENTRY(__copy_from_user)
3279+ENTRY(___copy_from_user)
3280
3281 #include "copy_template.S"
3282
3283-ENDPROC(__copy_from_user)
3284+ENDPROC(___copy_from_user)
3285
3286 .pushsection .fixup,"ax"
3287 .align 0
3288diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3289index 6ee2f67..d1cce76 100644
3290--- a/arch/arm/lib/copy_page.S
3291+++ b/arch/arm/lib/copy_page.S
3292@@ -10,6 +10,7 @@
3293 * ASM optimised string functions
3294 */
3295 #include <linux/linkage.h>
3296+#include <linux/const.h>
3297 #include <asm/assembler.h>
3298 #include <asm/asm-offsets.h>
3299 #include <asm/cache.h>
3300diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3301index d066df6..df28194 100644
3302--- a/arch/arm/lib/copy_to_user.S
3303+++ b/arch/arm/lib/copy_to_user.S
3304@@ -16,7 +16,7 @@
3305 /*
3306 * Prototype:
3307 *
3308- * size_t __copy_to_user(void *to, const void *from, size_t n)
3309+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
3310 *
3311 * Purpose:
3312 *
3313@@ -88,11 +88,11 @@
3314 .text
3315
3316 ENTRY(__copy_to_user_std)
3317-WEAK(__copy_to_user)
3318+WEAK(___copy_to_user)
3319
3320 #include "copy_template.S"
3321
3322-ENDPROC(__copy_to_user)
3323+ENDPROC(___copy_to_user)
3324 ENDPROC(__copy_to_user_std)
3325
3326 .pushsection .fixup,"ax"
3327diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3328index 7d08b43..f7ca7ea 100644
3329--- a/arch/arm/lib/csumpartialcopyuser.S
3330+++ b/arch/arm/lib/csumpartialcopyuser.S
3331@@ -57,8 +57,8 @@
3332 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3333 */
3334
3335-#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3336-#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3337+#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3338+#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3339
3340 #include "csumpartialcopygeneric.S"
3341
3342diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3343index 5306de3..aed6d03 100644
3344--- a/arch/arm/lib/delay.c
3345+++ b/arch/arm/lib/delay.c
3346@@ -28,7 +28,7 @@
3347 /*
3348 * Default to the loop-based delay implementation.
3349 */
3350-struct arm_delay_ops arm_delay_ops = {
3351+struct arm_delay_ops arm_delay_ops __read_only = {
3352 .delay = __loop_delay,
3353 .const_udelay = __loop_const_udelay,
3354 .udelay = __loop_udelay,
3355diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3356index 025f742..a9e5b3b 100644
3357--- a/arch/arm/lib/uaccess_with_memcpy.c
3358+++ b/arch/arm/lib/uaccess_with_memcpy.c
3359@@ -104,7 +104,7 @@ out:
3360 }
3361
3362 unsigned long
3363-__copy_to_user(void __user *to, const void *from, unsigned long n)
3364+___copy_to_user(void __user *to, const void *from, unsigned long n)
3365 {
3366 /*
3367 * This test is stubbed out of the main function above to keep
3368@@ -155,7 +155,7 @@ out:
3369 return n;
3370 }
3371
3372-unsigned long __clear_user(void __user *addr, unsigned long n)
3373+unsigned long ___clear_user(void __user *addr, unsigned long n)
3374 {
3375 /* See rational for this in __copy_to_user() above. */
3376 if (n < 64)
3377diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3378index e9238b5..6ed904a 100644
3379--- a/arch/arm/mach-kirkwood/common.c
3380+++ b/arch/arm/mach-kirkwood/common.c
3381@@ -150,7 +150,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3382 clk_gate_ops.disable(hw);
3383 }
3384
3385-static struct clk_ops clk_gate_fn_ops;
3386+static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3387+{
3388+ return clk_gate_ops.is_enabled(hw);
3389+}
3390+
3391+static struct clk_ops clk_gate_fn_ops = {
3392+ .enable = clk_gate_fn_enable,
3393+ .disable = clk_gate_fn_disable,
3394+ .is_enabled = clk_gate_fn_is_enabled,
3395+};
3396
3397 static struct clk __init *clk_register_gate_fn(struct device *dev,
3398 const char *name,
3399@@ -184,14 +193,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3400 gate_fn->fn_en = fn_en;
3401 gate_fn->fn_dis = fn_dis;
3402
3403- /* ops is the gate ops, but with our enable/disable functions */
3404- if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3405- clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3406- clk_gate_fn_ops = clk_gate_ops;
3407- clk_gate_fn_ops.enable = clk_gate_fn_enable;
3408- clk_gate_fn_ops.disable = clk_gate_fn_disable;
3409- }
3410-
3411 clk = clk_register(dev, &gate_fn->gate.hw);
3412
3413 if (IS_ERR(clk))
3414diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3415index 827d1500..2885dc6 100644
3416--- a/arch/arm/mach-omap2/board-n8x0.c
3417+++ b/arch/arm/mach-omap2/board-n8x0.c
3418@@ -627,7 +627,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3419 }
3420 #endif
3421
3422-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3423+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3424 .late_init = n8x0_menelaus_late_init,
3425 };
3426
3427diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3428index f3fdd6a..3564800 100644
3429--- a/arch/arm/mach-omap2/gpmc.c
3430+++ b/arch/arm/mach-omap2/gpmc.c
3431@@ -148,7 +148,6 @@ struct omap3_gpmc_regs {
3432 };
3433
3434 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3435-static struct irq_chip gpmc_irq_chip;
3436 static unsigned gpmc_irq_start;
3437
3438 static struct resource gpmc_mem_root;
3439@@ -716,6 +715,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3440
3441 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3442
3443+static struct irq_chip gpmc_irq_chip = {
3444+ .name = "gpmc",
3445+ .irq_startup = gpmc_irq_noop_ret,
3446+ .irq_enable = gpmc_irq_enable,
3447+ .irq_disable = gpmc_irq_disable,
3448+ .irq_shutdown = gpmc_irq_noop,
3449+ .irq_ack = gpmc_irq_noop,
3450+ .irq_mask = gpmc_irq_noop,
3451+ .irq_unmask = gpmc_irq_noop,
3452+
3453+};
3454+
3455 static int gpmc_setup_irq(void)
3456 {
3457 int i;
3458@@ -730,15 +741,6 @@ static int gpmc_setup_irq(void)
3459 return gpmc_irq_start;
3460 }
3461
3462- gpmc_irq_chip.name = "gpmc";
3463- gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3464- gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3465- gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3466- gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3467- gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3468- gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3469- gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3470-
3471 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3472 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3473
3474diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3475index f991016..145ebeb 100644
3476--- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3477+++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3478@@ -84,7 +84,7 @@ struct cpu_pm_ops {
3479 int (*finish_suspend)(unsigned long cpu_state);
3480 void (*resume)(void);
3481 void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
3482-};
3483+} __no_const;
3484
3485 static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
3486 static struct powerdomain *mpuss_pd;
3487@@ -102,7 +102,7 @@ static void dummy_cpu_resume(void)
3488 static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
3489 {}
3490
3491-struct cpu_pm_ops omap_pm_ops = {
3492+static struct cpu_pm_ops omap_pm_ops __read_only = {
3493 .finish_suspend = default_finish_suspend,
3494 .resume = dummy_cpu_resume,
3495 .scu_prepare = dummy_scu_prepare,
3496diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3497index 813c615..ce467c6 100644
3498--- a/arch/arm/mach-omap2/omap-wakeupgen.c
3499+++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3500@@ -339,7 +339,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
3501 return NOTIFY_OK;
3502 }
3503
3504-static struct notifier_block __refdata irq_hotplug_notifier = {
3505+static struct notifier_block irq_hotplug_notifier = {
3506 .notifier_call = irq_cpu_hotplug_notify,
3507 };
3508
3509diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3510index f99f68e..e573e20 100644
3511--- a/arch/arm/mach-omap2/omap_device.c
3512+++ b/arch/arm/mach-omap2/omap_device.c
3513@@ -504,7 +504,7 @@ void omap_device_delete(struct omap_device *od)
3514 struct platform_device __init *omap_device_build(const char *pdev_name,
3515 int pdev_id,
3516 struct omap_hwmod *oh,
3517- void *pdata, int pdata_len)
3518+ const void *pdata, int pdata_len)
3519 {
3520 struct omap_hwmod *ohs[] = { oh };
3521
3522@@ -532,7 +532,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3523 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3524 int pdev_id,
3525 struct omap_hwmod **ohs,
3526- int oh_cnt, void *pdata,
3527+ int oh_cnt, const void *pdata,
3528 int pdata_len)
3529 {
3530 int ret = -ENOMEM;
3531diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3532index 17ca1ae..beba869 100644
3533--- a/arch/arm/mach-omap2/omap_device.h
3534+++ b/arch/arm/mach-omap2/omap_device.h
3535@@ -71,12 +71,12 @@ int omap_device_idle(struct platform_device *pdev);
3536 /* Core code interface */
3537
3538 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3539- struct omap_hwmod *oh, void *pdata,
3540+ struct omap_hwmod *oh, const void *pdata,
3541 int pdata_len);
3542
3543 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3544 struct omap_hwmod **oh, int oh_cnt,
3545- void *pdata, int pdata_len);
3546+ const void *pdata, int pdata_len);
3547
3548 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3549 struct omap_hwmod **ohs, int oh_cnt);
3550diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3551index 7f4db12..0243012 100644
3552--- a/arch/arm/mach-omap2/omap_hwmod.c
3553+++ b/arch/arm/mach-omap2/omap_hwmod.c
3554@@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3555 int (*init_clkdm)(struct omap_hwmod *oh);
3556 void (*update_context_lost)(struct omap_hwmod *oh);
3557 int (*get_context_lost)(struct omap_hwmod *oh);
3558-};
3559+} __no_const;
3560
3561 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3562-static struct omap_hwmod_soc_ops soc_ops;
3563+static struct omap_hwmod_soc_ops soc_ops __read_only;
3564
3565 /* omap_hwmod_list contains all registered struct omap_hwmods */
3566 static LIST_HEAD(omap_hwmod_list);
3567diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3568index d15c7bb..b2d1f0c 100644
3569--- a/arch/arm/mach-omap2/wd_timer.c
3570+++ b/arch/arm/mach-omap2/wd_timer.c
3571@@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3572 struct omap_hwmod *oh;
3573 char *oh_name = "wd_timer2";
3574 char *dev_name = "omap_wdt";
3575- struct omap_wd_timer_platform_data pdata;
3576+ static struct omap_wd_timer_platform_data pdata = {
3577+ .read_reset_sources = prm_read_reset_sources
3578+ };
3579
3580 if (!cpu_class_is_omap2() || of_have_populated_dt())
3581 return 0;
3582@@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3583 return -EINVAL;
3584 }
3585
3586- pdata.read_reset_sources = prm_read_reset_sources;
3587-
3588 pdev = omap_device_build(dev_name, id, oh, &pdata,
3589 sizeof(struct omap_wd_timer_platform_data));
3590 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3591diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3592index 706aa42..f85e9131 100644
3593--- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3594+++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3595@@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3596 bool entered_lp2 = false;
3597
3598 if (tegra_pending_sgi())
3599- ACCESS_ONCE(abort_flag) = true;
3600+ ACCESS_ONCE_RW(abort_flag) = true;
3601
3602 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3603
3604diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3605index cad3ca86..1d79e0f 100644
3606--- a/arch/arm/mach-ux500/setup.h
3607+++ b/arch/arm/mach-ux500/setup.h
3608@@ -37,13 +37,6 @@ extern void ux500_timer_init(void);
3609 .type = MT_DEVICE, \
3610 }
3611
3612-#define __MEM_DEV_DESC(x, sz) { \
3613- .virtual = IO_ADDRESS(x), \
3614- .pfn = __phys_to_pfn(x), \
3615- .length = sz, \
3616- .type = MT_MEMORY, \
3617-}
3618-
3619 extern struct smp_operations ux500_smp_ops;
3620 extern void ux500_cpu_die(unsigned int cpu);
3621
3622diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3623index cd2c88e..7430282 100644
3624--- a/arch/arm/mm/Kconfig
3625+++ b/arch/arm/mm/Kconfig
3626@@ -446,7 +446,7 @@ config CPU_32v5
3627
3628 config CPU_32v6
3629 bool
3630- select CPU_USE_DOMAINS if CPU_V6 && MMU
3631+ select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3632 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3633
3634 config CPU_32v6K
3635@@ -601,6 +601,7 @@ config CPU_CP15_MPU
3636
3637 config CPU_USE_DOMAINS
3638 bool
3639+ depends on !ARM_LPAE && !PAX_KERNEXEC
3640 help
3641 This option enables or disables the use of domain switching
3642 via the set_fs() function.
3643@@ -800,6 +801,7 @@ config NEED_KUSER_HELPERS
3644 config KUSER_HELPERS
3645 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3646 default y
3647+ depends on !(CPU_V6 || CPU_V6K || CPU_V7)
3648 help
3649 Warning: disabling this option may break user programs.
3650
3651@@ -812,7 +814,7 @@ config KUSER_HELPERS
3652 See Documentation/arm/kernel_user_helpers.txt for details.
3653
3654 However, the fixed address nature of these helpers can be used
3655- by ROP (return orientated programming) authors when creating
3656+ by ROP (Return Oriented Programming) authors when creating
3657 exploits.
3658
3659 If all of the binaries and libraries which run on your platform
3660diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3661index 6f4585b..7b6f52b 100644
3662--- a/arch/arm/mm/alignment.c
3663+++ b/arch/arm/mm/alignment.c
3664@@ -211,10 +211,12 @@ union offset_union {
3665 #define __get16_unaligned_check(ins,val,addr) \
3666 do { \
3667 unsigned int err = 0, v, a = addr; \
3668+ pax_open_userland(); \
3669 __get8_unaligned_check(ins,v,a,err); \
3670 val = v << ((BE) ? 8 : 0); \
3671 __get8_unaligned_check(ins,v,a,err); \
3672 val |= v << ((BE) ? 0 : 8); \
3673+ pax_close_userland(); \
3674 if (err) \
3675 goto fault; \
3676 } while (0)
3677@@ -228,6 +230,7 @@ union offset_union {
3678 #define __get32_unaligned_check(ins,val,addr) \
3679 do { \
3680 unsigned int err = 0, v, a = addr; \
3681+ pax_open_userland(); \
3682 __get8_unaligned_check(ins,v,a,err); \
3683 val = v << ((BE) ? 24 : 0); \
3684 __get8_unaligned_check(ins,v,a,err); \
3685@@ -236,6 +239,7 @@ union offset_union {
3686 val |= v << ((BE) ? 8 : 16); \
3687 __get8_unaligned_check(ins,v,a,err); \
3688 val |= v << ((BE) ? 0 : 24); \
3689+ pax_close_userland(); \
3690 if (err) \
3691 goto fault; \
3692 } while (0)
3693@@ -249,6 +253,7 @@ union offset_union {
3694 #define __put16_unaligned_check(ins,val,addr) \
3695 do { \
3696 unsigned int err = 0, v = val, a = addr; \
3697+ pax_open_userland(); \
3698 __asm__( FIRST_BYTE_16 \
3699 ARM( "1: "ins" %1, [%2], #1\n" ) \
3700 THUMB( "1: "ins" %1, [%2]\n" ) \
3701@@ -268,6 +273,7 @@ union offset_union {
3702 " .popsection\n" \
3703 : "=r" (err), "=&r" (v), "=&r" (a) \
3704 : "0" (err), "1" (v), "2" (a)); \
3705+ pax_close_userland(); \
3706 if (err) \
3707 goto fault; \
3708 } while (0)
3709@@ -281,6 +287,7 @@ union offset_union {
3710 #define __put32_unaligned_check(ins,val,addr) \
3711 do { \
3712 unsigned int err = 0, v = val, a = addr; \
3713+ pax_open_userland(); \
3714 __asm__( FIRST_BYTE_32 \
3715 ARM( "1: "ins" %1, [%2], #1\n" ) \
3716 THUMB( "1: "ins" %1, [%2]\n" ) \
3717@@ -310,6 +317,7 @@ union offset_union {
3718 " .popsection\n" \
3719 : "=r" (err), "=&r" (v), "=&r" (a) \
3720 : "0" (err), "1" (v), "2" (a)); \
3721+ pax_close_userland(); \
3722 if (err) \
3723 goto fault; \
3724 } while (0)
3725diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3726index 4a05444..d21968c 100644
3727--- a/arch/arm/mm/context.c
3728+++ b/arch/arm/mm/context.c
3729@@ -43,7 +43,7 @@
3730 #define NUM_USER_ASIDS ASID_FIRST_VERSION
3731
3732 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3733-static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3734+static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3735 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
3736
3737 static DEFINE_PER_CPU(atomic64_t, active_asids);
3738@@ -183,7 +183,7 @@ static int is_reserved_asid(u64 asid)
3739 static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3740 {
3741 u64 asid = atomic64_read(&mm->context.id);
3742- u64 generation = atomic64_read(&asid_generation);
3743+ u64 generation = atomic64_read_unchecked(&asid_generation);
3744
3745 if (asid != 0 && is_reserved_asid(asid)) {
3746 /*
3747@@ -201,7 +201,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3748 */
3749 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3750 if (asid == NUM_USER_ASIDS) {
3751- generation = atomic64_add_return(ASID_FIRST_VERSION,
3752+ generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
3753 &asid_generation);
3754 flush_context(cpu);
3755 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3756@@ -230,14 +230,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
3757 cpu_set_reserved_ttbr0();
3758
3759 asid = atomic64_read(&mm->context.id);
3760- if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
3761+ if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
3762 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
3763 goto switch_mm_fastpath;
3764
3765 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
3766 /* Check that our ASID belongs to the current generation. */
3767 asid = atomic64_read(&mm->context.id);
3768- if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
3769+ if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
3770 asid = new_context(mm, cpu);
3771 atomic64_set(&mm->context.id, asid);
3772 }
3773diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3774index c97f794..6461880 100644
3775--- a/arch/arm/mm/fault.c
3776+++ b/arch/arm/mm/fault.c
3777@@ -25,6 +25,7 @@
3778 #include <asm/system_misc.h>
3779 #include <asm/system_info.h>
3780 #include <asm/tlbflush.h>
3781+#include <asm/sections.h>
3782
3783 #include "fault.h"
3784
3785@@ -138,6 +139,20 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3786 if (fixup_exception(regs))
3787 return;
3788
3789+#ifdef CONFIG_PAX_KERNEXEC
3790+ if ((fsr & FSR_WRITE) &&
3791+ (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3792+ (MODULES_VADDR <= addr && addr < MODULES_END)))
3793+ {
3794+ if (current->signal->curr_ip)
3795+ 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),
3796+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3797+ else
3798+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3799+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3800+ }
3801+#endif
3802+
3803 /*
3804 * No handler, we'll have to terminate things with extreme prejudice.
3805 */
3806@@ -174,6 +189,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3807 }
3808 #endif
3809
3810+#ifdef CONFIG_PAX_PAGEEXEC
3811+ if (fsr & FSR_LNX_PF) {
3812+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3813+ do_group_exit(SIGKILL);
3814+ }
3815+#endif
3816+
3817 tsk->thread.address = addr;
3818 tsk->thread.error_code = fsr;
3819 tsk->thread.trap_no = 14;
3820@@ -398,6 +420,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3821 }
3822 #endif /* CONFIG_MMU */
3823
3824+#ifdef CONFIG_PAX_PAGEEXEC
3825+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3826+{
3827+ long i;
3828+
3829+ printk(KERN_ERR "PAX: bytes at PC: ");
3830+ for (i = 0; i < 20; i++) {
3831+ unsigned char c;
3832+ if (get_user(c, (__force unsigned char __user *)pc+i))
3833+ printk(KERN_CONT "?? ");
3834+ else
3835+ printk(KERN_CONT "%02x ", c);
3836+ }
3837+ printk("\n");
3838+
3839+ printk(KERN_ERR "PAX: bytes at SP-4: ");
3840+ for (i = -1; i < 20; i++) {
3841+ unsigned long c;
3842+ if (get_user(c, (__force unsigned long __user *)sp+i))
3843+ printk(KERN_CONT "???????? ");
3844+ else
3845+ printk(KERN_CONT "%08lx ", c);
3846+ }
3847+ printk("\n");
3848+}
3849+#endif
3850+
3851 /*
3852 * First Level Translation Fault Handler
3853 *
3854@@ -545,9 +594,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3855 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3856 struct siginfo info;
3857
3858+#ifdef CONFIG_PAX_MEMORY_UDEREF
3859+ if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3860+ if (current->signal->curr_ip)
3861+ 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),
3862+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3863+ else
3864+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3865+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3866+ goto die;
3867+ }
3868+#endif
3869+
3870 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3871 return;
3872
3873+die:
3874 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3875 inf->name, fsr, addr);
3876
3877@@ -571,15 +633,92 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
3878 ifsr_info[nr].name = name;
3879 }
3880
3881+asmlinkage int sys_sigreturn(struct pt_regs *regs);
3882+asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
3883+
3884 asmlinkage void __exception
3885 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
3886 {
3887 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
3888 struct siginfo info;
3889+ unsigned long pc = instruction_pointer(regs);
3890+
3891+ if (user_mode(regs)) {
3892+ unsigned long sigpage = current->mm->context.sigpage;
3893+
3894+ if (sigpage <= pc && pc < sigpage + 7*4) {
3895+ if (pc < sigpage + 3*4)
3896+ sys_sigreturn(regs);
3897+ else
3898+ sys_rt_sigreturn(regs);
3899+ return;
3900+ }
3901+ if (pc == 0xffff0f60UL) {
3902+ /*
3903+ * PaX: __kuser_cmpxchg64 emulation
3904+ */
3905+ // TODO
3906+ //regs->ARM_pc = regs->ARM_lr;
3907+ //return;
3908+ }
3909+ if (pc == 0xffff0fa0UL) {
3910+ /*
3911+ * PaX: __kuser_memory_barrier emulation
3912+ */
3913+ // dmb(); implied by the exception
3914+ regs->ARM_pc = regs->ARM_lr;
3915+ return;
3916+ }
3917+ if (pc == 0xffff0fc0UL) {
3918+ /*
3919+ * PaX: __kuser_cmpxchg emulation
3920+ */
3921+ // TODO
3922+ //regs->ARM_pc = regs->ARM_lr;
3923+ //return;
3924+ }
3925+ if (pc == 0xffff0fe0UL) {
3926+ /*
3927+ * PaX: __kuser_get_tls emulation
3928+ */
3929+ regs->ARM_r0 = current_thread_info()->tp_value[0];
3930+ regs->ARM_pc = regs->ARM_lr;
3931+ return;
3932+ }
3933+ }
3934+
3935+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3936+ else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
3937+ if (current->signal->curr_ip)
3938+ 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),
3939+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
3940+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
3941+ else
3942+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
3943+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
3944+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
3945+ goto die;
3946+ }
3947+#endif
3948+
3949+#ifdef CONFIG_PAX_REFCOUNT
3950+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
3951+ unsigned int bkpt;
3952+
3953+ if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
3954+ current->thread.error_code = ifsr;
3955+ current->thread.trap_no = 0;
3956+ pax_report_refcount_overflow(regs);
3957+ fixup_exception(regs);
3958+ return;
3959+ }
3960+ }
3961+#endif
3962
3963 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
3964 return;
3965
3966+die:
3967 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
3968 inf->name, ifsr, addr);
3969
3970diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
3971index cf08bdf..772656c 100644
3972--- a/arch/arm/mm/fault.h
3973+++ b/arch/arm/mm/fault.h
3974@@ -3,6 +3,7 @@
3975
3976 /*
3977 * Fault status register encodings. We steal bit 31 for our own purposes.
3978+ * Set when the FSR value is from an instruction fault.
3979 */
3980 #define FSR_LNX_PF (1 << 31)
3981 #define FSR_WRITE (1 << 11)
3982@@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
3983 }
3984 #endif
3985
3986+/* valid for LPAE and !LPAE */
3987+static inline int is_xn_fault(unsigned int fsr)
3988+{
3989+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
3990+}
3991+
3992+static inline int is_domain_fault(unsigned int fsr)
3993+{
3994+ return ((fsr_fs(fsr) & 0xD) == 0x9);
3995+}
3996+
3997 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
3998 unsigned long search_exception_table(unsigned long addr);
3999
4000diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4001index 15225d8..25e2e3c 100644
4002--- a/arch/arm/mm/init.c
4003+++ b/arch/arm/mm/init.c
4004@@ -30,6 +30,8 @@
4005 #include <asm/setup.h>
4006 #include <asm/tlb.h>
4007 #include <asm/fixmap.h>
4008+#include <asm/system_info.h>
4009+#include <asm/cp15.h>
4010
4011 #include <asm/mach/arch.h>
4012 #include <asm/mach/map.h>
4013@@ -683,7 +685,46 @@ void free_initmem(void)
4014 {
4015 #ifdef CONFIG_HAVE_TCM
4016 extern char __tcm_start, __tcm_end;
4017+#endif
4018
4019+#ifdef CONFIG_PAX_KERNEXEC
4020+ unsigned long addr;
4021+ pgd_t *pgd;
4022+ pud_t *pud;
4023+ pmd_t *pmd;
4024+ int cpu_arch = cpu_architecture();
4025+ unsigned int cr = get_cr();
4026+
4027+ if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4028+ /* make pages tables, etc before .text NX */
4029+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4030+ pgd = pgd_offset_k(addr);
4031+ pud = pud_offset(pgd, addr);
4032+ pmd = pmd_offset(pud, addr);
4033+ __section_update(pmd, addr, PMD_SECT_XN);
4034+ }
4035+ /* make init NX */
4036+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4037+ pgd = pgd_offset_k(addr);
4038+ pud = pud_offset(pgd, addr);
4039+ pmd = pmd_offset(pud, addr);
4040+ __section_update(pmd, addr, PMD_SECT_XN);
4041+ }
4042+ /* make kernel code/rodata RX */
4043+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4044+ pgd = pgd_offset_k(addr);
4045+ pud = pud_offset(pgd, addr);
4046+ pmd = pmd_offset(pud, addr);
4047+#ifdef CONFIG_ARM_LPAE
4048+ __section_update(pmd, addr, PMD_SECT_RDONLY);
4049+#else
4050+ __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4051+#endif
4052+ }
4053+ }
4054+#endif
4055+
4056+#ifdef CONFIG_HAVE_TCM
4057 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4058 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4059 #endif
4060diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4061index f123d6e..04bf569 100644
4062--- a/arch/arm/mm/ioremap.c
4063+++ b/arch/arm/mm/ioremap.c
4064@@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4065 unsigned int mtype;
4066
4067 if (cached)
4068- mtype = MT_MEMORY;
4069+ mtype = MT_MEMORY_RX;
4070 else
4071- mtype = MT_MEMORY_NONCACHED;
4072+ mtype = MT_MEMORY_NONCACHED_RX;
4073
4074 return __arm_ioremap_caller(phys_addr, size, mtype,
4075 __builtin_return_address(0));
4076diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4077index 0c63562..7128a90 100644
4078--- a/arch/arm/mm/mmap.c
4079+++ b/arch/arm/mm/mmap.c
4080@@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4081 struct vm_area_struct *vma;
4082 int do_align = 0;
4083 int aliasing = cache_is_vipt_aliasing();
4084+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4085 struct vm_unmapped_area_info info;
4086
4087 /*
4088@@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4089 if (len > TASK_SIZE)
4090 return -ENOMEM;
4091
4092+#ifdef CONFIG_PAX_RANDMMAP
4093+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4094+#endif
4095+
4096 if (addr) {
4097 if (do_align)
4098 addr = COLOUR_ALIGN(addr, pgoff);
4099@@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4100 addr = PAGE_ALIGN(addr);
4101
4102 vma = find_vma(mm, addr);
4103- if (TASK_SIZE - len >= addr &&
4104- (!vma || addr + len <= vma->vm_start))
4105+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4106 return addr;
4107 }
4108
4109@@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4110 info.high_limit = TASK_SIZE;
4111 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4112 info.align_offset = pgoff << PAGE_SHIFT;
4113+ info.threadstack_offset = offset;
4114 return vm_unmapped_area(&info);
4115 }
4116
4117@@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4118 unsigned long addr = addr0;
4119 int do_align = 0;
4120 int aliasing = cache_is_vipt_aliasing();
4121+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4122 struct vm_unmapped_area_info info;
4123
4124 /*
4125@@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4126 return addr;
4127 }
4128
4129+#ifdef CONFIG_PAX_RANDMMAP
4130+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4131+#endif
4132+
4133 /* requesting a specific address */
4134 if (addr) {
4135 if (do_align)
4136@@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4137 else
4138 addr = PAGE_ALIGN(addr);
4139 vma = find_vma(mm, addr);
4140- if (TASK_SIZE - len >= addr &&
4141- (!vma || addr + len <= vma->vm_start))
4142+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4143 return addr;
4144 }
4145
4146@@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4147 info.high_limit = mm->mmap_base;
4148 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4149 info.align_offset = pgoff << PAGE_SHIFT;
4150+ info.threadstack_offset = offset;
4151 addr = vm_unmapped_area(&info);
4152
4153 /*
4154@@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4155 {
4156 unsigned long random_factor = 0UL;
4157
4158+#ifdef CONFIG_PAX_RANDMMAP
4159+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4160+#endif
4161+
4162 /* 8 bits of randomness in 20 address space bits */
4163 if ((current->flags & PF_RANDOMIZE) &&
4164 !(current->personality & ADDR_NO_RANDOMIZE))
4165@@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4166
4167 if (mmap_is_legacy()) {
4168 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4169+
4170+#ifdef CONFIG_PAX_RANDMMAP
4171+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4172+ mm->mmap_base += mm->delta_mmap;
4173+#endif
4174+
4175 mm->get_unmapped_area = arch_get_unmapped_area;
4176 } else {
4177 mm->mmap_base = mmap_base(random_factor);
4178+
4179+#ifdef CONFIG_PAX_RANDMMAP
4180+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4181+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4182+#endif
4183+
4184 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4185 }
4186 }
4187diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4188index 53cdbd3..670f177 100644
4189--- a/arch/arm/mm/mmu.c
4190+++ b/arch/arm/mm/mmu.c
4191@@ -36,6 +36,22 @@
4192 #include "mm.h"
4193 #include "tcm.h"
4194
4195+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4196+void modify_domain(unsigned int dom, unsigned int type)
4197+{
4198+ struct thread_info *thread = current_thread_info();
4199+ unsigned int domain = thread->cpu_domain;
4200+ /*
4201+ * DOMAIN_MANAGER might be defined to some other value,
4202+ * use the arch-defined constant
4203+ */
4204+ domain &= ~domain_val(dom, 3);
4205+ thread->cpu_domain = domain | domain_val(dom, type);
4206+ set_domain(thread->cpu_domain);
4207+}
4208+EXPORT_SYMBOL(modify_domain);
4209+#endif
4210+
4211 /*
4212 * empty_zero_page is a special page that is used for
4213 * zero-initialized data and COW.
4214@@ -228,10 +244,18 @@ __setup("noalign", noalign_setup);
4215
4216 #endif /* ifdef CONFIG_CPU_CP15 / else */
4217
4218-#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN
4219+#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY
4220 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4221
4222-static struct mem_type mem_types[] = {
4223+#ifdef CONFIG_PAX_KERNEXEC
4224+#define L_PTE_KERNEXEC L_PTE_RDONLY
4225+#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4226+#else
4227+#define L_PTE_KERNEXEC L_PTE_DIRTY
4228+#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4229+#endif
4230+
4231+static struct mem_type mem_types[] __read_only = {
4232 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4233 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4234 L_PTE_SHARED,
4235@@ -260,16 +284,16 @@ static struct mem_type mem_types[] = {
4236 [MT_UNCACHED] = {
4237 .prot_pte = PROT_PTE_DEVICE,
4238 .prot_l1 = PMD_TYPE_TABLE,
4239- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4240+ .prot_sect = PROT_SECT_DEVICE,
4241 .domain = DOMAIN_IO,
4242 },
4243 [MT_CACHECLEAN] = {
4244- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4245+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4246 .domain = DOMAIN_KERNEL,
4247 },
4248 #ifndef CONFIG_ARM_LPAE
4249 [MT_MINICLEAN] = {
4250- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4251+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_RDONLY,
4252 .domain = DOMAIN_KERNEL,
4253 },
4254 #endif
4255@@ -277,36 +301,54 @@ static struct mem_type mem_types[] = {
4256 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4257 L_PTE_RDONLY,
4258 .prot_l1 = PMD_TYPE_TABLE,
4259- .domain = DOMAIN_USER,
4260+ .domain = DOMAIN_VECTORS,
4261 },
4262 [MT_HIGH_VECTORS] = {
4263 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4264 L_PTE_USER | L_PTE_RDONLY,
4265 .prot_l1 = PMD_TYPE_TABLE,
4266- .domain = DOMAIN_USER,
4267+ .domain = DOMAIN_VECTORS,
4268 },
4269- [MT_MEMORY] = {
4270+ [MT_MEMORY_RWX] = {
4271 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4272 .prot_l1 = PMD_TYPE_TABLE,
4273 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4274 .domain = DOMAIN_KERNEL,
4275 },
4276+ [MT_MEMORY_RW] = {
4277+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4278+ .prot_l1 = PMD_TYPE_TABLE,
4279+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4280+ .domain = DOMAIN_KERNEL,
4281+ },
4282+ [MT_MEMORY_RX] = {
4283+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4284+ .prot_l1 = PMD_TYPE_TABLE,
4285+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4286+ .domain = DOMAIN_KERNEL,
4287+ },
4288 [MT_ROM] = {
4289- .prot_sect = PMD_TYPE_SECT,
4290+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4291 .domain = DOMAIN_KERNEL,
4292 },
4293- [MT_MEMORY_NONCACHED] = {
4294+ [MT_MEMORY_NONCACHED_RW] = {
4295 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4296 L_PTE_MT_BUFFERABLE,
4297 .prot_l1 = PMD_TYPE_TABLE,
4298 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4299 .domain = DOMAIN_KERNEL,
4300 },
4301+ [MT_MEMORY_NONCACHED_RX] = {
4302+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4303+ L_PTE_MT_BUFFERABLE,
4304+ .prot_l1 = PMD_TYPE_TABLE,
4305+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4306+ .domain = DOMAIN_KERNEL,
4307+ },
4308 [MT_MEMORY_DTCM] = {
4309- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4310- L_PTE_XN,
4311+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4312 .prot_l1 = PMD_TYPE_TABLE,
4313- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4314+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4315 .domain = DOMAIN_KERNEL,
4316 },
4317 [MT_MEMORY_ITCM] = {
4318@@ -316,10 +358,10 @@ static struct mem_type mem_types[] = {
4319 },
4320 [MT_MEMORY_SO] = {
4321 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4322- L_PTE_MT_UNCACHED | L_PTE_XN,
4323+ L_PTE_MT_UNCACHED,
4324 .prot_l1 = PMD_TYPE_TABLE,
4325 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_S |
4326- PMD_SECT_UNCACHED | PMD_SECT_XN,
4327+ PMD_SECT_UNCACHED,
4328 .domain = DOMAIN_KERNEL,
4329 },
4330 [MT_MEMORY_DMA_READY] = {
4331@@ -405,9 +447,35 @@ static void __init build_mem_type_table(void)
4332 * to prevent speculative instruction fetches.
4333 */
4334 mem_types[MT_DEVICE].prot_sect |= PMD_SECT_XN;
4335+ mem_types[MT_DEVICE].prot_pte |= L_PTE_XN;
4336 mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_XN;
4337+ mem_types[MT_DEVICE_NONSHARED].prot_pte |= L_PTE_XN;
4338 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_XN;
4339+ mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_XN;
4340 mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_XN;
4341+ mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_XN;
4342+
4343+ /* Mark other regions on ARMv6+ as execute-never */
4344+
4345+#ifdef CONFIG_PAX_KERNEXEC
4346+ mem_types[MT_UNCACHED].prot_sect |= PMD_SECT_XN;
4347+ mem_types[MT_UNCACHED].prot_pte |= L_PTE_XN;
4348+ mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_XN;
4349+ mem_types[MT_CACHECLEAN].prot_pte |= L_PTE_XN;
4350+#ifndef CONFIG_ARM_LPAE
4351+ mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_XN;
4352+ mem_types[MT_MINICLEAN].prot_pte |= L_PTE_XN;
4353+#endif
4354+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_XN;
4355+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_XN;
4356+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_XN;
4357+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= PMD_SECT_XN;
4358+ mem_types[MT_MEMORY_DTCM].prot_sect |= PMD_SECT_XN;
4359+ mem_types[MT_MEMORY_DTCM].prot_pte |= L_PTE_XN;
4360+#endif
4361+
4362+ mem_types[MT_MEMORY_SO].prot_sect |= PMD_SECT_XN;
4363+ mem_types[MT_MEMORY_SO].prot_pte |= L_PTE_XN;
4364 }
4365 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4366 /*
4367@@ -468,6 +536,9 @@ static void __init build_mem_type_table(void)
4368 * from SVC mode and no access from userspace.
4369 */
4370 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4371+#ifdef CONFIG_PAX_KERNEXEC
4372+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4373+#endif
4374 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4375 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4376 #endif
4377@@ -485,11 +556,17 @@ static void __init build_mem_type_table(void)
4378 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4379 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4380 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4381- mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
4382- mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
4383+ mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4384+ mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4385+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4386+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4387+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4388+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4389 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4390- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
4391- mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
4392+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_S;
4393+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= L_PTE_SHARED;
4394+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_S;
4395+ mem_types[MT_MEMORY_NONCACHED_RX].prot_pte |= L_PTE_SHARED;
4396 }
4397 }
4398
4399@@ -500,15 +577,20 @@ static void __init build_mem_type_table(void)
4400 if (cpu_arch >= CPU_ARCH_ARMv6) {
4401 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4402 /* Non-cacheable Normal is XCB = 001 */
4403- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4404+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4405+ PMD_SECT_BUFFERED;
4406+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4407 PMD_SECT_BUFFERED;
4408 } else {
4409 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4410- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4411+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4412+ PMD_SECT_TEX(1);
4413+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4414 PMD_SECT_TEX(1);
4415 }
4416 } else {
4417- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4418+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_BUFFERABLE;
4419+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_BUFFERABLE;
4420 }
4421
4422 #ifdef CONFIG_ARM_LPAE
4423@@ -524,6 +606,8 @@ static void __init build_mem_type_table(void)
4424 vecs_pgprot |= PTE_EXT_AF;
4425 #endif
4426
4427+ user_pgprot |= __supported_pte_mask;
4428+
4429 for (i = 0; i < 16; i++) {
4430 pteval_t v = pgprot_val(protection_map[i]);
4431 protection_map[i] = __pgprot(v | user_pgprot);
4432@@ -541,10 +625,15 @@ static void __init build_mem_type_table(void)
4433
4434 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4435 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4436- mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
4437- mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
4438+ mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4439+ mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4440+ mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4441+ mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4442+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4443+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4444 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4445- mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
4446+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= ecc_mask;
4447+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= ecc_mask;
4448 mem_types[MT_ROM].prot_sect |= cp->pmd;
4449
4450 switch (cp->pmd) {
4451@@ -1186,18 +1275,15 @@ void __init arm_mm_memblock_reserve(void)
4452 * called function. This means you can't use any function or debugging
4453 * method which may touch any device, otherwise the kernel _will_ crash.
4454 */
4455+
4456+static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
4457+
4458 static void __init devicemaps_init(struct machine_desc *mdesc)
4459 {
4460 struct map_desc map;
4461 unsigned long addr;
4462- void *vectors;
4463
4464- /*
4465- * Allocate the vector page early.
4466- */
4467- vectors = early_alloc(PAGE_SIZE * 2);
4468-
4469- early_trap_init(vectors);
4470+ early_trap_init(&vectors);
4471
4472 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4473 pmd_clear(pmd_off_k(addr));
4474@@ -1237,7 +1323,7 @@ static void __init devicemaps_init(struct machine_desc *mdesc)
4475 * location (0xffff0000). If we aren't using high-vectors, also
4476 * create a mapping at the low-vectors virtual address.
4477 */
4478- map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4479+ map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4480 map.virtual = 0xffff0000;
4481 map.length = PAGE_SIZE;
4482 #ifdef CONFIG_KUSER_HELPERS
4483@@ -1309,8 +1395,39 @@ static void __init map_lowmem(void)
4484 map.pfn = __phys_to_pfn(start);
4485 map.virtual = __phys_to_virt(start);
4486 map.length = end - start;
4487- map.type = MT_MEMORY;
4488
4489+#ifdef CONFIG_PAX_KERNEXEC
4490+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4491+ struct map_desc kernel;
4492+ struct map_desc initmap;
4493+
4494+ /* when freeing initmem we will make this RW */
4495+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4496+ initmap.virtual = (unsigned long)__init_begin;
4497+ initmap.length = _sdata - __init_begin;
4498+ initmap.type = MT_MEMORY_RWX;
4499+ create_mapping(&initmap);
4500+
4501+ /* when freeing initmem we will make this RX */
4502+ kernel.pfn = __phys_to_pfn(__pa(_stext));
4503+ kernel.virtual = (unsigned long)_stext;
4504+ kernel.length = __init_begin - _stext;
4505+ kernel.type = MT_MEMORY_RWX;
4506+ create_mapping(&kernel);
4507+
4508+ if (map.virtual < (unsigned long)_stext) {
4509+ map.length = (unsigned long)_stext - map.virtual;
4510+ map.type = MT_MEMORY_RWX;
4511+ create_mapping(&map);
4512+ }
4513+
4514+ map.pfn = __phys_to_pfn(__pa(_sdata));
4515+ map.virtual = (unsigned long)_sdata;
4516+ map.length = end - __pa(_sdata);
4517+ }
4518+#endif
4519+
4520+ map.type = MT_MEMORY_RW;
4521 create_mapping(&map);
4522 }
4523 }
4524diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4525index a5bc92d..0bb4730 100644
4526--- a/arch/arm/plat-omap/sram.c
4527+++ b/arch/arm/plat-omap/sram.c
4528@@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4529 * Looks like we need to preserve some bootloader code at the
4530 * beginning of SRAM for jumping to flash for reboot to work...
4531 */
4532+ pax_open_kernel();
4533 memset_io(omap_sram_base + omap_sram_skip, 0,
4534 omap_sram_size - omap_sram_skip);
4535+ pax_close_kernel();
4536 }
4537diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4538index ce6d763..cfea917 100644
4539--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4540+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4541@@ -47,7 +47,7 @@ struct samsung_dma_ops {
4542 int (*started)(unsigned ch);
4543 int (*flush)(unsigned ch);
4544 int (*stop)(unsigned ch);
4545-};
4546+} __no_const;
4547
4548 extern void *samsung_dmadev_get_ops(void);
4549 extern void *s3c_dma_get_ops(void);
4550diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4551index c3a58a1..78fbf54 100644
4552--- a/arch/avr32/include/asm/cache.h
4553+++ b/arch/avr32/include/asm/cache.h
4554@@ -1,8 +1,10 @@
4555 #ifndef __ASM_AVR32_CACHE_H
4556 #define __ASM_AVR32_CACHE_H
4557
4558+#include <linux/const.h>
4559+
4560 #define L1_CACHE_SHIFT 5
4561-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4562+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4563
4564 /*
4565 * Memory returned by kmalloc() may be used for DMA, so we must make
4566diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4567index d232888..87c8df1 100644
4568--- a/arch/avr32/include/asm/elf.h
4569+++ b/arch/avr32/include/asm/elf.h
4570@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4571 the loader. We need to make sure that it is out of the way of the program
4572 that it will "exec", and that there is sufficient room for the brk. */
4573
4574-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4575+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4576
4577+#ifdef CONFIG_PAX_ASLR
4578+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4579+
4580+#define PAX_DELTA_MMAP_LEN 15
4581+#define PAX_DELTA_STACK_LEN 15
4582+#endif
4583
4584 /* This yields a mask that user programs can use to figure out what
4585 instruction set this CPU supports. This could be done in user space,
4586diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4587index 479330b..53717a8 100644
4588--- a/arch/avr32/include/asm/kmap_types.h
4589+++ b/arch/avr32/include/asm/kmap_types.h
4590@@ -2,9 +2,9 @@
4591 #define __ASM_AVR32_KMAP_TYPES_H
4592
4593 #ifdef CONFIG_DEBUG_HIGHMEM
4594-# define KM_TYPE_NR 29
4595+# define KM_TYPE_NR 30
4596 #else
4597-# define KM_TYPE_NR 14
4598+# define KM_TYPE_NR 15
4599 #endif
4600
4601 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4602diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4603index b2f2d2d..d1c85cb 100644
4604--- a/arch/avr32/mm/fault.c
4605+++ b/arch/avr32/mm/fault.c
4606@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4607
4608 int exception_trace = 1;
4609
4610+#ifdef CONFIG_PAX_PAGEEXEC
4611+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4612+{
4613+ unsigned long i;
4614+
4615+ printk(KERN_ERR "PAX: bytes at PC: ");
4616+ for (i = 0; i < 20; i++) {
4617+ unsigned char c;
4618+ if (get_user(c, (unsigned char *)pc+i))
4619+ printk(KERN_CONT "???????? ");
4620+ else
4621+ printk(KERN_CONT "%02x ", c);
4622+ }
4623+ printk("\n");
4624+}
4625+#endif
4626+
4627 /*
4628 * This routine handles page faults. It determines the address and the
4629 * problem, and then passes it off to one of the appropriate routines.
4630@@ -174,6 +191,16 @@ bad_area:
4631 up_read(&mm->mmap_sem);
4632
4633 if (user_mode(regs)) {
4634+
4635+#ifdef CONFIG_PAX_PAGEEXEC
4636+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4637+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4638+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4639+ do_group_exit(SIGKILL);
4640+ }
4641+ }
4642+#endif
4643+
4644 if (exception_trace && printk_ratelimit())
4645 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4646 "sp %08lx ecr %lu\n",
4647diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4648index 568885a..f8008df 100644
4649--- a/arch/blackfin/include/asm/cache.h
4650+++ b/arch/blackfin/include/asm/cache.h
4651@@ -7,6 +7,7 @@
4652 #ifndef __ARCH_BLACKFIN_CACHE_H
4653 #define __ARCH_BLACKFIN_CACHE_H
4654
4655+#include <linux/const.h>
4656 #include <linux/linkage.h> /* for asmlinkage */
4657
4658 /*
4659@@ -14,7 +15,7 @@
4660 * Blackfin loads 32 bytes for cache
4661 */
4662 #define L1_CACHE_SHIFT 5
4663-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4664+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4665 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4666
4667 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4668diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4669index aea2718..3639a60 100644
4670--- a/arch/cris/include/arch-v10/arch/cache.h
4671+++ b/arch/cris/include/arch-v10/arch/cache.h
4672@@ -1,8 +1,9 @@
4673 #ifndef _ASM_ARCH_CACHE_H
4674 #define _ASM_ARCH_CACHE_H
4675
4676+#include <linux/const.h>
4677 /* Etrax 100LX have 32-byte cache-lines. */
4678-#define L1_CACHE_BYTES 32
4679 #define L1_CACHE_SHIFT 5
4680+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4681
4682 #endif /* _ASM_ARCH_CACHE_H */
4683diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4684index 7caf25d..ee65ac5 100644
4685--- a/arch/cris/include/arch-v32/arch/cache.h
4686+++ b/arch/cris/include/arch-v32/arch/cache.h
4687@@ -1,11 +1,12 @@
4688 #ifndef _ASM_CRIS_ARCH_CACHE_H
4689 #define _ASM_CRIS_ARCH_CACHE_H
4690
4691+#include <linux/const.h>
4692 #include <arch/hwregs/dma.h>
4693
4694 /* A cache-line is 32 bytes. */
4695-#define L1_CACHE_BYTES 32
4696 #define L1_CACHE_SHIFT 5
4697+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4698
4699 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4700
4701diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4702index b86329d..6709906 100644
4703--- a/arch/frv/include/asm/atomic.h
4704+++ b/arch/frv/include/asm/atomic.h
4705@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4706 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4707 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4708
4709+#define atomic64_read_unchecked(v) atomic64_read(v)
4710+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4711+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4712+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4713+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4714+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4715+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4716+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4717+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4718+
4719 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4720 {
4721 int c, old;
4722diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4723index 2797163..c2a401d 100644
4724--- a/arch/frv/include/asm/cache.h
4725+++ b/arch/frv/include/asm/cache.h
4726@@ -12,10 +12,11 @@
4727 #ifndef __ASM_CACHE_H
4728 #define __ASM_CACHE_H
4729
4730+#include <linux/const.h>
4731
4732 /* bytes per L1 cache line */
4733 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4734-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4735+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4736
4737 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4738 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4739diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4740index 43901f2..0d8b865 100644
4741--- a/arch/frv/include/asm/kmap_types.h
4742+++ b/arch/frv/include/asm/kmap_types.h
4743@@ -2,6 +2,6 @@
4744 #ifndef _ASM_KMAP_TYPES_H
4745 #define _ASM_KMAP_TYPES_H
4746
4747-#define KM_TYPE_NR 17
4748+#define KM_TYPE_NR 18
4749
4750 #endif
4751diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4752index 836f147..4cf23f5 100644
4753--- a/arch/frv/mm/elf-fdpic.c
4754+++ b/arch/frv/mm/elf-fdpic.c
4755@@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4756 {
4757 struct vm_area_struct *vma;
4758 struct vm_unmapped_area_info info;
4759+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4760
4761 if (len > TASK_SIZE)
4762 return -ENOMEM;
4763@@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4764 if (addr) {
4765 addr = PAGE_ALIGN(addr);
4766 vma = find_vma(current->mm, addr);
4767- if (TASK_SIZE - len >= addr &&
4768- (!vma || addr + len <= vma->vm_start))
4769+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4770 goto success;
4771 }
4772
4773@@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4774 info.high_limit = (current->mm->start_stack - 0x00200000);
4775 info.align_mask = 0;
4776 info.align_offset = 0;
4777+ info.threadstack_offset = offset;
4778 addr = vm_unmapped_area(&info);
4779 if (!(addr & ~PAGE_MASK))
4780 goto success;
4781diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4782index f4ca594..adc72fd6 100644
4783--- a/arch/hexagon/include/asm/cache.h
4784+++ b/arch/hexagon/include/asm/cache.h
4785@@ -21,9 +21,11 @@
4786 #ifndef __ASM_CACHE_H
4787 #define __ASM_CACHE_H
4788
4789+#include <linux/const.h>
4790+
4791 /* Bytes per L1 cache line */
4792-#define L1_CACHE_SHIFT (5)
4793-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4794+#define L1_CACHE_SHIFT 5
4795+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4796
4797 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4798 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4799diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4800index 6e6fe18..a6ae668 100644
4801--- a/arch/ia64/include/asm/atomic.h
4802+++ b/arch/ia64/include/asm/atomic.h
4803@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4804 #define atomic64_inc(v) atomic64_add(1, (v))
4805 #define atomic64_dec(v) atomic64_sub(1, (v))
4806
4807+#define atomic64_read_unchecked(v) atomic64_read(v)
4808+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4809+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4810+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4811+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4812+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4813+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4814+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4815+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4816+
4817 /* Atomic operations are already serializing */
4818 #define smp_mb__before_atomic_dec() barrier()
4819 #define smp_mb__after_atomic_dec() barrier()
4820diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
4821index 988254a..e1ee885 100644
4822--- a/arch/ia64/include/asm/cache.h
4823+++ b/arch/ia64/include/asm/cache.h
4824@@ -1,6 +1,7 @@
4825 #ifndef _ASM_IA64_CACHE_H
4826 #define _ASM_IA64_CACHE_H
4827
4828+#include <linux/const.h>
4829
4830 /*
4831 * Copyright (C) 1998-2000 Hewlett-Packard Co
4832@@ -9,7 +10,7 @@
4833
4834 /* Bytes per L1 (data) cache line. */
4835 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
4836-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4837+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4838
4839 #ifdef CONFIG_SMP
4840 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
4841diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
4842index 5a83c5c..4d7f553 100644
4843--- a/arch/ia64/include/asm/elf.h
4844+++ b/arch/ia64/include/asm/elf.h
4845@@ -42,6 +42,13 @@
4846 */
4847 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
4848
4849+#ifdef CONFIG_PAX_ASLR
4850+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
4851+
4852+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4853+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4854+#endif
4855+
4856 #define PT_IA_64_UNWIND 0x70000001
4857
4858 /* IA-64 relocations: */
4859diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
4860index 96a8d92..617a1cf 100644
4861--- a/arch/ia64/include/asm/pgalloc.h
4862+++ b/arch/ia64/include/asm/pgalloc.h
4863@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4864 pgd_val(*pgd_entry) = __pa(pud);
4865 }
4866
4867+static inline void
4868+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4869+{
4870+ pgd_populate(mm, pgd_entry, pud);
4871+}
4872+
4873 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4874 {
4875 return quicklist_alloc(0, GFP_KERNEL, NULL);
4876@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4877 pud_val(*pud_entry) = __pa(pmd);
4878 }
4879
4880+static inline void
4881+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4882+{
4883+ pud_populate(mm, pud_entry, pmd);
4884+}
4885+
4886 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
4887 {
4888 return quicklist_alloc(0, GFP_KERNEL, NULL);
4889diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
4890index 7935115..c0eca6a 100644
4891--- a/arch/ia64/include/asm/pgtable.h
4892+++ b/arch/ia64/include/asm/pgtable.h
4893@@ -12,7 +12,7 @@
4894 * David Mosberger-Tang <davidm@hpl.hp.com>
4895 */
4896
4897-
4898+#include <linux/const.h>
4899 #include <asm/mman.h>
4900 #include <asm/page.h>
4901 #include <asm/processor.h>
4902@@ -142,6 +142,17 @@
4903 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4904 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4905 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
4906+
4907+#ifdef CONFIG_PAX_PAGEEXEC
4908+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
4909+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4910+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4911+#else
4912+# define PAGE_SHARED_NOEXEC PAGE_SHARED
4913+# define PAGE_READONLY_NOEXEC PAGE_READONLY
4914+# define PAGE_COPY_NOEXEC PAGE_COPY
4915+#endif
4916+
4917 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
4918 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
4919 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
4920diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
4921index 54ff557..70c88b7 100644
4922--- a/arch/ia64/include/asm/spinlock.h
4923+++ b/arch/ia64/include/asm/spinlock.h
4924@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
4925 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
4926
4927 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
4928- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
4929+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
4930 }
4931
4932 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
4933diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
4934index 449c8c0..18965fb 100644
4935--- a/arch/ia64/include/asm/uaccess.h
4936+++ b/arch/ia64/include/asm/uaccess.h
4937@@ -240,12 +240,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
4938 static inline unsigned long
4939 __copy_to_user (void __user *to, const void *from, unsigned long count)
4940 {
4941+ if (count > INT_MAX)
4942+ return count;
4943+
4944+ if (!__builtin_constant_p(count))
4945+ check_object_size(from, count, true);
4946+
4947 return __copy_user(to, (__force void __user *) from, count);
4948 }
4949
4950 static inline unsigned long
4951 __copy_from_user (void *to, const void __user *from, unsigned long count)
4952 {
4953+ if (count > INT_MAX)
4954+ return count;
4955+
4956+ if (!__builtin_constant_p(count))
4957+ check_object_size(to, count, false);
4958+
4959 return __copy_user((__force void __user *) to, from, count);
4960 }
4961
4962@@ -255,10 +267,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4963 ({ \
4964 void __user *__cu_to = (to); \
4965 const void *__cu_from = (from); \
4966- long __cu_len = (n); \
4967+ unsigned long __cu_len = (n); \
4968 \
4969- if (__access_ok(__cu_to, __cu_len, get_fs())) \
4970+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
4971+ if (!__builtin_constant_p(n)) \
4972+ check_object_size(__cu_from, __cu_len, true); \
4973 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
4974+ } \
4975 __cu_len; \
4976 })
4977
4978@@ -266,11 +281,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4979 ({ \
4980 void *__cu_to = (to); \
4981 const void __user *__cu_from = (from); \
4982- long __cu_len = (n); \
4983+ unsigned long __cu_len = (n); \
4984 \
4985 __chk_user_ptr(__cu_from); \
4986- if (__access_ok(__cu_from, __cu_len, get_fs())) \
4987+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
4988+ if (!__builtin_constant_p(n)) \
4989+ check_object_size(__cu_to, __cu_len, false); \
4990 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
4991+ } \
4992 __cu_len; \
4993 })
4994
4995diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
4996index 24603be..948052d 100644
4997--- a/arch/ia64/kernel/module.c
4998+++ b/arch/ia64/kernel/module.c
4999@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5000 void
5001 module_free (struct module *mod, void *module_region)
5002 {
5003- if (mod && mod->arch.init_unw_table &&
5004- module_region == mod->module_init) {
5005+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5006 unw_remove_unwind_table(mod->arch.init_unw_table);
5007 mod->arch.init_unw_table = NULL;
5008 }
5009@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5010 }
5011
5012 static inline int
5013+in_init_rx (const struct module *mod, uint64_t addr)
5014+{
5015+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5016+}
5017+
5018+static inline int
5019+in_init_rw (const struct module *mod, uint64_t addr)
5020+{
5021+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5022+}
5023+
5024+static inline int
5025 in_init (const struct module *mod, uint64_t addr)
5026 {
5027- return addr - (uint64_t) mod->module_init < mod->init_size;
5028+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5029+}
5030+
5031+static inline int
5032+in_core_rx (const struct module *mod, uint64_t addr)
5033+{
5034+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5035+}
5036+
5037+static inline int
5038+in_core_rw (const struct module *mod, uint64_t addr)
5039+{
5040+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5041 }
5042
5043 static inline int
5044 in_core (const struct module *mod, uint64_t addr)
5045 {
5046- return addr - (uint64_t) mod->module_core < mod->core_size;
5047+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5048 }
5049
5050 static inline int
5051@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5052 break;
5053
5054 case RV_BDREL:
5055- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5056+ if (in_init_rx(mod, val))
5057+ val -= (uint64_t) mod->module_init_rx;
5058+ else if (in_init_rw(mod, val))
5059+ val -= (uint64_t) mod->module_init_rw;
5060+ else if (in_core_rx(mod, val))
5061+ val -= (uint64_t) mod->module_core_rx;
5062+ else if (in_core_rw(mod, val))
5063+ val -= (uint64_t) mod->module_core_rw;
5064 break;
5065
5066 case RV_LTV:
5067@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5068 * addresses have been selected...
5069 */
5070 uint64_t gp;
5071- if (mod->core_size > MAX_LTOFF)
5072+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5073 /*
5074 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5075 * at the end of the module.
5076 */
5077- gp = mod->core_size - MAX_LTOFF / 2;
5078+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5079 else
5080- gp = mod->core_size / 2;
5081- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5082+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5083+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5084 mod->arch.gp = gp;
5085 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5086 }
5087diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5088index ab33328..f39506c 100644
5089--- a/arch/ia64/kernel/palinfo.c
5090+++ b/arch/ia64/kernel/palinfo.c
5091@@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5092 return NOTIFY_OK;
5093 }
5094
5095-static struct notifier_block __refdata palinfo_cpu_notifier =
5096+static struct notifier_block palinfo_cpu_notifier =
5097 {
5098 .notifier_call = palinfo_cpu_callback,
5099 .priority = 0,
5100diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5101index 41e33f8..65180b2 100644
5102--- a/arch/ia64/kernel/sys_ia64.c
5103+++ b/arch/ia64/kernel/sys_ia64.c
5104@@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5105 unsigned long align_mask = 0;
5106 struct mm_struct *mm = current->mm;
5107 struct vm_unmapped_area_info info;
5108+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5109
5110 if (len > RGN_MAP_LIMIT)
5111 return -ENOMEM;
5112@@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5113 if (REGION_NUMBER(addr) == RGN_HPAGE)
5114 addr = 0;
5115 #endif
5116+
5117+#ifdef CONFIG_PAX_RANDMMAP
5118+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5119+ addr = mm->free_area_cache;
5120+ else
5121+#endif
5122+
5123 if (!addr)
5124 addr = TASK_UNMAPPED_BASE;
5125
5126@@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5127 info.high_limit = TASK_SIZE;
5128 info.align_mask = align_mask;
5129 info.align_offset = 0;
5130+ info.threadstack_offset = offset;
5131 return vm_unmapped_area(&info);
5132 }
5133
5134diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5135index 0ccb28f..8992469 100644
5136--- a/arch/ia64/kernel/vmlinux.lds.S
5137+++ b/arch/ia64/kernel/vmlinux.lds.S
5138@@ -198,7 +198,7 @@ SECTIONS {
5139 /* Per-cpu data: */
5140 . = ALIGN(PERCPU_PAGE_SIZE);
5141 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5142- __phys_per_cpu_start = __per_cpu_load;
5143+ __phys_per_cpu_start = per_cpu_load;
5144 /*
5145 * ensure percpu data fits
5146 * into percpu page size
5147diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5148index 6cf0341..d352594 100644
5149--- a/arch/ia64/mm/fault.c
5150+++ b/arch/ia64/mm/fault.c
5151@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5152 return pte_present(pte);
5153 }
5154
5155+#ifdef CONFIG_PAX_PAGEEXEC
5156+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5157+{
5158+ unsigned long i;
5159+
5160+ printk(KERN_ERR "PAX: bytes at PC: ");
5161+ for (i = 0; i < 8; i++) {
5162+ unsigned int c;
5163+ if (get_user(c, (unsigned int *)pc+i))
5164+ printk(KERN_CONT "???????? ");
5165+ else
5166+ printk(KERN_CONT "%08x ", c);
5167+ }
5168+ printk("\n");
5169+}
5170+#endif
5171+
5172 # define VM_READ_BIT 0
5173 # define VM_WRITE_BIT 1
5174 # define VM_EXEC_BIT 2
5175@@ -149,8 +166,21 @@ retry:
5176 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5177 goto bad_area;
5178
5179- if ((vma->vm_flags & mask) != mask)
5180+ if ((vma->vm_flags & mask) != mask) {
5181+
5182+#ifdef CONFIG_PAX_PAGEEXEC
5183+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5184+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5185+ goto bad_area;
5186+
5187+ up_read(&mm->mmap_sem);
5188+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5189+ do_group_exit(SIGKILL);
5190+ }
5191+#endif
5192+
5193 goto bad_area;
5194+ }
5195
5196 /*
5197 * If for any reason at all we couldn't handle the fault, make
5198diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5199index 76069c1..c2aa816 100644
5200--- a/arch/ia64/mm/hugetlbpage.c
5201+++ b/arch/ia64/mm/hugetlbpage.c
5202@@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5203 unsigned long pgoff, unsigned long flags)
5204 {
5205 struct vm_unmapped_area_info info;
5206+ unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5207
5208 if (len > RGN_MAP_LIMIT)
5209 return -ENOMEM;
5210@@ -172,6 +173,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5211 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5212 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5213 info.align_offset = 0;
5214+ info.threadstack_offset = offset;
5215 return vm_unmapped_area(&info);
5216 }
5217
5218diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5219index b6f7f43..c04320d 100644
5220--- a/arch/ia64/mm/init.c
5221+++ b/arch/ia64/mm/init.c
5222@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5223 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5224 vma->vm_end = vma->vm_start + PAGE_SIZE;
5225 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5226+
5227+#ifdef CONFIG_PAX_PAGEEXEC
5228+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5229+ vma->vm_flags &= ~VM_EXEC;
5230+
5231+#ifdef CONFIG_PAX_MPROTECT
5232+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
5233+ vma->vm_flags &= ~VM_MAYEXEC;
5234+#endif
5235+
5236+ }
5237+#endif
5238+
5239 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5240 down_write(&current->mm->mmap_sem);
5241 if (insert_vm_struct(current->mm, vma)) {
5242diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5243index 40b3ee9..8c2c112 100644
5244--- a/arch/m32r/include/asm/cache.h
5245+++ b/arch/m32r/include/asm/cache.h
5246@@ -1,8 +1,10 @@
5247 #ifndef _ASM_M32R_CACHE_H
5248 #define _ASM_M32R_CACHE_H
5249
5250+#include <linux/const.h>
5251+
5252 /* L1 cache line size */
5253 #define L1_CACHE_SHIFT 4
5254-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5255+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5256
5257 #endif /* _ASM_M32R_CACHE_H */
5258diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5259index 82abd15..d95ae5d 100644
5260--- a/arch/m32r/lib/usercopy.c
5261+++ b/arch/m32r/lib/usercopy.c
5262@@ -14,6 +14,9 @@
5263 unsigned long
5264 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5265 {
5266+ if ((long)n < 0)
5267+ return n;
5268+
5269 prefetch(from);
5270 if (access_ok(VERIFY_WRITE, to, n))
5271 __copy_user(to,from,n);
5272@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5273 unsigned long
5274 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5275 {
5276+ if ((long)n < 0)
5277+ return n;
5278+
5279 prefetchw(to);
5280 if (access_ok(VERIFY_READ, from, n))
5281 __copy_user_zeroing(to,from,n);
5282diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5283index 0395c51..5f26031 100644
5284--- a/arch/m68k/include/asm/cache.h
5285+++ b/arch/m68k/include/asm/cache.h
5286@@ -4,9 +4,11 @@
5287 #ifndef __ARCH_M68K_CACHE_H
5288 #define __ARCH_M68K_CACHE_H
5289
5290+#include <linux/const.h>
5291+
5292 /* bytes per L1 cache line */
5293 #define L1_CACHE_SHIFT 4
5294-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5295+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5296
5297 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5298
5299diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5300index 3c52fa6..11b2ad8 100644
5301--- a/arch/metag/mm/hugetlbpage.c
5302+++ b/arch/metag/mm/hugetlbpage.c
5303@@ -200,6 +200,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5304 info.high_limit = TASK_SIZE;
5305 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5306 info.align_offset = 0;
5307+ info.threadstack_offset = 0;
5308 return vm_unmapped_area(&info);
5309 }
5310
5311diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5312index 4efe96a..60e8699 100644
5313--- a/arch/microblaze/include/asm/cache.h
5314+++ b/arch/microblaze/include/asm/cache.h
5315@@ -13,11 +13,12 @@
5316 #ifndef _ASM_MICROBLAZE_CACHE_H
5317 #define _ASM_MICROBLAZE_CACHE_H
5318
5319+#include <linux/const.h>
5320 #include <asm/registers.h>
5321
5322 #define L1_CACHE_SHIFT 5
5323 /* word-granular cache in microblaze */
5324-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5325+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5326
5327 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5328
5329diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5330index 08b6079..8b554d2 100644
5331--- a/arch/mips/include/asm/atomic.h
5332+++ b/arch/mips/include/asm/atomic.h
5333@@ -21,15 +21,39 @@
5334 #include <asm/cmpxchg.h>
5335 #include <asm/war.h>
5336
5337+#ifdef CONFIG_GENERIC_ATOMIC64
5338+#include <asm-generic/atomic64.h>
5339+#endif
5340+
5341 #define ATOMIC_INIT(i) { (i) }
5342
5343+#ifdef CONFIG_64BIT
5344+#define _ASM_EXTABLE(from, to) \
5345+" .section __ex_table,\"a\"\n" \
5346+" .dword " #from ", " #to"\n" \
5347+" .previous\n"
5348+#else
5349+#define _ASM_EXTABLE(from, to) \
5350+" .section __ex_table,\"a\"\n" \
5351+" .word " #from ", " #to"\n" \
5352+" .previous\n"
5353+#endif
5354+
5355 /*
5356 * atomic_read - read atomic variable
5357 * @v: pointer of type atomic_t
5358 *
5359 * Atomically reads the value of @v.
5360 */
5361-#define atomic_read(v) (*(volatile int *)&(v)->counter)
5362+static inline int atomic_read(const atomic_t *v)
5363+{
5364+ return (*(volatile const int *) &v->counter);
5365+}
5366+
5367+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5368+{
5369+ return (*(volatile const int *) &v->counter);
5370+}
5371
5372 /*
5373 * atomic_set - set atomic variable
5374@@ -38,7 +62,15 @@
5375 *
5376 * Atomically sets the value of @v to @i.
5377 */
5378-#define atomic_set(v, i) ((v)->counter = (i))
5379+static inline void atomic_set(atomic_t *v, int i)
5380+{
5381+ v->counter = i;
5382+}
5383+
5384+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5385+{
5386+ v->counter = i;
5387+}
5388
5389 /*
5390 * atomic_add - add integer to atomic variable
5391@@ -47,7 +79,67 @@
5392 *
5393 * Atomically adds @i to @v.
5394 */
5395-static __inline__ void atomic_add(int i, atomic_t * v)
5396+static __inline__ void atomic_add(int i, atomic_t *v)
5397+{
5398+ int temp;
5399+
5400+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5401+ __asm__ __volatile__(
5402+ " .set mips3 \n"
5403+ "1: ll %0, %1 # atomic_add \n"
5404+#ifdef CONFIG_PAX_REFCOUNT
5405+ /* Exception on overflow. */
5406+ "2: add %0, %2 \n"
5407+#else
5408+ " addu %0, %2 \n"
5409+#endif
5410+ " sc %0, %1 \n"
5411+ " beqzl %0, 1b \n"
5412+#ifdef CONFIG_PAX_REFCOUNT
5413+ "3: \n"
5414+ _ASM_EXTABLE(2b, 3b)
5415+#endif
5416+ " .set mips0 \n"
5417+ : "=&r" (temp), "+m" (v->counter)
5418+ : "Ir" (i));
5419+ } else if (kernel_uses_llsc) {
5420+ __asm__ __volatile__(
5421+ " .set mips3 \n"
5422+ "1: ll %0, %1 # atomic_add \n"
5423+#ifdef CONFIG_PAX_REFCOUNT
5424+ /* Exception on overflow. */
5425+ "2: add %0, %2 \n"
5426+#else
5427+ " addu %0, %2 \n"
5428+#endif
5429+ " sc %0, %1 \n"
5430+ " beqz %0, 1b \n"
5431+#ifdef CONFIG_PAX_REFCOUNT
5432+ "3: \n"
5433+ _ASM_EXTABLE(2b, 3b)
5434+#endif
5435+ " .set mips0 \n"
5436+ : "=&r" (temp), "+m" (v->counter)
5437+ : "Ir" (i));
5438+ } else {
5439+ unsigned long flags;
5440+
5441+ raw_local_irq_save(flags);
5442+ __asm__ __volatile__(
5443+#ifdef CONFIG_PAX_REFCOUNT
5444+ /* Exception on overflow. */
5445+ "1: add %0, %1 \n"
5446+ "2: \n"
5447+ _ASM_EXTABLE(1b, 2b)
5448+#else
5449+ " addu %0, %1 \n"
5450+#endif
5451+ : "+r" (v->counter) : "Ir" (i));
5452+ raw_local_irq_restore(flags);
5453+ }
5454+}
5455+
5456+static __inline__ void atomic_add_unchecked(int i, atomic_unchecked_t *v)
5457 {
5458 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5459 int temp;
5460@@ -90,7 +182,67 @@ static __inline__ void atomic_add(int i, atomic_t * v)
5461 *
5462 * Atomically subtracts @i from @v.
5463 */
5464-static __inline__ void atomic_sub(int i, atomic_t * v)
5465+static __inline__ void atomic_sub(int i, atomic_t *v)
5466+{
5467+ int temp;
5468+
5469+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5470+ __asm__ __volatile__(
5471+ " .set mips3 \n"
5472+ "1: ll %0, %1 # atomic64_sub \n"
5473+#ifdef CONFIG_PAX_REFCOUNT
5474+ /* Exception on overflow. */
5475+ "2: sub %0, %2 \n"
5476+#else
5477+ " subu %0, %2 \n"
5478+#endif
5479+ " sc %0, %1 \n"
5480+ " beqzl %0, 1b \n"
5481+#ifdef CONFIG_PAX_REFCOUNT
5482+ "3: \n"
5483+ _ASM_EXTABLE(2b, 3b)
5484+#endif
5485+ " .set mips0 \n"
5486+ : "=&r" (temp), "+m" (v->counter)
5487+ : "Ir" (i));
5488+ } else if (kernel_uses_llsc) {
5489+ __asm__ __volatile__(
5490+ " .set mips3 \n"
5491+ "1: ll %0, %1 # atomic64_sub \n"
5492+#ifdef CONFIG_PAX_REFCOUNT
5493+ /* Exception on overflow. */
5494+ "2: sub %0, %2 \n"
5495+#else
5496+ " subu %0, %2 \n"
5497+#endif
5498+ " sc %0, %1 \n"
5499+ " beqz %0, 1b \n"
5500+#ifdef CONFIG_PAX_REFCOUNT
5501+ "3: \n"
5502+ _ASM_EXTABLE(2b, 3b)
5503+#endif
5504+ " .set mips0 \n"
5505+ : "=&r" (temp), "+m" (v->counter)
5506+ : "Ir" (i));
5507+ } else {
5508+ unsigned long flags;
5509+
5510+ raw_local_irq_save(flags);
5511+ __asm__ __volatile__(
5512+#ifdef CONFIG_PAX_REFCOUNT
5513+ /* Exception on overflow. */
5514+ "1: sub %0, %1 \n"
5515+ "2: \n"
5516+ _ASM_EXTABLE(1b, 2b)
5517+#else
5518+ " subu %0, %1 \n"
5519+#endif
5520+ : "+r" (v->counter) : "Ir" (i));
5521+ raw_local_irq_restore(flags);
5522+ }
5523+}
5524+
5525+static __inline__ void atomic_sub_unchecked(long i, atomic_unchecked_t *v)
5526 {
5527 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5528 int temp;
5529@@ -129,7 +281,93 @@ static __inline__ void atomic_sub(int i, atomic_t * v)
5530 /*
5531 * Same as above, but return the result value
5532 */
5533-static __inline__ int atomic_add_return(int i, atomic_t * v)
5534+static __inline__ int atomic_add_return(int i, atomic_t *v)
5535+{
5536+ int result;
5537+ int temp;
5538+
5539+ smp_mb__before_llsc();
5540+
5541+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5542+ __asm__ __volatile__(
5543+ " .set mips3 \n"
5544+ "1: ll %1, %2 # atomic_add_return \n"
5545+#ifdef CONFIG_PAX_REFCOUNT
5546+ "2: add %0, %1, %3 \n"
5547+#else
5548+ " addu %0, %1, %3 \n"
5549+#endif
5550+ " sc %0, %2 \n"
5551+ " beqzl %0, 1b \n"
5552+#ifdef CONFIG_PAX_REFCOUNT
5553+ " b 4f \n"
5554+ " .set noreorder \n"
5555+ "3: b 5f \n"
5556+ " move %0, %1 \n"
5557+ " .set reorder \n"
5558+ _ASM_EXTABLE(2b, 3b)
5559+#endif
5560+ "4: addu %0, %1, %3 \n"
5561+#ifdef CONFIG_PAX_REFCOUNT
5562+ "5: \n"
5563+#endif
5564+ " .set mips0 \n"
5565+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5566+ : "Ir" (i));
5567+ } else if (kernel_uses_llsc) {
5568+ __asm__ __volatile__(
5569+ " .set mips3 \n"
5570+ "1: ll %1, %2 # atomic_add_return \n"
5571+#ifdef CONFIG_PAX_REFCOUNT
5572+ "2: add %0, %1, %3 \n"
5573+#else
5574+ " addu %0, %1, %3 \n"
5575+#endif
5576+ " sc %0, %2 \n"
5577+ " bnez %0, 4f \n"
5578+ " b 1b \n"
5579+#ifdef CONFIG_PAX_REFCOUNT
5580+ " .set noreorder \n"
5581+ "3: b 5f \n"
5582+ " move %0, %1 \n"
5583+ " .set reorder \n"
5584+ _ASM_EXTABLE(2b, 3b)
5585+#endif
5586+ "4: addu %0, %1, %3 \n"
5587+#ifdef CONFIG_PAX_REFCOUNT
5588+ "5: \n"
5589+#endif
5590+ " .set mips0 \n"
5591+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5592+ : "Ir" (i));
5593+ } else {
5594+ unsigned long flags;
5595+
5596+ raw_local_irq_save(flags);
5597+ __asm__ __volatile__(
5598+ " lw %0, %1 \n"
5599+#ifdef CONFIG_PAX_REFCOUNT
5600+ /* Exception on overflow. */
5601+ "1: add %0, %2 \n"
5602+#else
5603+ " addu %0, %2 \n"
5604+#endif
5605+ " sw %0, %1 \n"
5606+#ifdef CONFIG_PAX_REFCOUNT
5607+ /* Note: Dest reg is not modified on overflow */
5608+ "2: \n"
5609+ _ASM_EXTABLE(1b, 2b)
5610+#endif
5611+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5612+ raw_local_irq_restore(flags);
5613+ }
5614+
5615+ smp_llsc_mb();
5616+
5617+ return result;
5618+}
5619+
5620+static __inline__ int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5621 {
5622 int result;
5623
5624@@ -178,7 +416,93 @@ static __inline__ int atomic_add_return(int i, atomic_t * v)
5625 return result;
5626 }
5627
5628-static __inline__ int atomic_sub_return(int i, atomic_t * v)
5629+static __inline__ int atomic_sub_return(int i, atomic_t *v)
5630+{
5631+ int result;
5632+ int temp;
5633+
5634+ smp_mb__before_llsc();
5635+
5636+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5637+ __asm__ __volatile__(
5638+ " .set mips3 \n"
5639+ "1: ll %1, %2 # atomic_sub_return \n"
5640+#ifdef CONFIG_PAX_REFCOUNT
5641+ "2: sub %0, %1, %3 \n"
5642+#else
5643+ " subu %0, %1, %3 \n"
5644+#endif
5645+ " sc %0, %2 \n"
5646+ " beqzl %0, 1b \n"
5647+#ifdef CONFIG_PAX_REFCOUNT
5648+ " b 4f \n"
5649+ " .set noreorder \n"
5650+ "3: b 5f \n"
5651+ " move %0, %1 \n"
5652+ " .set reorder \n"
5653+ _ASM_EXTABLE(2b, 3b)
5654+#endif
5655+ "4: subu %0, %1, %3 \n"
5656+#ifdef CONFIG_PAX_REFCOUNT
5657+ "5: \n"
5658+#endif
5659+ " .set mips0 \n"
5660+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
5661+ : "Ir" (i), "m" (v->counter)
5662+ : "memory");
5663+ } else if (kernel_uses_llsc) {
5664+ __asm__ __volatile__(
5665+ " .set mips3 \n"
5666+ "1: ll %1, %2 # atomic_sub_return \n"
5667+#ifdef CONFIG_PAX_REFCOUNT
5668+ "2: sub %0, %1, %3 \n"
5669+#else
5670+ " subu %0, %1, %3 \n"
5671+#endif
5672+ " sc %0, %2 \n"
5673+ " bnez %0, 4f \n"
5674+ " b 1b \n"
5675+#ifdef CONFIG_PAX_REFCOUNT
5676+ " .set noreorder \n"
5677+ "3: b 5f \n"
5678+ " move %0, %1 \n"
5679+ " .set reorder \n"
5680+ _ASM_EXTABLE(2b, 3b)
5681+#endif
5682+ "4: subu %0, %1, %3 \n"
5683+#ifdef CONFIG_PAX_REFCOUNT
5684+ "5: \n"
5685+#endif
5686+ " .set mips0 \n"
5687+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5688+ : "Ir" (i));
5689+ } else {
5690+ unsigned long flags;
5691+
5692+ raw_local_irq_save(flags);
5693+ __asm__ __volatile__(
5694+ " lw %0, %1 \n"
5695+#ifdef CONFIG_PAX_REFCOUNT
5696+ /* Exception on overflow. */
5697+ "1: sub %0, %2 \n"
5698+#else
5699+ " subu %0, %2 \n"
5700+#endif
5701+ " sw %0, %1 \n"
5702+#ifdef CONFIG_PAX_REFCOUNT
5703+ /* Note: Dest reg is not modified on overflow */
5704+ "2: \n"
5705+ _ASM_EXTABLE(1b, 2b)
5706+#endif
5707+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5708+ raw_local_irq_restore(flags);
5709+ }
5710+
5711+ smp_llsc_mb();
5712+
5713+ return result;
5714+}
5715+static __inline__ int atomic_sub_return_unchecked(int i, atomic_unchecked_t *v)
5716 {
5717 int result;
5718
5719@@ -238,7 +562,7 @@ static __inline__ int atomic_sub_return(int i, atomic_t * v)
5720 * Atomically test @v and subtract @i if @v is greater or equal than @i.
5721 * The function returns the old value of @v minus @i.
5722 */
5723-static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5724+static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
5725 {
5726 int result;
5727
5728@@ -295,8 +619,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5729 return result;
5730 }
5731
5732-#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5733-#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
5734+static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
5735+{
5736+ return cmpxchg(&v->counter, old, new);
5737+}
5738+
5739+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
5740+ int new)
5741+{
5742+ return cmpxchg(&(v->counter), old, new);
5743+}
5744+
5745+static inline int atomic_xchg(atomic_t *v, int new)
5746+{
5747+ return xchg(&v->counter, new);
5748+}
5749+
5750+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5751+{
5752+ return xchg(&(v->counter), new);
5753+}
5754
5755 /**
5756 * __atomic_add_unless - add unless the number is a given value
5757@@ -324,6 +666,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5758
5759 #define atomic_dec_return(v) atomic_sub_return(1, (v))
5760 #define atomic_inc_return(v) atomic_add_return(1, (v))
5761+static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5762+{
5763+ return atomic_add_return_unchecked(1, v);
5764+}
5765
5766 /*
5767 * atomic_sub_and_test - subtract value from variable and test result
5768@@ -345,6 +691,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5769 * other cases.
5770 */
5771 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5772+static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5773+{
5774+ return atomic_add_return_unchecked(1, v) == 0;
5775+}
5776
5777 /*
5778 * atomic_dec_and_test - decrement by 1 and test
5779@@ -369,6 +719,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5780 * Atomically increments @v by 1.
5781 */
5782 #define atomic_inc(v) atomic_add(1, (v))
5783+static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
5784+{
5785+ atomic_add_unchecked(1, v);
5786+}
5787
5788 /*
5789 * atomic_dec - decrement and test
5790@@ -377,6 +731,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5791 * Atomically decrements @v by 1.
5792 */
5793 #define atomic_dec(v) atomic_sub(1, (v))
5794+static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
5795+{
5796+ atomic_sub_unchecked(1, v);
5797+}
5798
5799 /*
5800 * atomic_add_negative - add and test if negative
5801@@ -398,14 +756,30 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5802 * @v: pointer of type atomic64_t
5803 *
5804 */
5805-#define atomic64_read(v) (*(volatile long *)&(v)->counter)
5806+static inline long atomic64_read(const atomic64_t *v)
5807+{
5808+ return (*(volatile const long *) &v->counter);
5809+}
5810+
5811+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5812+{
5813+ return (*(volatile const long *) &v->counter);
5814+}
5815
5816 /*
5817 * atomic64_set - set atomic variable
5818 * @v: pointer of type atomic64_t
5819 * @i: required value
5820 */
5821-#define atomic64_set(v, i) ((v)->counter = (i))
5822+static inline void atomic64_set(atomic64_t *v, long i)
5823+{
5824+ v->counter = i;
5825+}
5826+
5827+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5828+{
5829+ v->counter = i;
5830+}
5831
5832 /*
5833 * atomic64_add - add integer to atomic variable
5834@@ -414,7 +788,66 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5835 *
5836 * Atomically adds @i to @v.
5837 */
5838-static __inline__ void atomic64_add(long i, atomic64_t * v)
5839+static __inline__ void atomic64_add(long i, atomic64_t *v)
5840+{
5841+ long temp;
5842+
5843+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5844+ __asm__ __volatile__(
5845+ " .set mips3 \n"
5846+ "1: lld %0, %1 # atomic64_add \n"
5847+#ifdef CONFIG_PAX_REFCOUNT
5848+ /* Exception on overflow. */
5849+ "2: dadd %0, %2 \n"
5850+#else
5851+ " daddu %0, %2 \n"
5852+#endif
5853+ " scd %0, %1 \n"
5854+ " beqzl %0, 1b \n"
5855+#ifdef CONFIG_PAX_REFCOUNT
5856+ "3: \n"
5857+ _ASM_EXTABLE(2b, 3b)
5858+#endif
5859+ " .set mips0 \n"
5860+ : "=&r" (temp), "+m" (v->counter)
5861+ : "Ir" (i));
5862+ } else if (kernel_uses_llsc) {
5863+ __asm__ __volatile__(
5864+ " .set mips3 \n"
5865+ "1: lld %0, %1 # atomic64_add \n"
5866+#ifdef CONFIG_PAX_REFCOUNT
5867+ /* Exception on overflow. */
5868+ "2: dadd %0, %2 \n"
5869+#else
5870+ " daddu %0, %2 \n"
5871+#endif
5872+ " scd %0, %1 \n"
5873+ " beqz %0, 1b \n"
5874+#ifdef CONFIG_PAX_REFCOUNT
5875+ "3: \n"
5876+ _ASM_EXTABLE(2b, 3b)
5877+#endif
5878+ " .set mips0 \n"
5879+ : "=&r" (temp), "+m" (v->counter)
5880+ : "Ir" (i));
5881+ } else {
5882+ unsigned long flags;
5883+
5884+ raw_local_irq_save(flags);
5885+ __asm__ __volatile__(
5886+#ifdef CONFIG_PAX_REFCOUNT
5887+ /* Exception on overflow. */
5888+ "1: dadd %0, %1 \n"
5889+ "2: \n"
5890+ _ASM_EXTABLE(1b, 2b)
5891+#else
5892+ " daddu %0, %1 \n"
5893+#endif
5894+ : "+r" (v->counter) : "Ir" (i));
5895+ raw_local_irq_restore(flags);
5896+ }
5897+}
5898+static __inline__ void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
5899 {
5900 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5901 long temp;
5902@@ -457,7 +890,67 @@ static __inline__ void atomic64_add(long i, atomic64_t * v)
5903 *
5904 * Atomically subtracts @i from @v.
5905 */
5906-static __inline__ void atomic64_sub(long i, atomic64_t * v)
5907+static __inline__ void atomic64_sub(long i, atomic64_t *v)
5908+{
5909+ long temp;
5910+
5911+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5912+ __asm__ __volatile__(
5913+ " .set mips3 \n"
5914+ "1: lld %0, %1 # atomic64_sub \n"
5915+#ifdef CONFIG_PAX_REFCOUNT
5916+ /* Exception on overflow. */
5917+ "2: dsub %0, %2 \n"
5918+#else
5919+ " dsubu %0, %2 \n"
5920+#endif
5921+ " scd %0, %1 \n"
5922+ " beqzl %0, 1b \n"
5923+#ifdef CONFIG_PAX_REFCOUNT
5924+ "3: \n"
5925+ _ASM_EXTABLE(2b, 3b)
5926+#endif
5927+ " .set mips0 \n"
5928+ : "=&r" (temp), "+m" (v->counter)
5929+ : "Ir" (i));
5930+ } else if (kernel_uses_llsc) {
5931+ __asm__ __volatile__(
5932+ " .set mips3 \n"
5933+ "1: lld %0, %1 # atomic64_sub \n"
5934+#ifdef CONFIG_PAX_REFCOUNT
5935+ /* Exception on overflow. */
5936+ "2: dsub %0, %2 \n"
5937+#else
5938+ " dsubu %0, %2 \n"
5939+#endif
5940+ " scd %0, %1 \n"
5941+ " beqz %0, 1b \n"
5942+#ifdef CONFIG_PAX_REFCOUNT
5943+ "3: \n"
5944+ _ASM_EXTABLE(2b, 3b)
5945+#endif
5946+ " .set mips0 \n"
5947+ : "=&r" (temp), "+m" (v->counter)
5948+ : "Ir" (i));
5949+ } else {
5950+ unsigned long flags;
5951+
5952+ raw_local_irq_save(flags);
5953+ __asm__ __volatile__(
5954+#ifdef CONFIG_PAX_REFCOUNT
5955+ /* Exception on overflow. */
5956+ "1: dsub %0, %1 \n"
5957+ "2: \n"
5958+ _ASM_EXTABLE(1b, 2b)
5959+#else
5960+ " dsubu %0, %1 \n"
5961+#endif
5962+ : "+r" (v->counter) : "Ir" (i));
5963+ raw_local_irq_restore(flags);
5964+ }
5965+}
5966+
5967+static __inline__ void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
5968 {
5969 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5970 long temp;
5971@@ -496,7 +989,93 @@ static __inline__ void atomic64_sub(long i, atomic64_t * v)
5972 /*
5973 * Same as above, but return the result value
5974 */
5975-static __inline__ long atomic64_add_return(long i, atomic64_t * v)
5976+static __inline__ long atomic64_add_return(long i, atomic64_t *v)
5977+{
5978+ long result;
5979+ long temp;
5980+
5981+ smp_mb__before_llsc();
5982+
5983+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5984+ __asm__ __volatile__(
5985+ " .set mips3 \n"
5986+ "1: lld %1, %2 # atomic64_add_return \n"
5987+#ifdef CONFIG_PAX_REFCOUNT
5988+ "2: dadd %0, %1, %3 \n"
5989+#else
5990+ " daddu %0, %1, %3 \n"
5991+#endif
5992+ " scd %0, %2 \n"
5993+ " beqzl %0, 1b \n"
5994+#ifdef CONFIG_PAX_REFCOUNT
5995+ " b 4f \n"
5996+ " .set noreorder \n"
5997+ "3: b 5f \n"
5998+ " move %0, %1 \n"
5999+ " .set reorder \n"
6000+ _ASM_EXTABLE(2b, 3b)
6001+#endif
6002+ "4: daddu %0, %1, %3 \n"
6003+#ifdef CONFIG_PAX_REFCOUNT
6004+ "5: \n"
6005+#endif
6006+ " .set mips0 \n"
6007+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6008+ : "Ir" (i));
6009+ } else if (kernel_uses_llsc) {
6010+ __asm__ __volatile__(
6011+ " .set mips3 \n"
6012+ "1: lld %1, %2 # atomic64_add_return \n"
6013+#ifdef CONFIG_PAX_REFCOUNT
6014+ "2: dadd %0, %1, %3 \n"
6015+#else
6016+ " daddu %0, %1, %3 \n"
6017+#endif
6018+ " scd %0, %2 \n"
6019+ " bnez %0, 4f \n"
6020+ " b 1b \n"
6021+#ifdef CONFIG_PAX_REFCOUNT
6022+ " .set noreorder \n"
6023+ "3: b 5f \n"
6024+ " move %0, %1 \n"
6025+ " .set reorder \n"
6026+ _ASM_EXTABLE(2b, 3b)
6027+#endif
6028+ "4: daddu %0, %1, %3 \n"
6029+#ifdef CONFIG_PAX_REFCOUNT
6030+ "5: \n"
6031+#endif
6032+ " .set mips0 \n"
6033+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6034+ : "Ir" (i), "m" (v->counter)
6035+ : "memory");
6036+ } else {
6037+ unsigned long flags;
6038+
6039+ raw_local_irq_save(flags);
6040+ __asm__ __volatile__(
6041+ " ld %0, %1 \n"
6042+#ifdef CONFIG_PAX_REFCOUNT
6043+ /* Exception on overflow. */
6044+ "1: dadd %0, %2 \n"
6045+#else
6046+ " daddu %0, %2 \n"
6047+#endif
6048+ " sd %0, %1 \n"
6049+#ifdef CONFIG_PAX_REFCOUNT
6050+ /* Note: Dest reg is not modified on overflow */
6051+ "2: \n"
6052+ _ASM_EXTABLE(1b, 2b)
6053+#endif
6054+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6055+ raw_local_irq_restore(flags);
6056+ }
6057+
6058+ smp_llsc_mb();
6059+
6060+ return result;
6061+}
6062+static __inline__ long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6063 {
6064 long result;
6065
6066@@ -546,7 +1125,97 @@ static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6067 return result;
6068 }
6069
6070-static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6071+static __inline__ long atomic64_sub_return(long i, atomic64_t *v)
6072+{
6073+ long result;
6074+ long temp;
6075+
6076+ smp_mb__before_llsc();
6077+
6078+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6079+ long temp;
6080+
6081+ __asm__ __volatile__(
6082+ " .set mips3 \n"
6083+ "1: lld %1, %2 # atomic64_sub_return \n"
6084+#ifdef CONFIG_PAX_REFCOUNT
6085+ "2: dsub %0, %1, %3 \n"
6086+#else
6087+ " dsubu %0, %1, %3 \n"
6088+#endif
6089+ " scd %0, %2 \n"
6090+ " beqzl %0, 1b \n"
6091+#ifdef CONFIG_PAX_REFCOUNT
6092+ " b 4f \n"
6093+ " .set noreorder \n"
6094+ "3: b 5f \n"
6095+ " move %0, %1 \n"
6096+ " .set reorder \n"
6097+ _ASM_EXTABLE(2b, 3b)
6098+#endif
6099+ "4: dsubu %0, %1, %3 \n"
6100+#ifdef CONFIG_PAX_REFCOUNT
6101+ "5: \n"
6102+#endif
6103+ " .set mips0 \n"
6104+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6105+ : "Ir" (i), "m" (v->counter)
6106+ : "memory");
6107+ } else if (kernel_uses_llsc) {
6108+ __asm__ __volatile__(
6109+ " .set mips3 \n"
6110+ "1: lld %1, %2 # atomic64_sub_return \n"
6111+#ifdef CONFIG_PAX_REFCOUNT
6112+ "2: dsub %0, %1, %3 \n"
6113+#else
6114+ " dsubu %0, %1, %3 \n"
6115+#endif
6116+ " scd %0, %2 \n"
6117+ " bnez %0, 4f \n"
6118+ " b 1b \n"
6119+#ifdef CONFIG_PAX_REFCOUNT
6120+ " .set noreorder \n"
6121+ "3: b 5f \n"
6122+ " move %0, %1 \n"
6123+ " .set reorder \n"
6124+ _ASM_EXTABLE(2b, 3b)
6125+#endif
6126+ "4: dsubu %0, %1, %3 \n"
6127+#ifdef CONFIG_PAX_REFCOUNT
6128+ "5: \n"
6129+#endif
6130+ " .set mips0 \n"
6131+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6132+ : "Ir" (i), "m" (v->counter)
6133+ : "memory");
6134+ } else {
6135+ unsigned long flags;
6136+
6137+ raw_local_irq_save(flags);
6138+ __asm__ __volatile__(
6139+ " ld %0, %1 \n"
6140+#ifdef CONFIG_PAX_REFCOUNT
6141+ /* Exception on overflow. */
6142+ "1: dsub %0, %2 \n"
6143+#else
6144+ " dsubu %0, %2 \n"
6145+#endif
6146+ " sd %0, %1 \n"
6147+#ifdef CONFIG_PAX_REFCOUNT
6148+ /* Note: Dest reg is not modified on overflow */
6149+ "2: \n"
6150+ _ASM_EXTABLE(1b, 2b)
6151+#endif
6152+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6153+ raw_local_irq_restore(flags);
6154+ }
6155+
6156+ smp_llsc_mb();
6157+
6158+ return result;
6159+}
6160+
6161+static __inline__ long atomic64_sub_return_unchecked(long i, atomic64_unchecked_t *v)
6162 {
6163 long result;
6164
6165@@ -605,7 +1274,7 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6166 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6167 * The function returns the old value of @v minus @i.
6168 */
6169-static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6170+static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6171 {
6172 long result;
6173
6174@@ -662,9 +1331,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6175 return result;
6176 }
6177
6178-#define atomic64_cmpxchg(v, o, n) \
6179- ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6180-#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6181+static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6182+{
6183+ return cmpxchg(&v->counter, old, new);
6184+}
6185+
6186+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
6187+ long new)
6188+{
6189+ return cmpxchg(&(v->counter), old, new);
6190+}
6191+
6192+static inline long atomic64_xchg(atomic64_t *v, long new)
6193+{
6194+ return xchg(&v->counter, new);
6195+}
6196+
6197+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6198+{
6199+ return xchg(&(v->counter), new);
6200+}
6201
6202 /**
6203 * atomic64_add_unless - add unless the number is a given value
6204@@ -694,6 +1380,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6205
6206 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
6207 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
6208+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
6209
6210 /*
6211 * atomic64_sub_and_test - subtract value from variable and test result
6212@@ -715,6 +1402,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6213 * other cases.
6214 */
6215 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6216+#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
6217
6218 /*
6219 * atomic64_dec_and_test - decrement by 1 and test
6220@@ -739,6 +1427,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6221 * Atomically increments @v by 1.
6222 */
6223 #define atomic64_inc(v) atomic64_add(1, (v))
6224+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
6225
6226 /*
6227 * atomic64_dec - decrement and test
6228@@ -747,6 +1436,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6229 * Atomically decrements @v by 1.
6230 */
6231 #define atomic64_dec(v) atomic64_sub(1, (v))
6232+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
6233
6234 /*
6235 * atomic64_add_negative - add and test if negative
6236diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
6237index b4db69f..8f3b093 100644
6238--- a/arch/mips/include/asm/cache.h
6239+++ b/arch/mips/include/asm/cache.h
6240@@ -9,10 +9,11 @@
6241 #ifndef _ASM_CACHE_H
6242 #define _ASM_CACHE_H
6243
6244+#include <linux/const.h>
6245 #include <kmalloc.h>
6246
6247 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
6248-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6249+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6250
6251 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
6252 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6253diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
6254index cf3ae24..238d22f 100644
6255--- a/arch/mips/include/asm/elf.h
6256+++ b/arch/mips/include/asm/elf.h
6257@@ -372,13 +372,16 @@ extern const char *__elf_platform;
6258 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
6259 #endif
6260
6261+#ifdef CONFIG_PAX_ASLR
6262+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6263+
6264+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6265+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6266+#endif
6267+
6268 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6269 struct linux_binprm;
6270 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6271 int uses_interp);
6272
6273-struct mm_struct;
6274-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6275-#define arch_randomize_brk arch_randomize_brk
6276-
6277 #endif /* _ASM_ELF_H */
6278diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
6279index c1f6afa..38cc6e9 100644
6280--- a/arch/mips/include/asm/exec.h
6281+++ b/arch/mips/include/asm/exec.h
6282@@ -12,6 +12,6 @@
6283 #ifndef _ASM_EXEC_H
6284 #define _ASM_EXEC_H
6285
6286-extern unsigned long arch_align_stack(unsigned long sp);
6287+#define arch_align_stack(x) ((x) & ~0xfUL)
6288
6289 #endif /* _ASM_EXEC_H */
6290diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
6291index d44622c..64990d2 100644
6292--- a/arch/mips/include/asm/local.h
6293+++ b/arch/mips/include/asm/local.h
6294@@ -12,15 +12,25 @@ typedef struct
6295 atomic_long_t a;
6296 } local_t;
6297
6298+typedef struct {
6299+ atomic_long_unchecked_t a;
6300+} local_unchecked_t;
6301+
6302 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
6303
6304 #define local_read(l) atomic_long_read(&(l)->a)
6305+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
6306 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
6307+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
6308
6309 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
6310+#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
6311 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
6312+#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
6313 #define local_inc(l) atomic_long_inc(&(l)->a)
6314+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
6315 #define local_dec(l) atomic_long_dec(&(l)->a)
6316+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
6317
6318 /*
6319 * Same as above, but return the result value
6320@@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
6321 return result;
6322 }
6323
6324+static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
6325+{
6326+ unsigned long result;
6327+
6328+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6329+ unsigned long temp;
6330+
6331+ __asm__ __volatile__(
6332+ " .set mips3 \n"
6333+ "1:" __LL "%1, %2 # local_add_return \n"
6334+ " addu %0, %1, %3 \n"
6335+ __SC "%0, %2 \n"
6336+ " beqzl %0, 1b \n"
6337+ " addu %0, %1, %3 \n"
6338+ " .set mips0 \n"
6339+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6340+ : "Ir" (i), "m" (l->a.counter)
6341+ : "memory");
6342+ } else if (kernel_uses_llsc) {
6343+ unsigned long temp;
6344+
6345+ __asm__ __volatile__(
6346+ " .set mips3 \n"
6347+ "1:" __LL "%1, %2 # local_add_return \n"
6348+ " addu %0, %1, %3 \n"
6349+ __SC "%0, %2 \n"
6350+ " beqz %0, 1b \n"
6351+ " addu %0, %1, %3 \n"
6352+ " .set mips0 \n"
6353+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6354+ : "Ir" (i), "m" (l->a.counter)
6355+ : "memory");
6356+ } else {
6357+ unsigned long flags;
6358+
6359+ local_irq_save(flags);
6360+ result = l->a.counter;
6361+ result += i;
6362+ l->a.counter = result;
6363+ local_irq_restore(flags);
6364+ }
6365+
6366+ return result;
6367+}
6368+
6369 static __inline__ long local_sub_return(long i, local_t * l)
6370 {
6371 unsigned long result;
6372@@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
6373
6374 #define local_cmpxchg(l, o, n) \
6375 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6376+#define local_cmpxchg_unchecked(l, o, n) \
6377+ ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6378 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
6379
6380 /**
6381diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
6382index f6be474..12ad554 100644
6383--- a/arch/mips/include/asm/page.h
6384+++ b/arch/mips/include/asm/page.h
6385@@ -95,7 +95,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
6386 #ifdef CONFIG_CPU_MIPS32
6387 typedef struct { unsigned long pte_low, pte_high; } pte_t;
6388 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
6389- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
6390+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
6391 #else
6392 typedef struct { unsigned long long pte; } pte_t;
6393 #define pte_val(x) ((x).pte)
6394diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
6395index 881d18b..cea38bc 100644
6396--- a/arch/mips/include/asm/pgalloc.h
6397+++ b/arch/mips/include/asm/pgalloc.h
6398@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6399 {
6400 set_pud(pud, __pud((unsigned long)pmd));
6401 }
6402+
6403+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6404+{
6405+ pud_populate(mm, pud, pmd);
6406+}
6407 #endif
6408
6409 /*
6410diff --git a/arch/mips/include/asm/smtc_proc.h b/arch/mips/include/asm/smtc_proc.h
6411index 25da651..ae2a259 100644
6412--- a/arch/mips/include/asm/smtc_proc.h
6413+++ b/arch/mips/include/asm/smtc_proc.h
6414@@ -18,6 +18,6 @@ extern struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6415
6416 /* Count of number of recoveries of "stolen" FPU access rights on 34K */
6417
6418-extern atomic_t smtc_fpu_recoveries;
6419+extern atomic_unchecked_t smtc_fpu_recoveries;
6420
6421 #endif /* __ASM_SMTC_PROC_H */
6422diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
6423index 61215a3..213ee0e 100644
6424--- a/arch/mips/include/asm/thread_info.h
6425+++ b/arch/mips/include/asm/thread_info.h
6426@@ -116,6 +116,8 @@ static inline struct thread_info *current_thread_info(void)
6427 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
6428 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
6429 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
6430+/* li takes a 32bit immediate */
6431+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
6432 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
6433
6434 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6435@@ -132,20 +134,18 @@ static inline struct thread_info *current_thread_info(void)
6436 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
6437 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
6438 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
6439+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6440
6441-#define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6442- _TIF_SYSCALL_AUDIT)
6443+#define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
6444
6445 /* work to do in syscall_trace_leave() */
6446-#define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6447- _TIF_SYSCALL_AUDIT)
6448+#define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
6449
6450 /* work to do on interrupt/exception return */
6451 #define _TIF_WORK_MASK \
6452 (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_NOTIFY_RESUME)
6453 /* work to do on any return to u-space */
6454-#define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
6455- _TIF_WORK_SYSCALL_EXIT)
6456+#define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT | _TIF_GRSEC_SETXID)
6457
6458 #endif /* __KERNEL__ */
6459
6460diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
6461index 1188e00..41cf144 100644
6462--- a/arch/mips/kernel/binfmt_elfn32.c
6463+++ b/arch/mips/kernel/binfmt_elfn32.c
6464@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6465 #undef ELF_ET_DYN_BASE
6466 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6467
6468+#ifdef CONFIG_PAX_ASLR
6469+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6470+
6471+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6472+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6473+#endif
6474+
6475 #include <asm/processor.h>
6476 #include <linux/module.h>
6477 #include <linux/elfcore.h>
6478diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
6479index 202e581..689ca79 100644
6480--- a/arch/mips/kernel/binfmt_elfo32.c
6481+++ b/arch/mips/kernel/binfmt_elfo32.c
6482@@ -56,6 +56,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6483 #undef ELF_ET_DYN_BASE
6484 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6485
6486+#ifdef CONFIG_PAX_ASLR
6487+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6488+
6489+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6490+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6491+#endif
6492+
6493 #include <asm/processor.h>
6494
6495 /*
6496diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
6497index d1fea7a..45602ea 100644
6498--- a/arch/mips/kernel/irq.c
6499+++ b/arch/mips/kernel/irq.c
6500@@ -77,17 +77,17 @@ void ack_bad_irq(unsigned int irq)
6501 printk("unexpected IRQ # %d\n", irq);
6502 }
6503
6504-atomic_t irq_err_count;
6505+atomic_unchecked_t irq_err_count;
6506
6507 int arch_show_interrupts(struct seq_file *p, int prec)
6508 {
6509- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
6510+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
6511 return 0;
6512 }
6513
6514 asmlinkage void spurious_interrupt(void)
6515 {
6516- atomic_inc(&irq_err_count);
6517+ atomic_inc_unchecked(&irq_err_count);
6518 }
6519
6520 void __init init_IRQ(void)
6521diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
6522index ddc7610..8c58f17 100644
6523--- a/arch/mips/kernel/process.c
6524+++ b/arch/mips/kernel/process.c
6525@@ -566,15 +566,3 @@ unsigned long get_wchan(struct task_struct *task)
6526 out:
6527 return pc;
6528 }
6529-
6530-/*
6531- * Don't forget that the stack pointer must be aligned on a 8 bytes
6532- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
6533- */
6534-unsigned long arch_align_stack(unsigned long sp)
6535-{
6536- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6537- sp -= get_random_int() & ~PAGE_MASK;
6538-
6539- return sp & ALMASK;
6540-}
6541diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
6542index 8ae1ebe..1bcbf47 100644
6543--- a/arch/mips/kernel/ptrace.c
6544+++ b/arch/mips/kernel/ptrace.c
6545@@ -529,6 +529,10 @@ static inline int audit_arch(void)
6546 return arch;
6547 }
6548
6549+#ifdef CONFIG_GRKERNSEC_SETXID
6550+extern void gr_delayed_cred_worker(void);
6551+#endif
6552+
6553 /*
6554 * Notification of system call entry/exit
6555 * - triggered by current->work.syscall_trace
6556@@ -540,6 +544,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
6557 /* do the secure computing check first */
6558 secure_computing_strict(regs->regs[2]);
6559
6560+#ifdef CONFIG_GRKERNSEC_SETXID
6561+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6562+ gr_delayed_cred_worker();
6563+#endif
6564+
6565 if (!(current->ptrace & PT_PTRACED))
6566 goto out;
6567
6568diff --git a/arch/mips/kernel/smtc-proc.c b/arch/mips/kernel/smtc-proc.c
6569index c10aa84..9ec2e60 100644
6570--- a/arch/mips/kernel/smtc-proc.c
6571+++ b/arch/mips/kernel/smtc-proc.c
6572@@ -31,7 +31,7 @@ unsigned long selfipis[NR_CPUS];
6573
6574 struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6575
6576-atomic_t smtc_fpu_recoveries;
6577+atomic_unchecked_t smtc_fpu_recoveries;
6578
6579 static int smtc_proc_show(struct seq_file *m, void *v)
6580 {
6581@@ -48,7 +48,7 @@ static int smtc_proc_show(struct seq_file *m, void *v)
6582 for(i = 0; i < NR_CPUS; i++)
6583 seq_printf(m, "%d: %ld\n", i, smtc_cpu_stats[i].selfipis);
6584 seq_printf(m, "%d Recoveries of \"stolen\" FPU\n",
6585- atomic_read(&smtc_fpu_recoveries));
6586+ atomic_read_unchecked(&smtc_fpu_recoveries));
6587 return 0;
6588 }
6589
6590@@ -73,7 +73,7 @@ void init_smtc_stats(void)
6591 smtc_cpu_stats[i].selfipis = 0;
6592 }
6593
6594- atomic_set(&smtc_fpu_recoveries, 0);
6595+ atomic_set_unchecked(&smtc_fpu_recoveries, 0);
6596
6597 proc_create("smtc", 0444, NULL, &smtc_proc_fops);
6598 }
6599diff --git a/arch/mips/kernel/smtc.c b/arch/mips/kernel/smtc.c
6600index dfc1b91..11a2c07 100644
6601--- a/arch/mips/kernel/smtc.c
6602+++ b/arch/mips/kernel/smtc.c
6603@@ -1359,7 +1359,7 @@ void smtc_soft_dump(void)
6604 }
6605 smtc_ipi_qdump();
6606 printk("%d Recoveries of \"stolen\" FPU\n",
6607- atomic_read(&smtc_fpu_recoveries));
6608+ atomic_read_unchecked(&smtc_fpu_recoveries));
6609 }
6610
6611
6612diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
6613index 84536bf..79caa4d 100644
6614--- a/arch/mips/kernel/sync-r4k.c
6615+++ b/arch/mips/kernel/sync-r4k.c
6616@@ -21,8 +21,8 @@
6617 #include <asm/mipsregs.h>
6618
6619 static atomic_t count_start_flag = ATOMIC_INIT(0);
6620-static atomic_t count_count_start = ATOMIC_INIT(0);
6621-static atomic_t count_count_stop = ATOMIC_INIT(0);
6622+static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
6623+static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
6624 static atomic_t count_reference = ATOMIC_INIT(0);
6625
6626 #define COUNTON 100
6627@@ -69,13 +69,13 @@ void synchronise_count_master(int cpu)
6628
6629 for (i = 0; i < NR_LOOPS; i++) {
6630 /* slaves loop on '!= 2' */
6631- while (atomic_read(&count_count_start) != 1)
6632+ while (atomic_read_unchecked(&count_count_start) != 1)
6633 mb();
6634- atomic_set(&count_count_stop, 0);
6635+ atomic_set_unchecked(&count_count_stop, 0);
6636 smp_wmb();
6637
6638 /* this lets the slaves write their count register */
6639- atomic_inc(&count_count_start);
6640+ atomic_inc_unchecked(&count_count_start);
6641
6642 /*
6643 * Everyone initialises count in the last loop:
6644@@ -86,11 +86,11 @@ void synchronise_count_master(int cpu)
6645 /*
6646 * Wait for all slaves to leave the synchronization point:
6647 */
6648- while (atomic_read(&count_count_stop) != 1)
6649+ while (atomic_read_unchecked(&count_count_stop) != 1)
6650 mb();
6651- atomic_set(&count_count_start, 0);
6652+ atomic_set_unchecked(&count_count_start, 0);
6653 smp_wmb();
6654- atomic_inc(&count_count_stop);
6655+ atomic_inc_unchecked(&count_count_stop);
6656 }
6657 /* Arrange for an interrupt in a short while */
6658 write_c0_compare(read_c0_count() + COUNTON);
6659@@ -131,8 +131,8 @@ void synchronise_count_slave(int cpu)
6660 initcount = atomic_read(&count_reference);
6661
6662 for (i = 0; i < NR_LOOPS; i++) {
6663- atomic_inc(&count_count_start);
6664- while (atomic_read(&count_count_start) != 2)
6665+ atomic_inc_unchecked(&count_count_start);
6666+ while (atomic_read_unchecked(&count_count_start) != 2)
6667 mb();
6668
6669 /*
6670@@ -141,8 +141,8 @@ void synchronise_count_slave(int cpu)
6671 if (i == NR_LOOPS-1)
6672 write_c0_count(initcount);
6673
6674- atomic_inc(&count_count_stop);
6675- while (atomic_read(&count_count_stop) != 2)
6676+ atomic_inc_unchecked(&count_count_stop);
6677+ while (atomic_read_unchecked(&count_count_stop) != 2)
6678 mb();
6679 }
6680 /* Arrange for an interrupt in a short while */
6681diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
6682index aec3408..74d79d3 100644
6683--- a/arch/mips/kernel/traps.c
6684+++ b/arch/mips/kernel/traps.c
6685@@ -683,7 +683,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
6686 siginfo_t info;
6687
6688 prev_state = exception_enter();
6689- die_if_kernel("Integer overflow", regs);
6690+ if (unlikely(!user_mode(regs))) {
6691+
6692+#ifdef CONFIG_PAX_REFCOUNT
6693+ if (fixup_exception(regs)) {
6694+ pax_report_refcount_overflow(regs);
6695+ exception_exit(prev_state);
6696+ return;
6697+ }
6698+#endif
6699+
6700+ die("Integer overflow", regs);
6701+ }
6702
6703 info.si_code = FPE_INTOVF;
6704 info.si_signo = SIGFPE;
6705diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
6706index 85df1cd..4f0a4de 100644
6707--- a/arch/mips/mm/fault.c
6708+++ b/arch/mips/mm/fault.c
6709@@ -28,6 +28,23 @@
6710 #include <asm/highmem.h> /* For VMALLOC_END */
6711 #include <linux/kdebug.h>
6712
6713+#ifdef CONFIG_PAX_PAGEEXEC
6714+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6715+{
6716+ unsigned long i;
6717+
6718+ printk(KERN_ERR "PAX: bytes at PC: ");
6719+ for (i = 0; i < 5; i++) {
6720+ unsigned int c;
6721+ if (get_user(c, (unsigned int *)pc+i))
6722+ printk(KERN_CONT "???????? ");
6723+ else
6724+ printk(KERN_CONT "%08x ", c);
6725+ }
6726+ printk("\n");
6727+}
6728+#endif
6729+
6730 /*
6731 * This routine handles page faults. It determines the address,
6732 * and the problem, and then passes it off to one of the appropriate
6733@@ -197,6 +214,14 @@ bad_area:
6734 bad_area_nosemaphore:
6735 /* User mode accesses just cause a SIGSEGV */
6736 if (user_mode(regs)) {
6737+
6738+#ifdef CONFIG_PAX_PAGEEXEC
6739+ if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
6740+ pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
6741+ do_group_exit(SIGKILL);
6742+ }
6743+#endif
6744+
6745 tsk->thread.cp0_badvaddr = address;
6746 tsk->thread.error_code = write;
6747 #if 0
6748diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
6749index f1baadd..8537544 100644
6750--- a/arch/mips/mm/mmap.c
6751+++ b/arch/mips/mm/mmap.c
6752@@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6753 struct vm_area_struct *vma;
6754 unsigned long addr = addr0;
6755 int do_color_align;
6756+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6757 struct vm_unmapped_area_info info;
6758
6759 if (unlikely(len > TASK_SIZE))
6760@@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6761 do_color_align = 1;
6762
6763 /* requesting a specific address */
6764+
6765+#ifdef CONFIG_PAX_RANDMMAP
6766+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
6767+#endif
6768+
6769 if (addr) {
6770 if (do_color_align)
6771 addr = COLOUR_ALIGN(addr, pgoff);
6772@@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6773 addr = PAGE_ALIGN(addr);
6774
6775 vma = find_vma(mm, addr);
6776- if (TASK_SIZE - len >= addr &&
6777- (!vma || addr + len <= vma->vm_start))
6778+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len, offset))
6779 return addr;
6780 }
6781
6782 info.length = len;
6783 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
6784 info.align_offset = pgoff << PAGE_SHIFT;
6785+ info.threadstack_offset = offset;
6786
6787 if (dir == DOWN) {
6788 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
6789@@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6790 {
6791 unsigned long random_factor = 0UL;
6792
6793+#ifdef CONFIG_PAX_RANDMMAP
6794+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
6795+#endif
6796+
6797 if (current->flags & PF_RANDOMIZE) {
6798 random_factor = get_random_int();
6799 random_factor = random_factor << PAGE_SHIFT;
6800@@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6801
6802 if (mmap_is_legacy()) {
6803 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
6804+
6805+#ifdef CONFIG_PAX_RANDMMAP
6806+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6807+ mm->mmap_base += mm->delta_mmap;
6808+#endif
6809+
6810 mm->get_unmapped_area = arch_get_unmapped_area;
6811 } else {
6812 mm->mmap_base = mmap_base(random_factor);
6813+
6814+#ifdef CONFIG_PAX_RANDMMAP
6815+ if (mm->pax_flags & MF_PAX_RANDMMAP)
6816+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6817+#endif
6818+
6819 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6820 }
6821 }
6822
6823-static inline unsigned long brk_rnd(void)
6824-{
6825- unsigned long rnd = get_random_int();
6826-
6827- rnd = rnd << PAGE_SHIFT;
6828- /* 8MB for 32bit, 256MB for 64bit */
6829- if (TASK_IS_32BIT_ADDR)
6830- rnd = rnd & 0x7ffffful;
6831- else
6832- rnd = rnd & 0xffffffful;
6833-
6834- return rnd;
6835-}
6836-
6837-unsigned long arch_randomize_brk(struct mm_struct *mm)
6838-{
6839- unsigned long base = mm->brk;
6840- unsigned long ret;
6841-
6842- ret = PAGE_ALIGN(base + brk_rnd());
6843-
6844- if (ret < mm->brk)
6845- return mm->brk;
6846-
6847- return ret;
6848-}
6849-
6850 int __virt_addr_valid(const volatile void *kaddr)
6851 {
6852 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
6853diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
6854index a2358b4..7cead4f 100644
6855--- a/arch/mips/sgi-ip27/ip27-nmi.c
6856+++ b/arch/mips/sgi-ip27/ip27-nmi.c
6857@@ -187,9 +187,9 @@ void
6858 cont_nmi_dump(void)
6859 {
6860 #ifndef REAL_NMI_SIGNAL
6861- static atomic_t nmied_cpus = ATOMIC_INIT(0);
6862+ static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
6863
6864- atomic_inc(&nmied_cpus);
6865+ atomic_inc_unchecked(&nmied_cpus);
6866 #endif
6867 /*
6868 * Only allow 1 cpu to proceed
6869@@ -233,7 +233,7 @@ cont_nmi_dump(void)
6870 udelay(10000);
6871 }
6872 #else
6873- while (atomic_read(&nmied_cpus) != num_online_cpus());
6874+ while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
6875 #endif
6876
6877 /*
6878diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
6879index 967d144..db12197 100644
6880--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
6881+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
6882@@ -11,12 +11,14 @@
6883 #ifndef _ASM_PROC_CACHE_H
6884 #define _ASM_PROC_CACHE_H
6885
6886+#include <linux/const.h>
6887+
6888 /* L1 cache */
6889
6890 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
6891 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
6892-#define L1_CACHE_BYTES 16 /* bytes per entry */
6893 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
6894+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
6895 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
6896
6897 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
6898diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
6899index bcb5df2..84fabd2 100644
6900--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
6901+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
6902@@ -16,13 +16,15 @@
6903 #ifndef _ASM_PROC_CACHE_H
6904 #define _ASM_PROC_CACHE_H
6905
6906+#include <linux/const.h>
6907+
6908 /*
6909 * L1 cache
6910 */
6911 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
6912 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
6913-#define L1_CACHE_BYTES 32 /* bytes per entry */
6914 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
6915+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
6916 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
6917
6918 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
6919diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
6920index 4ce7a01..449202a 100644
6921--- a/arch/openrisc/include/asm/cache.h
6922+++ b/arch/openrisc/include/asm/cache.h
6923@@ -19,11 +19,13 @@
6924 #ifndef __ASM_OPENRISC_CACHE_H
6925 #define __ASM_OPENRISC_CACHE_H
6926
6927+#include <linux/const.h>
6928+
6929 /* FIXME: How can we replace these with values from the CPU...
6930 * they shouldn't be hard-coded!
6931 */
6932
6933-#define L1_CACHE_BYTES 16
6934 #define L1_CACHE_SHIFT 4
6935+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6936
6937 #endif /* __ASM_OPENRISC_CACHE_H */
6938diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
6939index 472886c..00e7df9 100644
6940--- a/arch/parisc/include/asm/atomic.h
6941+++ b/arch/parisc/include/asm/atomic.h
6942@@ -252,6 +252,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
6943 return dec;
6944 }
6945
6946+#define atomic64_read_unchecked(v) atomic64_read(v)
6947+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
6948+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
6949+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
6950+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
6951+#define atomic64_inc_unchecked(v) atomic64_inc(v)
6952+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
6953+#define atomic64_dec_unchecked(v) atomic64_dec(v)
6954+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
6955+
6956 #endif /* !CONFIG_64BIT */
6957
6958
6959diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
6960index 47f11c7..3420df2 100644
6961--- a/arch/parisc/include/asm/cache.h
6962+++ b/arch/parisc/include/asm/cache.h
6963@@ -5,6 +5,7 @@
6964 #ifndef __ARCH_PARISC_CACHE_H
6965 #define __ARCH_PARISC_CACHE_H
6966
6967+#include <linux/const.h>
6968
6969 /*
6970 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
6971@@ -15,13 +16,13 @@
6972 * just ruin performance.
6973 */
6974 #ifdef CONFIG_PA20
6975-#define L1_CACHE_BYTES 64
6976 #define L1_CACHE_SHIFT 6
6977 #else
6978-#define L1_CACHE_BYTES 32
6979 #define L1_CACHE_SHIFT 5
6980 #endif
6981
6982+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6983+
6984 #ifndef __ASSEMBLY__
6985
6986 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6987diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
6988index ad2b503..bdf1651 100644
6989--- a/arch/parisc/include/asm/elf.h
6990+++ b/arch/parisc/include/asm/elf.h
6991@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
6992
6993 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
6994
6995+#ifdef CONFIG_PAX_ASLR
6996+#define PAX_ELF_ET_DYN_BASE 0x10000UL
6997+
6998+#define PAX_DELTA_MMAP_LEN 16
6999+#define PAX_DELTA_STACK_LEN 16
7000+#endif
7001+
7002 /* This yields a mask that user programs can use to figure out what
7003 instruction set this CPU supports. This could be done in user space,
7004 but it's not easy, and we've already done it here. */
7005diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
7006index fc987a1..6e068ef 100644
7007--- a/arch/parisc/include/asm/pgalloc.h
7008+++ b/arch/parisc/include/asm/pgalloc.h
7009@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7010 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
7011 }
7012
7013+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7014+{
7015+ pgd_populate(mm, pgd, pmd);
7016+}
7017+
7018 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
7019 {
7020 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
7021@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
7022 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
7023 #define pmd_free(mm, x) do { } while (0)
7024 #define pgd_populate(mm, pmd, pte) BUG()
7025+#define pgd_populate_kernel(mm, pmd, pte) BUG()
7026
7027 #endif
7028
7029diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
7030index 34899b5..02dd060 100644
7031--- a/arch/parisc/include/asm/pgtable.h
7032+++ b/arch/parisc/include/asm/pgtable.h
7033@@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
7034 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
7035 #define PAGE_COPY PAGE_EXECREAD
7036 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
7037+
7038+#ifdef CONFIG_PAX_PAGEEXEC
7039+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
7040+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7041+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7042+#else
7043+# define PAGE_SHARED_NOEXEC PAGE_SHARED
7044+# define PAGE_COPY_NOEXEC PAGE_COPY
7045+# define PAGE_READONLY_NOEXEC PAGE_READONLY
7046+#endif
7047+
7048 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
7049 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
7050 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
7051diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
7052index e0a8235..ce2f1e1 100644
7053--- a/arch/parisc/include/asm/uaccess.h
7054+++ b/arch/parisc/include/asm/uaccess.h
7055@@ -245,10 +245,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7056 const void __user *from,
7057 unsigned long n)
7058 {
7059- int sz = __compiletime_object_size(to);
7060+ size_t sz = __compiletime_object_size(to);
7061 int ret = -EFAULT;
7062
7063- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7064+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7065 ret = __copy_from_user(to, from, n);
7066 else
7067 copy_from_user_overflow();
7068diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7069index 2a625fb..9908930 100644
7070--- a/arch/parisc/kernel/module.c
7071+++ b/arch/parisc/kernel/module.c
7072@@ -98,16 +98,38 @@
7073
7074 /* three functions to determine where in the module core
7075 * or init pieces the location is */
7076+static inline int in_init_rx(struct module *me, void *loc)
7077+{
7078+ return (loc >= me->module_init_rx &&
7079+ loc < (me->module_init_rx + me->init_size_rx));
7080+}
7081+
7082+static inline int in_init_rw(struct module *me, void *loc)
7083+{
7084+ return (loc >= me->module_init_rw &&
7085+ loc < (me->module_init_rw + me->init_size_rw));
7086+}
7087+
7088 static inline int in_init(struct module *me, void *loc)
7089 {
7090- return (loc >= me->module_init &&
7091- loc <= (me->module_init + me->init_size));
7092+ return in_init_rx(me, loc) || in_init_rw(me, loc);
7093+}
7094+
7095+static inline int in_core_rx(struct module *me, void *loc)
7096+{
7097+ return (loc >= me->module_core_rx &&
7098+ loc < (me->module_core_rx + me->core_size_rx));
7099+}
7100+
7101+static inline int in_core_rw(struct module *me, void *loc)
7102+{
7103+ return (loc >= me->module_core_rw &&
7104+ loc < (me->module_core_rw + me->core_size_rw));
7105 }
7106
7107 static inline int in_core(struct module *me, void *loc)
7108 {
7109- return (loc >= me->module_core &&
7110- loc <= (me->module_core + me->core_size));
7111+ return in_core_rx(me, loc) || in_core_rw(me, loc);
7112 }
7113
7114 static inline int in_local(struct module *me, void *loc)
7115@@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7116 }
7117
7118 /* align things a bit */
7119- me->core_size = ALIGN(me->core_size, 16);
7120- me->arch.got_offset = me->core_size;
7121- me->core_size += gots * sizeof(struct got_entry);
7122+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7123+ me->arch.got_offset = me->core_size_rw;
7124+ me->core_size_rw += gots * sizeof(struct got_entry);
7125
7126- me->core_size = ALIGN(me->core_size, 16);
7127- me->arch.fdesc_offset = me->core_size;
7128- me->core_size += fdescs * sizeof(Elf_Fdesc);
7129+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7130+ me->arch.fdesc_offset = me->core_size_rw;
7131+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7132
7133 me->arch.got_max = gots;
7134 me->arch.fdesc_max = fdescs;
7135@@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7136
7137 BUG_ON(value == 0);
7138
7139- got = me->module_core + me->arch.got_offset;
7140+ got = me->module_core_rw + me->arch.got_offset;
7141 for (i = 0; got[i].addr; i++)
7142 if (got[i].addr == value)
7143 goto out;
7144@@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7145 #ifdef CONFIG_64BIT
7146 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7147 {
7148- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7149+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7150
7151 if (!value) {
7152 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7153@@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7154
7155 /* Create new one */
7156 fdesc->addr = value;
7157- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7158+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7159 return (Elf_Addr)fdesc;
7160 }
7161 #endif /* CONFIG_64BIT */
7162@@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7163
7164 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7165 end = table + sechdrs[me->arch.unwind_section].sh_size;
7166- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7167+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7168
7169 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7170 me->arch.unwind_section, table, end, gp);
7171diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7172index 5dfd248..64914ac 100644
7173--- a/arch/parisc/kernel/sys_parisc.c
7174+++ b/arch/parisc/kernel/sys_parisc.c
7175@@ -33,9 +33,11 @@
7176 #include <linux/utsname.h>
7177 #include <linux/personality.h>
7178
7179-static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
7180+static unsigned long get_unshared_area(struct file *filp, unsigned long addr, unsigned long len,
7181+ unsigned long flags)
7182 {
7183 struct vm_unmapped_area_info info;
7184+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7185
7186 info.flags = 0;
7187 info.length = len;
7188@@ -43,6 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
7189 info.high_limit = TASK_SIZE;
7190 info.align_mask = 0;
7191 info.align_offset = 0;
7192+ info.threadstack_offset = offset;
7193 return vm_unmapped_area(&info);
7194 }
7195
7196@@ -61,10 +64,11 @@ static int get_offset(struct address_space *mapping)
7197 return (unsigned long) mapping >> 8;
7198 }
7199
7200-static unsigned long get_shared_area(struct address_space *mapping,
7201- unsigned long addr, unsigned long len, unsigned long pgoff)
7202+static unsigned long get_shared_area(struct file *filp, struct address_space *mapping,
7203+ unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
7204 {
7205 struct vm_unmapped_area_info info;
7206+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7207
7208 info.flags = 0;
7209 info.length = len;
7210@@ -72,6 +76,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
7211 info.high_limit = TASK_SIZE;
7212 info.align_mask = PAGE_MASK & (SHMLBA - 1);
7213 info.align_offset = (get_offset(mapping) + pgoff) << PAGE_SHIFT;
7214+ info.threadstack_offset = offset;
7215 return vm_unmapped_area(&info);
7216 }
7217
7218@@ -86,15 +91,22 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7219 return -EINVAL;
7220 return addr;
7221 }
7222- if (!addr)
7223+ if (!addr) {
7224 addr = TASK_UNMAPPED_BASE;
7225
7226+#ifdef CONFIG_PAX_RANDMMAP
7227+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
7228+ addr += current->mm->delta_mmap;
7229+#endif
7230+
7231+ }
7232+
7233 if (filp) {
7234- addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
7235+ addr = get_shared_area(filp, filp->f_mapping, addr, len, pgoff, flags);
7236 } else if(flags & MAP_SHARED) {
7237- addr = get_shared_area(NULL, addr, len, pgoff);
7238+ addr = get_shared_area(filp, NULL, addr, len, pgoff, flags);
7239 } else {
7240- addr = get_unshared_area(addr, len);
7241+ addr = get_unshared_area(filp, addr, len, flags);
7242 }
7243 return addr;
7244 }
7245diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7246index 04e47c6..7a8faf6 100644
7247--- a/arch/parisc/kernel/traps.c
7248+++ b/arch/parisc/kernel/traps.c
7249@@ -727,9 +727,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7250
7251 down_read(&current->mm->mmap_sem);
7252 vma = find_vma(current->mm,regs->iaoq[0]);
7253- if (vma && (regs->iaoq[0] >= vma->vm_start)
7254- && (vma->vm_flags & VM_EXEC)) {
7255-
7256+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7257 fault_address = regs->iaoq[0];
7258 fault_space = regs->iasq[0];
7259
7260diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7261index f247a34..dc0f219 100644
7262--- a/arch/parisc/mm/fault.c
7263+++ b/arch/parisc/mm/fault.c
7264@@ -15,6 +15,7 @@
7265 #include <linux/sched.h>
7266 #include <linux/interrupt.h>
7267 #include <linux/module.h>
7268+#include <linux/unistd.h>
7269
7270 #include <asm/uaccess.h>
7271 #include <asm/traps.h>
7272@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
7273 static unsigned long
7274 parisc_acctyp(unsigned long code, unsigned int inst)
7275 {
7276- if (code == 6 || code == 16)
7277+ if (code == 6 || code == 7 || code == 16)
7278 return VM_EXEC;
7279
7280 switch (inst & 0xf0000000) {
7281@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
7282 }
7283 #endif
7284
7285+#ifdef CONFIG_PAX_PAGEEXEC
7286+/*
7287+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
7288+ *
7289+ * returns 1 when task should be killed
7290+ * 2 when rt_sigreturn trampoline was detected
7291+ * 3 when unpatched PLT trampoline was detected
7292+ */
7293+static int pax_handle_fetch_fault(struct pt_regs *regs)
7294+{
7295+
7296+#ifdef CONFIG_PAX_EMUPLT
7297+ int err;
7298+
7299+ do { /* PaX: unpatched PLT emulation */
7300+ unsigned int bl, depwi;
7301+
7302+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
7303+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
7304+
7305+ if (err)
7306+ break;
7307+
7308+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
7309+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
7310+
7311+ err = get_user(ldw, (unsigned int *)addr);
7312+ err |= get_user(bv, (unsigned int *)(addr+4));
7313+ err |= get_user(ldw2, (unsigned int *)(addr+8));
7314+
7315+ if (err)
7316+ break;
7317+
7318+ if (ldw == 0x0E801096U &&
7319+ bv == 0xEAC0C000U &&
7320+ ldw2 == 0x0E881095U)
7321+ {
7322+ unsigned int resolver, map;
7323+
7324+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
7325+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
7326+ if (err)
7327+ break;
7328+
7329+ regs->gr[20] = instruction_pointer(regs)+8;
7330+ regs->gr[21] = map;
7331+ regs->gr[22] = resolver;
7332+ regs->iaoq[0] = resolver | 3UL;
7333+ regs->iaoq[1] = regs->iaoq[0] + 4;
7334+ return 3;
7335+ }
7336+ }
7337+ } while (0);
7338+#endif
7339+
7340+#ifdef CONFIG_PAX_EMUTRAMP
7341+
7342+#ifndef CONFIG_PAX_EMUSIGRT
7343+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
7344+ return 1;
7345+#endif
7346+
7347+ do { /* PaX: rt_sigreturn emulation */
7348+ unsigned int ldi1, ldi2, bel, nop;
7349+
7350+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
7351+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
7352+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
7353+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
7354+
7355+ if (err)
7356+ break;
7357+
7358+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
7359+ ldi2 == 0x3414015AU &&
7360+ bel == 0xE4008200U &&
7361+ nop == 0x08000240U)
7362+ {
7363+ regs->gr[25] = (ldi1 & 2) >> 1;
7364+ regs->gr[20] = __NR_rt_sigreturn;
7365+ regs->gr[31] = regs->iaoq[1] + 16;
7366+ regs->sr[0] = regs->iasq[1];
7367+ regs->iaoq[0] = 0x100UL;
7368+ regs->iaoq[1] = regs->iaoq[0] + 4;
7369+ regs->iasq[0] = regs->sr[2];
7370+ regs->iasq[1] = regs->sr[2];
7371+ return 2;
7372+ }
7373+ } while (0);
7374+#endif
7375+
7376+ return 1;
7377+}
7378+
7379+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7380+{
7381+ unsigned long i;
7382+
7383+ printk(KERN_ERR "PAX: bytes at PC: ");
7384+ for (i = 0; i < 5; i++) {
7385+ unsigned int c;
7386+ if (get_user(c, (unsigned int *)pc+i))
7387+ printk(KERN_CONT "???????? ");
7388+ else
7389+ printk(KERN_CONT "%08x ", c);
7390+ }
7391+ printk("\n");
7392+}
7393+#endif
7394+
7395 int fixup_exception(struct pt_regs *regs)
7396 {
7397 const struct exception_table_entry *fix;
7398@@ -194,8 +305,33 @@ good_area:
7399
7400 acc_type = parisc_acctyp(code,regs->iir);
7401
7402- if ((vma->vm_flags & acc_type) != acc_type)
7403+ if ((vma->vm_flags & acc_type) != acc_type) {
7404+
7405+#ifdef CONFIG_PAX_PAGEEXEC
7406+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
7407+ (address & ~3UL) == instruction_pointer(regs))
7408+ {
7409+ up_read(&mm->mmap_sem);
7410+ switch (pax_handle_fetch_fault(regs)) {
7411+
7412+#ifdef CONFIG_PAX_EMUPLT
7413+ case 3:
7414+ return;
7415+#endif
7416+
7417+#ifdef CONFIG_PAX_EMUTRAMP
7418+ case 2:
7419+ return;
7420+#endif
7421+
7422+ }
7423+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
7424+ do_group_exit(SIGKILL);
7425+ }
7426+#endif
7427+
7428 goto bad_area;
7429+ }
7430
7431 /*
7432 * If for any reason at all we couldn't handle the fault, make
7433diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
7434index e3b1d41..8e81edf 100644
7435--- a/arch/powerpc/include/asm/atomic.h
7436+++ b/arch/powerpc/include/asm/atomic.h
7437@@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
7438 return t1;
7439 }
7440
7441+#define atomic64_read_unchecked(v) atomic64_read(v)
7442+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7443+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7444+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7445+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7446+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7447+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7448+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7449+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7450+
7451 #endif /* __powerpc64__ */
7452
7453 #endif /* __KERNEL__ */
7454diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
7455index 9e495c9..b6878e5 100644
7456--- a/arch/powerpc/include/asm/cache.h
7457+++ b/arch/powerpc/include/asm/cache.h
7458@@ -3,6 +3,7 @@
7459
7460 #ifdef __KERNEL__
7461
7462+#include <linux/const.h>
7463
7464 /* bytes per L1 cache line */
7465 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
7466@@ -22,7 +23,7 @@
7467 #define L1_CACHE_SHIFT 7
7468 #endif
7469
7470-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7471+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7472
7473 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7474
7475diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
7476index cc0655a..13eac2e 100644
7477--- a/arch/powerpc/include/asm/elf.h
7478+++ b/arch/powerpc/include/asm/elf.h
7479@@ -28,8 +28,19 @@
7480 the loader. We need to make sure that it is out of the way of the program
7481 that it will "exec", and that there is sufficient room for the brk. */
7482
7483-extern unsigned long randomize_et_dyn(unsigned long base);
7484-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
7485+#define ELF_ET_DYN_BASE (0x20000000)
7486+
7487+#ifdef CONFIG_PAX_ASLR
7488+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
7489+
7490+#ifdef __powerpc64__
7491+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
7492+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
7493+#else
7494+#define PAX_DELTA_MMAP_LEN 15
7495+#define PAX_DELTA_STACK_LEN 15
7496+#endif
7497+#endif
7498
7499 /*
7500 * Our registers are always unsigned longs, whether we're a 32 bit
7501@@ -123,10 +134,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
7502 (0x7ff >> (PAGE_SHIFT - 12)) : \
7503 (0x3ffff >> (PAGE_SHIFT - 12)))
7504
7505-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7506-#define arch_randomize_brk arch_randomize_brk
7507-
7508-
7509 #ifdef CONFIG_SPU_BASE
7510 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
7511 #define NT_SPU 1
7512diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
7513index 8196e9c..d83a9f3 100644
7514--- a/arch/powerpc/include/asm/exec.h
7515+++ b/arch/powerpc/include/asm/exec.h
7516@@ -4,6 +4,6 @@
7517 #ifndef _ASM_POWERPC_EXEC_H
7518 #define _ASM_POWERPC_EXEC_H
7519
7520-extern unsigned long arch_align_stack(unsigned long sp);
7521+#define arch_align_stack(x) ((x) & ~0xfUL)
7522
7523 #endif /* _ASM_POWERPC_EXEC_H */
7524diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
7525index 5acabbd..7ea14fa 100644
7526--- a/arch/powerpc/include/asm/kmap_types.h
7527+++ b/arch/powerpc/include/asm/kmap_types.h
7528@@ -10,7 +10,7 @@
7529 * 2 of the License, or (at your option) any later version.
7530 */
7531
7532-#define KM_TYPE_NR 16
7533+#define KM_TYPE_NR 17
7534
7535 #endif /* __KERNEL__ */
7536 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
7537diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
7538index 8565c25..2865190 100644
7539--- a/arch/powerpc/include/asm/mman.h
7540+++ b/arch/powerpc/include/asm/mman.h
7541@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
7542 }
7543 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
7544
7545-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
7546+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
7547 {
7548 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
7549 }
7550diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
7551index b9f4262..dcf04f7 100644
7552--- a/arch/powerpc/include/asm/page.h
7553+++ b/arch/powerpc/include/asm/page.h
7554@@ -230,8 +230,9 @@ extern long long virt_phys_offset;
7555 * and needs to be executable. This means the whole heap ends
7556 * up being executable.
7557 */
7558-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
7559- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7560+#define VM_DATA_DEFAULT_FLAGS32 \
7561+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
7562+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7563
7564 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
7565 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7566@@ -259,6 +260,9 @@ extern long long virt_phys_offset;
7567 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
7568 #endif
7569
7570+#define ktla_ktva(addr) (addr)
7571+#define ktva_ktla(addr) (addr)
7572+
7573 #ifndef CONFIG_PPC_BOOK3S_64
7574 /*
7575 * Use the top bit of the higher-level page table entries to indicate whether
7576diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
7577index 88693ce..ac6f9ab 100644
7578--- a/arch/powerpc/include/asm/page_64.h
7579+++ b/arch/powerpc/include/asm/page_64.h
7580@@ -153,15 +153,18 @@ do { \
7581 * stack by default, so in the absence of a PT_GNU_STACK program header
7582 * we turn execute permission off.
7583 */
7584-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
7585- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7586+#define VM_STACK_DEFAULT_FLAGS32 \
7587+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
7588+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7589
7590 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
7591 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7592
7593+#ifndef CONFIG_PAX_PAGEEXEC
7594 #define VM_STACK_DEFAULT_FLAGS \
7595 (is_32bit_task() ? \
7596 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
7597+#endif
7598
7599 #include <asm-generic/getorder.h>
7600
7601diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
7602index f65e27b..23ffb5b 100644
7603--- a/arch/powerpc/include/asm/pgalloc-64.h
7604+++ b/arch/powerpc/include/asm/pgalloc-64.h
7605@@ -53,6 +53,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
7606 #ifndef CONFIG_PPC_64K_PAGES
7607
7608 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
7609+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
7610
7611 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
7612 {
7613@@ -70,6 +71,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
7614 pud_set(pud, (unsigned long)pmd);
7615 }
7616
7617+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
7618+{
7619+ pud_populate(mm, pud, pmd);
7620+}
7621+
7622 #define pmd_populate(mm, pmd, pte_page) \
7623 pmd_populate_kernel(mm, pmd, page_address(pte_page))
7624 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
7625@@ -171,6 +177,7 @@ extern void __tlb_remove_table(void *_table);
7626 #endif
7627
7628 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
7629+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7630
7631 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
7632 pte_t *pte)
7633diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
7634index 7d6eacf..14c0240 100644
7635--- a/arch/powerpc/include/asm/pgtable.h
7636+++ b/arch/powerpc/include/asm/pgtable.h
7637@@ -2,6 +2,7 @@
7638 #define _ASM_POWERPC_PGTABLE_H
7639 #ifdef __KERNEL__
7640
7641+#include <linux/const.h>
7642 #ifndef __ASSEMBLY__
7643 #include <asm/processor.h> /* For TASK_SIZE */
7644 #include <asm/mmu.h>
7645diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
7646index 4aad413..85d86bf 100644
7647--- a/arch/powerpc/include/asm/pte-hash32.h
7648+++ b/arch/powerpc/include/asm/pte-hash32.h
7649@@ -21,6 +21,7 @@
7650 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
7651 #define _PAGE_USER 0x004 /* usermode access allowed */
7652 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
7653+#define _PAGE_EXEC _PAGE_GUARDED
7654 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
7655 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
7656 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
7657diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
7658index 99222e2..f629aef 100644
7659--- a/arch/powerpc/include/asm/reg.h
7660+++ b/arch/powerpc/include/asm/reg.h
7661@@ -234,6 +234,7 @@
7662 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
7663 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
7664 #define DSISR_NOHPTE 0x40000000 /* no translation found */
7665+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
7666 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
7667 #define DSISR_ISSTORE 0x02000000 /* access was a store */
7668 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
7669diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
7670index 48cfc85..891382f 100644
7671--- a/arch/powerpc/include/asm/smp.h
7672+++ b/arch/powerpc/include/asm/smp.h
7673@@ -50,7 +50,7 @@ struct smp_ops_t {
7674 int (*cpu_disable)(void);
7675 void (*cpu_die)(unsigned int nr);
7676 int (*cpu_bootable)(unsigned int nr);
7677-};
7678+} __no_const;
7679
7680 extern void smp_send_debugger_break(void);
7681 extern void start_secondary_resume(void);
7682diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
7683index ba7b197..d292e26 100644
7684--- a/arch/powerpc/include/asm/thread_info.h
7685+++ b/arch/powerpc/include/asm/thread_info.h
7686@@ -93,7 +93,6 @@ static inline struct thread_info *current_thread_info(void)
7687 #define TIF_POLLING_NRFLAG 3 /* true if poll_idle() is polling
7688 TIF_NEED_RESCHED */
7689 #define TIF_32BIT 4 /* 32 bit binary */
7690-#define TIF_PERFMON_WORK 5 /* work for pfm_handle_work() */
7691 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
7692 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
7693 #define TIF_SINGLESTEP 8 /* singlestepping active */
7694@@ -107,6 +106,9 @@ static inline struct thread_info *current_thread_info(void)
7695 #define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation
7696 for stack store? */
7697 #define TIF_MEMDIE 17 /* is terminating due to OOM killer */
7698+#define TIF_PERFMON_WORK 18 /* work for pfm_handle_work() */
7699+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
7700+#define TIF_GRSEC_SETXID 5 /* update credentials on syscall entry/exit */
7701
7702 /* as above, but as bit values */
7703 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
7704@@ -126,9 +128,10 @@ static inline struct thread_info *current_thread_info(void)
7705 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
7706 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
7707 #define _TIF_NOHZ (1<<TIF_NOHZ)
7708+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
7709 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
7710 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
7711- _TIF_NOHZ)
7712+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
7713
7714 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
7715 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
7716diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
7717index 9485b43..4718d50 100644
7718--- a/arch/powerpc/include/asm/uaccess.h
7719+++ b/arch/powerpc/include/asm/uaccess.h
7720@@ -318,52 +318,6 @@ do { \
7721 extern unsigned long __copy_tofrom_user(void __user *to,
7722 const void __user *from, unsigned long size);
7723
7724-#ifndef __powerpc64__
7725-
7726-static inline unsigned long copy_from_user(void *to,
7727- const void __user *from, unsigned long n)
7728-{
7729- unsigned long over;
7730-
7731- if (access_ok(VERIFY_READ, from, n))
7732- return __copy_tofrom_user((__force void __user *)to, from, n);
7733- if ((unsigned long)from < TASK_SIZE) {
7734- over = (unsigned long)from + n - TASK_SIZE;
7735- return __copy_tofrom_user((__force void __user *)to, from,
7736- n - over) + over;
7737- }
7738- return n;
7739-}
7740-
7741-static inline unsigned long copy_to_user(void __user *to,
7742- const void *from, unsigned long n)
7743-{
7744- unsigned long over;
7745-
7746- if (access_ok(VERIFY_WRITE, to, n))
7747- return __copy_tofrom_user(to, (__force void __user *)from, n);
7748- if ((unsigned long)to < TASK_SIZE) {
7749- over = (unsigned long)to + n - TASK_SIZE;
7750- return __copy_tofrom_user(to, (__force void __user *)from,
7751- n - over) + over;
7752- }
7753- return n;
7754-}
7755-
7756-#else /* __powerpc64__ */
7757-
7758-#define __copy_in_user(to, from, size) \
7759- __copy_tofrom_user((to), (from), (size))
7760-
7761-extern unsigned long copy_from_user(void *to, const void __user *from,
7762- unsigned long n);
7763-extern unsigned long copy_to_user(void __user *to, const void *from,
7764- unsigned long n);
7765-extern unsigned long copy_in_user(void __user *to, const void __user *from,
7766- unsigned long n);
7767-
7768-#endif /* __powerpc64__ */
7769-
7770 static inline unsigned long __copy_from_user_inatomic(void *to,
7771 const void __user *from, unsigned long n)
7772 {
7773@@ -387,6 +341,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
7774 if (ret == 0)
7775 return 0;
7776 }
7777+
7778+ if (!__builtin_constant_p(n))
7779+ check_object_size(to, n, false);
7780+
7781 return __copy_tofrom_user((__force void __user *)to, from, n);
7782 }
7783
7784@@ -413,6 +371,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
7785 if (ret == 0)
7786 return 0;
7787 }
7788+
7789+ if (!__builtin_constant_p(n))
7790+ check_object_size(from, n, true);
7791+
7792 return __copy_tofrom_user(to, (__force const void __user *)from, n);
7793 }
7794
7795@@ -430,6 +392,92 @@ static inline unsigned long __copy_to_user(void __user *to,
7796 return __copy_to_user_inatomic(to, from, size);
7797 }
7798
7799+#ifndef __powerpc64__
7800+
7801+static inline unsigned long __must_check copy_from_user(void *to,
7802+ const void __user *from, unsigned long n)
7803+{
7804+ unsigned long over;
7805+
7806+ if ((long)n < 0)
7807+ return n;
7808+
7809+ if (access_ok(VERIFY_READ, from, n)) {
7810+ if (!__builtin_constant_p(n))
7811+ check_object_size(to, n, false);
7812+ return __copy_tofrom_user((__force void __user *)to, from, n);
7813+ }
7814+ if ((unsigned long)from < TASK_SIZE) {
7815+ over = (unsigned long)from + n - TASK_SIZE;
7816+ if (!__builtin_constant_p(n - over))
7817+ check_object_size(to, n - over, false);
7818+ return __copy_tofrom_user((__force void __user *)to, from,
7819+ n - over) + over;
7820+ }
7821+ return n;
7822+}
7823+
7824+static inline unsigned long __must_check copy_to_user(void __user *to,
7825+ const void *from, unsigned long n)
7826+{
7827+ unsigned long over;
7828+
7829+ if ((long)n < 0)
7830+ return n;
7831+
7832+ if (access_ok(VERIFY_WRITE, to, n)) {
7833+ if (!__builtin_constant_p(n))
7834+ check_object_size(from, n, true);
7835+ return __copy_tofrom_user(to, (__force void __user *)from, n);
7836+ }
7837+ if ((unsigned long)to < TASK_SIZE) {
7838+ over = (unsigned long)to + n - TASK_SIZE;
7839+ if (!__builtin_constant_p(n))
7840+ check_object_size(from, n - over, true);
7841+ return __copy_tofrom_user(to, (__force void __user *)from,
7842+ n - over) + over;
7843+ }
7844+ return n;
7845+}
7846+
7847+#else /* __powerpc64__ */
7848+
7849+#define __copy_in_user(to, from, size) \
7850+ __copy_tofrom_user((to), (from), (size))
7851+
7852+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
7853+{
7854+ if ((long)n < 0 || n > INT_MAX)
7855+ return n;
7856+
7857+ if (!__builtin_constant_p(n))
7858+ check_object_size(to, n, false);
7859+
7860+ if (likely(access_ok(VERIFY_READ, from, n)))
7861+ n = __copy_from_user(to, from, n);
7862+ else
7863+ memset(to, 0, n);
7864+ return n;
7865+}
7866+
7867+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
7868+{
7869+ if ((long)n < 0 || n > INT_MAX)
7870+ return n;
7871+
7872+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
7873+ if (!__builtin_constant_p(n))
7874+ check_object_size(from, n, true);
7875+ n = __copy_to_user(to, from, n);
7876+ }
7877+ return n;
7878+}
7879+
7880+extern unsigned long copy_in_user(void __user *to, const void __user *from,
7881+ unsigned long n);
7882+
7883+#endif /* __powerpc64__ */
7884+
7885 extern unsigned long __clear_user(void __user *addr, unsigned long size);
7886
7887 static inline unsigned long clear_user(void __user *addr, unsigned long size)
7888diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
7889index 645170a..6cf0271 100644
7890--- a/arch/powerpc/kernel/exceptions-64e.S
7891+++ b/arch/powerpc/kernel/exceptions-64e.S
7892@@ -757,6 +757,7 @@ storage_fault_common:
7893 std r14,_DAR(r1)
7894 std r15,_DSISR(r1)
7895 addi r3,r1,STACK_FRAME_OVERHEAD
7896+ bl .save_nvgprs
7897 mr r4,r14
7898 mr r5,r15
7899 ld r14,PACA_EXGEN+EX_R14(r13)
7900@@ -765,8 +766,7 @@ storage_fault_common:
7901 cmpdi r3,0
7902 bne- 1f
7903 b .ret_from_except_lite
7904-1: bl .save_nvgprs
7905- mr r5,r3
7906+1: mr r5,r3
7907 addi r3,r1,STACK_FRAME_OVERHEAD
7908 ld r4,_DAR(r1)
7909 bl .bad_page_fault
7910diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
7911index 902ca3c..e942155 100644
7912--- a/arch/powerpc/kernel/exceptions-64s.S
7913+++ b/arch/powerpc/kernel/exceptions-64s.S
7914@@ -1357,10 +1357,10 @@ handle_page_fault:
7915 11: ld r4,_DAR(r1)
7916 ld r5,_DSISR(r1)
7917 addi r3,r1,STACK_FRAME_OVERHEAD
7918+ bl .save_nvgprs
7919 bl .do_page_fault
7920 cmpdi r3,0
7921 beq+ 12f
7922- bl .save_nvgprs
7923 mr r5,r3
7924 addi r3,r1,STACK_FRAME_OVERHEAD
7925 lwz r4,_DAR(r1)
7926diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
7927index 2e3200c..72095ce 100644
7928--- a/arch/powerpc/kernel/module_32.c
7929+++ b/arch/powerpc/kernel/module_32.c
7930@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
7931 me->arch.core_plt_section = i;
7932 }
7933 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
7934- printk("Module doesn't contain .plt or .init.plt sections.\n");
7935+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
7936 return -ENOEXEC;
7937 }
7938
7939@@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
7940
7941 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
7942 /* Init, or core PLT? */
7943- if (location >= mod->module_core
7944- && location < mod->module_core + mod->core_size)
7945+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
7946+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
7947 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
7948- else
7949+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
7950+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
7951 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
7952+ else {
7953+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
7954+ return ~0UL;
7955+ }
7956
7957 /* Find this entry, or if that fails, the next avail. entry */
7958 while (entry->jump[0]) {
7959diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
7960index 8083be2..10aa352 100644
7961--- a/arch/powerpc/kernel/process.c
7962+++ b/arch/powerpc/kernel/process.c
7963@@ -884,8 +884,8 @@ void show_regs(struct pt_regs * regs)
7964 * Lookup NIP late so we have the best change of getting the
7965 * above info out without failing
7966 */
7967- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
7968- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
7969+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
7970+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
7971 #endif
7972 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
7973 printk("PACATMSCRATCH [%llx]\n", get_paca()->tm_scratch);
7974@@ -1349,10 +1349,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
7975 newsp = stack[0];
7976 ip = stack[STACK_FRAME_LR_SAVE];
7977 if (!firstframe || ip != lr) {
7978- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
7979+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
7980 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
7981 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
7982- printk(" (%pS)",
7983+ printk(" (%pA)",
7984 (void *)current->ret_stack[curr_frame].ret);
7985 curr_frame--;
7986 }
7987@@ -1372,7 +1372,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
7988 struct pt_regs *regs = (struct pt_regs *)
7989 (sp + STACK_FRAME_OVERHEAD);
7990 lr = regs->link;
7991- printk("--- Exception: %lx at %pS\n LR = %pS\n",
7992+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
7993 regs->trap, (void *)regs->nip, (void *)lr);
7994 firstframe = 1;
7995 }
7996@@ -1408,58 +1408,3 @@ void notrace __ppc64_runlatch_off(void)
7997 mtspr(SPRN_CTRLT, ctrl);
7998 }
7999 #endif /* CONFIG_PPC64 */
8000-
8001-unsigned long arch_align_stack(unsigned long sp)
8002-{
8003- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8004- sp -= get_random_int() & ~PAGE_MASK;
8005- return sp & ~0xf;
8006-}
8007-
8008-static inline unsigned long brk_rnd(void)
8009-{
8010- unsigned long rnd = 0;
8011-
8012- /* 8MB for 32bit, 1GB for 64bit */
8013- if (is_32bit_task())
8014- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
8015- else
8016- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
8017-
8018- return rnd << PAGE_SHIFT;
8019-}
8020-
8021-unsigned long arch_randomize_brk(struct mm_struct *mm)
8022-{
8023- unsigned long base = mm->brk;
8024- unsigned long ret;
8025-
8026-#ifdef CONFIG_PPC_STD_MMU_64
8027- /*
8028- * If we are using 1TB segments and we are allowed to randomise
8029- * the heap, we can put it above 1TB so it is backed by a 1TB
8030- * segment. Otherwise the heap will be in the bottom 1TB
8031- * which always uses 256MB segments and this may result in a
8032- * performance penalty.
8033- */
8034- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
8035- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
8036-#endif
8037-
8038- ret = PAGE_ALIGN(base + brk_rnd());
8039-
8040- if (ret < mm->brk)
8041- return mm->brk;
8042-
8043- return ret;
8044-}
8045-
8046-unsigned long randomize_et_dyn(unsigned long base)
8047-{
8048- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8049-
8050- if (ret < base)
8051- return base;
8052-
8053- return ret;
8054-}
8055diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
8056index 9a0d24c..e7fbedf 100644
8057--- a/arch/powerpc/kernel/ptrace.c
8058+++ b/arch/powerpc/kernel/ptrace.c
8059@@ -1761,6 +1761,10 @@ long arch_ptrace(struct task_struct *child, long request,
8060 return ret;
8061 }
8062
8063+#ifdef CONFIG_GRKERNSEC_SETXID
8064+extern void gr_delayed_cred_worker(void);
8065+#endif
8066+
8067 /*
8068 * We must return the syscall number to actually look up in the table.
8069 * This can be -1L to skip running any syscall at all.
8070@@ -1773,6 +1777,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
8071
8072 secure_computing_strict(regs->gpr[0]);
8073
8074+#ifdef CONFIG_GRKERNSEC_SETXID
8075+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8076+ gr_delayed_cred_worker();
8077+#endif
8078+
8079 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
8080 tracehook_report_syscall_entry(regs))
8081 /*
8082@@ -1807,6 +1816,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
8083 {
8084 int step;
8085
8086+#ifdef CONFIG_GRKERNSEC_SETXID
8087+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8088+ gr_delayed_cred_worker();
8089+#endif
8090+
8091 audit_syscall_exit(regs);
8092
8093 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8094diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
8095index 0f83122..c0aca6a 100644
8096--- a/arch/powerpc/kernel/signal_32.c
8097+++ b/arch/powerpc/kernel/signal_32.c
8098@@ -987,7 +987,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
8099 /* Save user registers on the stack */
8100 frame = &rt_sf->uc.uc_mcontext;
8101 addr = frame;
8102- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
8103+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8104 sigret = 0;
8105 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
8106 } else {
8107diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
8108index 887e99d..310bc11 100644
8109--- a/arch/powerpc/kernel/signal_64.c
8110+++ b/arch/powerpc/kernel/signal_64.c
8111@@ -751,7 +751,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
8112 #endif
8113
8114 /* Set up to return from userspace. */
8115- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
8116+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8117 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
8118 } else {
8119 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
8120diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
8121index e435bc0..41c2964 100644
8122--- a/arch/powerpc/kernel/traps.c
8123+++ b/arch/powerpc/kernel/traps.c
8124@@ -141,6 +141,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
8125 return flags;
8126 }
8127
8128+extern void gr_handle_kernel_exploit(void);
8129+
8130 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8131 int signr)
8132 {
8133@@ -190,6 +192,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8134 panic("Fatal exception in interrupt");
8135 if (panic_on_oops)
8136 panic("Fatal exception");
8137+
8138+ gr_handle_kernel_exploit();
8139+
8140 do_exit(signr);
8141 }
8142
8143diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
8144index 1d9c926..25f4741 100644
8145--- a/arch/powerpc/kernel/vdso.c
8146+++ b/arch/powerpc/kernel/vdso.c
8147@@ -34,6 +34,7 @@
8148 #include <asm/firmware.h>
8149 #include <asm/vdso.h>
8150 #include <asm/vdso_datapage.h>
8151+#include <asm/mman.h>
8152
8153 #include "setup.h"
8154
8155@@ -222,7 +223,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8156 vdso_base = VDSO32_MBASE;
8157 #endif
8158
8159- current->mm->context.vdso_base = 0;
8160+ current->mm->context.vdso_base = ~0UL;
8161
8162 /* vDSO has a problem and was disabled, just don't "enable" it for the
8163 * process
8164@@ -242,7 +243,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8165 vdso_base = get_unmapped_area(NULL, vdso_base,
8166 (vdso_pages << PAGE_SHIFT) +
8167 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
8168- 0, 0);
8169+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
8170 if (IS_ERR_VALUE(vdso_base)) {
8171 rc = vdso_base;
8172 goto fail_mmapsem;
8173diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
8174index 5eea6f3..5d10396 100644
8175--- a/arch/powerpc/lib/usercopy_64.c
8176+++ b/arch/powerpc/lib/usercopy_64.c
8177@@ -9,22 +9,6 @@
8178 #include <linux/module.h>
8179 #include <asm/uaccess.h>
8180
8181-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8182-{
8183- if (likely(access_ok(VERIFY_READ, from, n)))
8184- n = __copy_from_user(to, from, n);
8185- else
8186- memset(to, 0, n);
8187- return n;
8188-}
8189-
8190-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8191-{
8192- if (likely(access_ok(VERIFY_WRITE, to, n)))
8193- n = __copy_to_user(to, from, n);
8194- return n;
8195-}
8196-
8197 unsigned long copy_in_user(void __user *to, const void __user *from,
8198 unsigned long n)
8199 {
8200@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
8201 return n;
8202 }
8203
8204-EXPORT_SYMBOL(copy_from_user);
8205-EXPORT_SYMBOL(copy_to_user);
8206 EXPORT_SYMBOL(copy_in_user);
8207
8208diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
8209index 8726779..a33c512 100644
8210--- a/arch/powerpc/mm/fault.c
8211+++ b/arch/powerpc/mm/fault.c
8212@@ -33,6 +33,10 @@
8213 #include <linux/magic.h>
8214 #include <linux/ratelimit.h>
8215 #include <linux/context_tracking.h>
8216+#include <linux/slab.h>
8217+#include <linux/pagemap.h>
8218+#include <linux/compiler.h>
8219+#include <linux/unistd.h>
8220
8221 #include <asm/firmware.h>
8222 #include <asm/page.h>
8223@@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
8224 }
8225 #endif
8226
8227+#ifdef CONFIG_PAX_PAGEEXEC
8228+/*
8229+ * PaX: decide what to do with offenders (regs->nip = fault address)
8230+ *
8231+ * returns 1 when task should be killed
8232+ */
8233+static int pax_handle_fetch_fault(struct pt_regs *regs)
8234+{
8235+ return 1;
8236+}
8237+
8238+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8239+{
8240+ unsigned long i;
8241+
8242+ printk(KERN_ERR "PAX: bytes at PC: ");
8243+ for (i = 0; i < 5; i++) {
8244+ unsigned int c;
8245+ if (get_user(c, (unsigned int __user *)pc+i))
8246+ printk(KERN_CONT "???????? ");
8247+ else
8248+ printk(KERN_CONT "%08x ", c);
8249+ }
8250+ printk("\n");
8251+}
8252+#endif
8253+
8254 /*
8255 * Check whether the instruction at regs->nip is a store using
8256 * an update addressing form which will update r1.
8257@@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
8258 * indicate errors in DSISR but can validly be set in SRR1.
8259 */
8260 if (trap == 0x400)
8261- error_code &= 0x48200000;
8262+ error_code &= 0x58200000;
8263 else
8264 is_write = error_code & DSISR_ISSTORE;
8265 #else
8266@@ -371,7 +402,7 @@ good_area:
8267 * "undefined". Of those that can be set, this is the only
8268 * one which seems bad.
8269 */
8270- if (error_code & 0x10000000)
8271+ if (error_code & DSISR_GUARDED)
8272 /* Guarded storage error. */
8273 goto bad_area;
8274 #endif /* CONFIG_8xx */
8275@@ -386,7 +417,7 @@ good_area:
8276 * processors use the same I/D cache coherency mechanism
8277 * as embedded.
8278 */
8279- if (error_code & DSISR_PROTFAULT)
8280+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
8281 goto bad_area;
8282 #endif /* CONFIG_PPC_STD_MMU */
8283
8284@@ -471,6 +502,23 @@ bad_area:
8285 bad_area_nosemaphore:
8286 /* User mode accesses cause a SIGSEGV */
8287 if (user_mode(regs)) {
8288+
8289+#ifdef CONFIG_PAX_PAGEEXEC
8290+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
8291+#ifdef CONFIG_PPC_STD_MMU
8292+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
8293+#else
8294+ if (is_exec && regs->nip == address) {
8295+#endif
8296+ switch (pax_handle_fetch_fault(regs)) {
8297+ }
8298+
8299+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
8300+ do_group_exit(SIGKILL);
8301+ }
8302+ }
8303+#endif
8304+
8305 _exception(SIGSEGV, regs, code, address);
8306 goto bail;
8307 }
8308diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
8309index cb8bdbe..d770680 100644
8310--- a/arch/powerpc/mm/mmap.c
8311+++ b/arch/powerpc/mm/mmap.c
8312@@ -57,6 +57,10 @@ static unsigned long mmap_rnd(void)
8313 {
8314 unsigned long rnd = 0;
8315
8316+#ifdef CONFIG_PAX_RANDMMAP
8317+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8318+#endif
8319+
8320 if (current->flags & PF_RANDOMIZE) {
8321 /* 8MB for 32bit, 1GB for 64bit */
8322 if (is_32bit_task())
8323@@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8324 */
8325 if (mmap_is_legacy()) {
8326 mm->mmap_base = TASK_UNMAPPED_BASE;
8327+
8328+#ifdef CONFIG_PAX_RANDMMAP
8329+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8330+ mm->mmap_base += mm->delta_mmap;
8331+#endif
8332+
8333 mm->get_unmapped_area = arch_get_unmapped_area;
8334 } else {
8335 mm->mmap_base = mmap_base();
8336+
8337+#ifdef CONFIG_PAX_RANDMMAP
8338+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8339+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8340+#endif
8341+
8342 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8343 }
8344 }
8345diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
8346index 3e99c14..f00953c 100644
8347--- a/arch/powerpc/mm/slice.c
8348+++ b/arch/powerpc/mm/slice.c
8349@@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
8350 if ((mm->task_size - len) < addr)
8351 return 0;
8352 vma = find_vma(mm, addr);
8353- return (!vma || (addr + len) <= vma->vm_start);
8354+ return check_heap_stack_gap(vma, addr, len, 0);
8355 }
8356
8357 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
8358@@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
8359 info.align_offset = 0;
8360
8361 addr = TASK_UNMAPPED_BASE;
8362+
8363+#ifdef CONFIG_PAX_RANDMMAP
8364+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8365+ addr += mm->delta_mmap;
8366+#endif
8367+
8368 while (addr < TASK_SIZE) {
8369 info.low_limit = addr;
8370 if (!slice_scan_available(addr, available, 1, &addr))
8371@@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
8372 if (fixed && addr > (mm->task_size - len))
8373 return -EINVAL;
8374
8375+#ifdef CONFIG_PAX_RANDMMAP
8376+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
8377+ addr = 0;
8378+#endif
8379+
8380 /* If hint, make sure it matches our alignment restrictions */
8381 if (!fixed && addr) {
8382 addr = _ALIGN_UP(addr, 1ul << pshift);
8383diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
8384index 9098692..3d54cd1 100644
8385--- a/arch/powerpc/platforms/cell/spufs/file.c
8386+++ b/arch/powerpc/platforms/cell/spufs/file.c
8387@@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
8388 return VM_FAULT_NOPAGE;
8389 }
8390
8391-static int spufs_mem_mmap_access(struct vm_area_struct *vma,
8392+static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
8393 unsigned long address,
8394- void *buf, int len, int write)
8395+ void *buf, size_t len, int write)
8396 {
8397 struct spu_context *ctx = vma->vm_file->private_data;
8398 unsigned long offset = address - vma->vm_start;
8399diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
8400index c797832..ce575c8 100644
8401--- a/arch/s390/include/asm/atomic.h
8402+++ b/arch/s390/include/asm/atomic.h
8403@@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
8404 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
8405 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
8406
8407+#define atomic64_read_unchecked(v) atomic64_read(v)
8408+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
8409+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
8410+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
8411+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
8412+#define atomic64_inc_unchecked(v) atomic64_inc(v)
8413+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
8414+#define atomic64_dec_unchecked(v) atomic64_dec(v)
8415+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
8416+
8417 #define smp_mb__before_atomic_dec() smp_mb()
8418 #define smp_mb__after_atomic_dec() smp_mb()
8419 #define smp_mb__before_atomic_inc() smp_mb()
8420diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
8421index 4d7ccac..d03d0ad 100644
8422--- a/arch/s390/include/asm/cache.h
8423+++ b/arch/s390/include/asm/cache.h
8424@@ -9,8 +9,10 @@
8425 #ifndef __ARCH_S390_CACHE_H
8426 #define __ARCH_S390_CACHE_H
8427
8428-#define L1_CACHE_BYTES 256
8429+#include <linux/const.h>
8430+
8431 #define L1_CACHE_SHIFT 8
8432+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8433 #define NET_SKB_PAD 32
8434
8435 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
8436diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
8437index 78f4f87..598ce39 100644
8438--- a/arch/s390/include/asm/elf.h
8439+++ b/arch/s390/include/asm/elf.h
8440@@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
8441 the loader. We need to make sure that it is out of the way of the program
8442 that it will "exec", and that there is sufficient room for the brk. */
8443
8444-extern unsigned long randomize_et_dyn(unsigned long base);
8445-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
8446+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
8447+
8448+#ifdef CONFIG_PAX_ASLR
8449+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
8450+
8451+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
8452+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
8453+#endif
8454
8455 /* This yields a mask that user programs can use to figure out what
8456 instruction set this CPU supports. */
8457@@ -222,9 +228,6 @@ struct linux_binprm;
8458 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
8459 int arch_setup_additional_pages(struct linux_binprm *, int);
8460
8461-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
8462-#define arch_randomize_brk arch_randomize_brk
8463-
8464 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
8465
8466 #endif
8467diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
8468index c4a93d6..4d2a9b4 100644
8469--- a/arch/s390/include/asm/exec.h
8470+++ b/arch/s390/include/asm/exec.h
8471@@ -7,6 +7,6 @@
8472 #ifndef __ASM_EXEC_H
8473 #define __ASM_EXEC_H
8474
8475-extern unsigned long arch_align_stack(unsigned long sp);
8476+#define arch_align_stack(x) ((x) & ~0xfUL)
8477
8478 #endif /* __ASM_EXEC_H */
8479diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
8480index 9c33ed4..e40cbef 100644
8481--- a/arch/s390/include/asm/uaccess.h
8482+++ b/arch/s390/include/asm/uaccess.h
8483@@ -252,6 +252,10 @@ static inline unsigned long __must_check
8484 copy_to_user(void __user *to, const void *from, unsigned long n)
8485 {
8486 might_fault();
8487+
8488+ if ((long)n < 0)
8489+ return n;
8490+
8491 return __copy_to_user(to, from, n);
8492 }
8493
8494@@ -275,6 +279,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
8495 static inline unsigned long __must_check
8496 __copy_from_user(void *to, const void __user *from, unsigned long n)
8497 {
8498+ if ((long)n < 0)
8499+ return n;
8500+
8501 if (__builtin_constant_p(n) && (n <= 256))
8502 return uaccess.copy_from_user_small(n, from, to);
8503 else
8504@@ -306,10 +313,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
8505 static inline unsigned long __must_check
8506 copy_from_user(void *to, const void __user *from, unsigned long n)
8507 {
8508- unsigned int sz = __compiletime_object_size(to);
8509+ size_t sz = __compiletime_object_size(to);
8510
8511 might_fault();
8512- if (unlikely(sz != -1 && sz < n)) {
8513+
8514+ if ((long)n < 0)
8515+ return n;
8516+
8517+ if (unlikely(sz != (size_t)-1 && sz < n)) {
8518 copy_from_user_overflow();
8519 return n;
8520 }
8521diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
8522index 7845e15..59c4353 100644
8523--- a/arch/s390/kernel/module.c
8524+++ b/arch/s390/kernel/module.c
8525@@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
8526
8527 /* Increase core size by size of got & plt and set start
8528 offsets for got and plt. */
8529- me->core_size = ALIGN(me->core_size, 4);
8530- me->arch.got_offset = me->core_size;
8531- me->core_size += me->arch.got_size;
8532- me->arch.plt_offset = me->core_size;
8533- me->core_size += me->arch.plt_size;
8534+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
8535+ me->arch.got_offset = me->core_size_rw;
8536+ me->core_size_rw += me->arch.got_size;
8537+ me->arch.plt_offset = me->core_size_rx;
8538+ me->core_size_rx += me->arch.plt_size;
8539 return 0;
8540 }
8541
8542@@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8543 if (info->got_initialized == 0) {
8544 Elf_Addr *gotent;
8545
8546- gotent = me->module_core + me->arch.got_offset +
8547+ gotent = me->module_core_rw + me->arch.got_offset +
8548 info->got_offset;
8549 *gotent = val;
8550 info->got_initialized = 1;
8551@@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8552 rc = apply_rela_bits(loc, val, 0, 64, 0);
8553 else if (r_type == R_390_GOTENT ||
8554 r_type == R_390_GOTPLTENT) {
8555- val += (Elf_Addr) me->module_core - loc;
8556+ val += (Elf_Addr) me->module_core_rw - loc;
8557 rc = apply_rela_bits(loc, val, 1, 32, 1);
8558 }
8559 break;
8560@@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8561 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
8562 if (info->plt_initialized == 0) {
8563 unsigned int *ip;
8564- ip = me->module_core + me->arch.plt_offset +
8565+ ip = me->module_core_rx + me->arch.plt_offset +
8566 info->plt_offset;
8567 #ifndef CONFIG_64BIT
8568 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
8569@@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8570 val - loc + 0xffffUL < 0x1ffffeUL) ||
8571 (r_type == R_390_PLT32DBL &&
8572 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
8573- val = (Elf_Addr) me->module_core +
8574+ val = (Elf_Addr) me->module_core_rx +
8575 me->arch.plt_offset +
8576 info->plt_offset;
8577 val += rela->r_addend - loc;
8578@@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8579 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
8580 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
8581 val = val + rela->r_addend -
8582- ((Elf_Addr) me->module_core + me->arch.got_offset);
8583+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
8584 if (r_type == R_390_GOTOFF16)
8585 rc = apply_rela_bits(loc, val, 0, 16, 0);
8586 else if (r_type == R_390_GOTOFF32)
8587@@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8588 break;
8589 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
8590 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
8591- val = (Elf_Addr) me->module_core + me->arch.got_offset +
8592+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
8593 rela->r_addend - loc;
8594 if (r_type == R_390_GOTPC)
8595 rc = apply_rela_bits(loc, val, 1, 32, 0);
8596diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
8597index 2bc3edd..ab9d598 100644
8598--- a/arch/s390/kernel/process.c
8599+++ b/arch/s390/kernel/process.c
8600@@ -236,39 +236,3 @@ unsigned long get_wchan(struct task_struct *p)
8601 }
8602 return 0;
8603 }
8604-
8605-unsigned long arch_align_stack(unsigned long sp)
8606-{
8607- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8608- sp -= get_random_int() & ~PAGE_MASK;
8609- return sp & ~0xf;
8610-}
8611-
8612-static inline unsigned long brk_rnd(void)
8613-{
8614- /* 8MB for 32bit, 1GB for 64bit */
8615- if (is_32bit_task())
8616- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
8617- else
8618- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
8619-}
8620-
8621-unsigned long arch_randomize_brk(struct mm_struct *mm)
8622-{
8623- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
8624-
8625- if (ret < mm->brk)
8626- return mm->brk;
8627- return ret;
8628-}
8629-
8630-unsigned long randomize_et_dyn(unsigned long base)
8631-{
8632- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8633-
8634- if (!(current->flags & PF_RANDOMIZE))
8635- return base;
8636- if (ret < base)
8637- return base;
8638- return ret;
8639-}
8640diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
8641index 4002329..99b67cb 100644
8642--- a/arch/s390/mm/mmap.c
8643+++ b/arch/s390/mm/mmap.c
8644@@ -90,9 +90,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8645 */
8646 if (mmap_is_legacy()) {
8647 mm->mmap_base = TASK_UNMAPPED_BASE;
8648+
8649+#ifdef CONFIG_PAX_RANDMMAP
8650+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8651+ mm->mmap_base += mm->delta_mmap;
8652+#endif
8653+
8654 mm->get_unmapped_area = arch_get_unmapped_area;
8655 } else {
8656 mm->mmap_base = mmap_base();
8657+
8658+#ifdef CONFIG_PAX_RANDMMAP
8659+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8660+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8661+#endif
8662+
8663 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8664 }
8665 }
8666@@ -173,9 +185,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8667 */
8668 if (mmap_is_legacy()) {
8669 mm->mmap_base = TASK_UNMAPPED_BASE;
8670+
8671+#ifdef CONFIG_PAX_RANDMMAP
8672+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8673+ mm->mmap_base += mm->delta_mmap;
8674+#endif
8675+
8676 mm->get_unmapped_area = s390_get_unmapped_area;
8677 } else {
8678 mm->mmap_base = mmap_base();
8679+
8680+#ifdef CONFIG_PAX_RANDMMAP
8681+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8682+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8683+#endif
8684+
8685 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
8686 }
8687 }
8688diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
8689index ae3d59f..f65f075 100644
8690--- a/arch/score/include/asm/cache.h
8691+++ b/arch/score/include/asm/cache.h
8692@@ -1,7 +1,9 @@
8693 #ifndef _ASM_SCORE_CACHE_H
8694 #define _ASM_SCORE_CACHE_H
8695
8696+#include <linux/const.h>
8697+
8698 #define L1_CACHE_SHIFT 4
8699-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8700+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8701
8702 #endif /* _ASM_SCORE_CACHE_H */
8703diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
8704index f9f3cd5..58ff438 100644
8705--- a/arch/score/include/asm/exec.h
8706+++ b/arch/score/include/asm/exec.h
8707@@ -1,6 +1,6 @@
8708 #ifndef _ASM_SCORE_EXEC_H
8709 #define _ASM_SCORE_EXEC_H
8710
8711-extern unsigned long arch_align_stack(unsigned long sp);
8712+#define arch_align_stack(x) (x)
8713
8714 #endif /* _ASM_SCORE_EXEC_H */
8715diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
8716index f4c6d02..e9355c3 100644
8717--- a/arch/score/kernel/process.c
8718+++ b/arch/score/kernel/process.c
8719@@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
8720
8721 return task_pt_regs(task)->cp0_epc;
8722 }
8723-
8724-unsigned long arch_align_stack(unsigned long sp)
8725-{
8726- return sp;
8727-}
8728diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
8729index ef9e555..331bd29 100644
8730--- a/arch/sh/include/asm/cache.h
8731+++ b/arch/sh/include/asm/cache.h
8732@@ -9,10 +9,11 @@
8733 #define __ASM_SH_CACHE_H
8734 #ifdef __KERNEL__
8735
8736+#include <linux/const.h>
8737 #include <linux/init.h>
8738 #include <cpu/cache.h>
8739
8740-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8741+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8742
8743 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
8744
8745diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
8746index 6777177..cb5e44f 100644
8747--- a/arch/sh/mm/mmap.c
8748+++ b/arch/sh/mm/mmap.c
8749@@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8750 struct mm_struct *mm = current->mm;
8751 struct vm_area_struct *vma;
8752 int do_colour_align;
8753+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8754 struct vm_unmapped_area_info info;
8755
8756 if (flags & MAP_FIXED) {
8757@@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8758 if (filp || (flags & MAP_SHARED))
8759 do_colour_align = 1;
8760
8761+#ifdef CONFIG_PAX_RANDMMAP
8762+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8763+#endif
8764+
8765 if (addr) {
8766 if (do_colour_align)
8767 addr = COLOUR_ALIGN(addr, pgoff);
8768@@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8769 addr = PAGE_ALIGN(addr);
8770
8771 vma = find_vma(mm, addr);
8772- if (TASK_SIZE - len >= addr &&
8773- (!vma || addr + len <= vma->vm_start))
8774+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8775 return addr;
8776 }
8777
8778 info.flags = 0;
8779 info.length = len;
8780- info.low_limit = TASK_UNMAPPED_BASE;
8781+ info.low_limit = mm->mmap_base;
8782 info.high_limit = TASK_SIZE;
8783 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
8784 info.align_offset = pgoff << PAGE_SHIFT;
8785@@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8786 struct mm_struct *mm = current->mm;
8787 unsigned long addr = addr0;
8788 int do_colour_align;
8789+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8790 struct vm_unmapped_area_info info;
8791
8792 if (flags & MAP_FIXED) {
8793@@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8794 if (filp || (flags & MAP_SHARED))
8795 do_colour_align = 1;
8796
8797+#ifdef CONFIG_PAX_RANDMMAP
8798+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8799+#endif
8800+
8801 /* requesting a specific address */
8802 if (addr) {
8803 if (do_colour_align)
8804@@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8805 addr = PAGE_ALIGN(addr);
8806
8807 vma = find_vma(mm, addr);
8808- if (TASK_SIZE - len >= addr &&
8809- (!vma || addr + len <= vma->vm_start))
8810+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8811 return addr;
8812 }
8813
8814@@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8815 VM_BUG_ON(addr != -ENOMEM);
8816 info.flags = 0;
8817 info.low_limit = TASK_UNMAPPED_BASE;
8818+
8819+#ifdef CONFIG_PAX_RANDMMAP
8820+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8821+ info.low_limit += mm->delta_mmap;
8822+#endif
8823+
8824 info.high_limit = TASK_SIZE;
8825 addr = vm_unmapped_area(&info);
8826 }
8827diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
8828index be56a24..443328f 100644
8829--- a/arch/sparc/include/asm/atomic_64.h
8830+++ b/arch/sparc/include/asm/atomic_64.h
8831@@ -14,18 +14,40 @@
8832 #define ATOMIC64_INIT(i) { (i) }
8833
8834 #define atomic_read(v) (*(volatile int *)&(v)->counter)
8835+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
8836+{
8837+ return v->counter;
8838+}
8839 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
8840+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
8841+{
8842+ return v->counter;
8843+}
8844
8845 #define atomic_set(v, i) (((v)->counter) = i)
8846+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
8847+{
8848+ v->counter = i;
8849+}
8850 #define atomic64_set(v, i) (((v)->counter) = i)
8851+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
8852+{
8853+ v->counter = i;
8854+}
8855
8856 extern void atomic_add(int, atomic_t *);
8857+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
8858 extern void atomic64_add(long, atomic64_t *);
8859+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
8860 extern void atomic_sub(int, atomic_t *);
8861+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
8862 extern void atomic64_sub(long, atomic64_t *);
8863+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
8864
8865 extern int atomic_add_ret(int, atomic_t *);
8866+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
8867 extern long atomic64_add_ret(long, atomic64_t *);
8868+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
8869 extern int atomic_sub_ret(int, atomic_t *);
8870 extern long atomic64_sub_ret(long, atomic64_t *);
8871
8872@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
8873 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
8874
8875 #define atomic_inc_return(v) atomic_add_ret(1, v)
8876+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
8877+{
8878+ return atomic_add_ret_unchecked(1, v);
8879+}
8880 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
8881+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
8882+{
8883+ return atomic64_add_ret_unchecked(1, v);
8884+}
8885
8886 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
8887 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
8888
8889 #define atomic_add_return(i, v) atomic_add_ret(i, v)
8890+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
8891+{
8892+ return atomic_add_ret_unchecked(i, v);
8893+}
8894 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
8895+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
8896+{
8897+ return atomic64_add_ret_unchecked(i, v);
8898+}
8899
8900 /*
8901 * atomic_inc_and_test - increment and test
8902@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
8903 * other cases.
8904 */
8905 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
8906+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
8907+{
8908+ return atomic_inc_return_unchecked(v) == 0;
8909+}
8910 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
8911
8912 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
8913@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
8914 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
8915
8916 #define atomic_inc(v) atomic_add(1, v)
8917+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
8918+{
8919+ atomic_add_unchecked(1, v);
8920+}
8921 #define atomic64_inc(v) atomic64_add(1, v)
8922+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
8923+{
8924+ atomic64_add_unchecked(1, v);
8925+}
8926
8927 #define atomic_dec(v) atomic_sub(1, v)
8928+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
8929+{
8930+ atomic_sub_unchecked(1, v);
8931+}
8932 #define atomic64_dec(v) atomic64_sub(1, v)
8933+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
8934+{
8935+ atomic64_sub_unchecked(1, v);
8936+}
8937
8938 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
8939 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
8940
8941 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
8942+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
8943+{
8944+ return cmpxchg(&v->counter, old, new);
8945+}
8946 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
8947+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
8948+{
8949+ return xchg(&v->counter, new);
8950+}
8951
8952 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
8953 {
8954- int c, old;
8955+ int c, old, new;
8956 c = atomic_read(v);
8957 for (;;) {
8958- if (unlikely(c == (u)))
8959+ if (unlikely(c == u))
8960 break;
8961- old = atomic_cmpxchg((v), c, c + (a));
8962+
8963+ asm volatile("addcc %2, %0, %0\n"
8964+
8965+#ifdef CONFIG_PAX_REFCOUNT
8966+ "tvs %%icc, 6\n"
8967+#endif
8968+
8969+ : "=r" (new)
8970+ : "0" (c), "ir" (a)
8971+ : "cc");
8972+
8973+ old = atomic_cmpxchg(v, c, new);
8974 if (likely(old == c))
8975 break;
8976 c = old;
8977@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
8978 #define atomic64_cmpxchg(v, o, n) \
8979 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
8980 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
8981+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
8982+{
8983+ return xchg(&v->counter, new);
8984+}
8985
8986 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
8987 {
8988- long c, old;
8989+ long c, old, new;
8990 c = atomic64_read(v);
8991 for (;;) {
8992- if (unlikely(c == (u)))
8993+ if (unlikely(c == u))
8994 break;
8995- old = atomic64_cmpxchg((v), c, c + (a));
8996+
8997+ asm volatile("addcc %2, %0, %0\n"
8998+
8999+#ifdef CONFIG_PAX_REFCOUNT
9000+ "tvs %%xcc, 6\n"
9001+#endif
9002+
9003+ : "=r" (new)
9004+ : "0" (c), "ir" (a)
9005+ : "cc");
9006+
9007+ old = atomic64_cmpxchg(v, c, new);
9008 if (likely(old == c))
9009 break;
9010 c = old;
9011 }
9012- return c != (u);
9013+ return c != u;
9014 }
9015
9016 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9017diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
9018index 5bb6991..5c2132e 100644
9019--- a/arch/sparc/include/asm/cache.h
9020+++ b/arch/sparc/include/asm/cache.h
9021@@ -7,10 +7,12 @@
9022 #ifndef _SPARC_CACHE_H
9023 #define _SPARC_CACHE_H
9024
9025+#include <linux/const.h>
9026+
9027 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
9028
9029 #define L1_CACHE_SHIFT 5
9030-#define L1_CACHE_BYTES 32
9031+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9032
9033 #ifdef CONFIG_SPARC32
9034 #define SMP_CACHE_BYTES_SHIFT 5
9035diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
9036index a24e41f..47677ff 100644
9037--- a/arch/sparc/include/asm/elf_32.h
9038+++ b/arch/sparc/include/asm/elf_32.h
9039@@ -114,6 +114,13 @@ typedef struct {
9040
9041 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
9042
9043+#ifdef CONFIG_PAX_ASLR
9044+#define PAX_ELF_ET_DYN_BASE 0x10000UL
9045+
9046+#define PAX_DELTA_MMAP_LEN 16
9047+#define PAX_DELTA_STACK_LEN 16
9048+#endif
9049+
9050 /* This yields a mask that user programs can use to figure out what
9051 instruction set this cpu supports. This can NOT be done in userspace
9052 on Sparc. */
9053diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
9054index 370ca1e..d4f4a98 100644
9055--- a/arch/sparc/include/asm/elf_64.h
9056+++ b/arch/sparc/include/asm/elf_64.h
9057@@ -189,6 +189,13 @@ typedef struct {
9058 #define ELF_ET_DYN_BASE 0x0000010000000000UL
9059 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
9060
9061+#ifdef CONFIG_PAX_ASLR
9062+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
9063+
9064+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
9065+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
9066+#endif
9067+
9068 extern unsigned long sparc64_elf_hwcap;
9069 #define ELF_HWCAP sparc64_elf_hwcap
9070
9071diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
9072index 9b1c36d..209298b 100644
9073--- a/arch/sparc/include/asm/pgalloc_32.h
9074+++ b/arch/sparc/include/asm/pgalloc_32.h
9075@@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
9076 }
9077
9078 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
9079+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
9080
9081 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
9082 unsigned long address)
9083diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
9084index bcfe063..b333142 100644
9085--- a/arch/sparc/include/asm/pgalloc_64.h
9086+++ b/arch/sparc/include/asm/pgalloc_64.h
9087@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
9088 }
9089
9090 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
9091+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
9092
9093 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
9094 {
9095diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
9096index 502f632..da1917f 100644
9097--- a/arch/sparc/include/asm/pgtable_32.h
9098+++ b/arch/sparc/include/asm/pgtable_32.h
9099@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
9100 #define PAGE_SHARED SRMMU_PAGE_SHARED
9101 #define PAGE_COPY SRMMU_PAGE_COPY
9102 #define PAGE_READONLY SRMMU_PAGE_RDONLY
9103+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
9104+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
9105+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
9106 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
9107
9108 /* Top-level page directory - dummy used by init-mm.
9109@@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
9110
9111 /* xwr */
9112 #define __P000 PAGE_NONE
9113-#define __P001 PAGE_READONLY
9114-#define __P010 PAGE_COPY
9115-#define __P011 PAGE_COPY
9116+#define __P001 PAGE_READONLY_NOEXEC
9117+#define __P010 PAGE_COPY_NOEXEC
9118+#define __P011 PAGE_COPY_NOEXEC
9119 #define __P100 PAGE_READONLY
9120 #define __P101 PAGE_READONLY
9121 #define __P110 PAGE_COPY
9122 #define __P111 PAGE_COPY
9123
9124 #define __S000 PAGE_NONE
9125-#define __S001 PAGE_READONLY
9126-#define __S010 PAGE_SHARED
9127-#define __S011 PAGE_SHARED
9128+#define __S001 PAGE_READONLY_NOEXEC
9129+#define __S010 PAGE_SHARED_NOEXEC
9130+#define __S011 PAGE_SHARED_NOEXEC
9131 #define __S100 PAGE_READONLY
9132 #define __S101 PAGE_READONLY
9133 #define __S110 PAGE_SHARED
9134diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
9135index 79da178..c2eede8 100644
9136--- a/arch/sparc/include/asm/pgtsrmmu.h
9137+++ b/arch/sparc/include/asm/pgtsrmmu.h
9138@@ -115,6 +115,11 @@
9139 SRMMU_EXEC | SRMMU_REF)
9140 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
9141 SRMMU_EXEC | SRMMU_REF)
9142+
9143+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
9144+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9145+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9146+
9147 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
9148 SRMMU_DIRTY | SRMMU_REF)
9149
9150diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
9151index 9689176..63c18ea 100644
9152--- a/arch/sparc/include/asm/spinlock_64.h
9153+++ b/arch/sparc/include/asm/spinlock_64.h
9154@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
9155
9156 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
9157
9158-static void inline arch_read_lock(arch_rwlock_t *lock)
9159+static inline void arch_read_lock(arch_rwlock_t *lock)
9160 {
9161 unsigned long tmp1, tmp2;
9162
9163 __asm__ __volatile__ (
9164 "1: ldsw [%2], %0\n"
9165 " brlz,pn %0, 2f\n"
9166-"4: add %0, 1, %1\n"
9167+"4: addcc %0, 1, %1\n"
9168+
9169+#ifdef CONFIG_PAX_REFCOUNT
9170+" tvs %%icc, 6\n"
9171+#endif
9172+
9173 " cas [%2], %0, %1\n"
9174 " cmp %0, %1\n"
9175 " bne,pn %%icc, 1b\n"
9176@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
9177 " .previous"
9178 : "=&r" (tmp1), "=&r" (tmp2)
9179 : "r" (lock)
9180- : "memory");
9181+ : "memory", "cc");
9182 }
9183
9184-static int inline arch_read_trylock(arch_rwlock_t *lock)
9185+static inline int arch_read_trylock(arch_rwlock_t *lock)
9186 {
9187 int tmp1, tmp2;
9188
9189@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9190 "1: ldsw [%2], %0\n"
9191 " brlz,a,pn %0, 2f\n"
9192 " mov 0, %0\n"
9193-" add %0, 1, %1\n"
9194+" addcc %0, 1, %1\n"
9195+
9196+#ifdef CONFIG_PAX_REFCOUNT
9197+" tvs %%icc, 6\n"
9198+#endif
9199+
9200 " cas [%2], %0, %1\n"
9201 " cmp %0, %1\n"
9202 " bne,pn %%icc, 1b\n"
9203@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9204 return tmp1;
9205 }
9206
9207-static void inline arch_read_unlock(arch_rwlock_t *lock)
9208+static inline void arch_read_unlock(arch_rwlock_t *lock)
9209 {
9210 unsigned long tmp1, tmp2;
9211
9212 __asm__ __volatile__(
9213 "1: lduw [%2], %0\n"
9214-" sub %0, 1, %1\n"
9215+" subcc %0, 1, %1\n"
9216+
9217+#ifdef CONFIG_PAX_REFCOUNT
9218+" tvs %%icc, 6\n"
9219+#endif
9220+
9221 " cas [%2], %0, %1\n"
9222 " cmp %0, %1\n"
9223 " bne,pn %%xcc, 1b\n"
9224@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
9225 : "memory");
9226 }
9227
9228-static void inline arch_write_lock(arch_rwlock_t *lock)
9229+static inline void arch_write_lock(arch_rwlock_t *lock)
9230 {
9231 unsigned long mask, tmp1, tmp2;
9232
9233@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
9234 : "memory");
9235 }
9236
9237-static void inline arch_write_unlock(arch_rwlock_t *lock)
9238+static inline void arch_write_unlock(arch_rwlock_t *lock)
9239 {
9240 __asm__ __volatile__(
9241 " stw %%g0, [%0]"
9242@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
9243 : "memory");
9244 }
9245
9246-static int inline arch_write_trylock(arch_rwlock_t *lock)
9247+static inline int arch_write_trylock(arch_rwlock_t *lock)
9248 {
9249 unsigned long mask, tmp1, tmp2, result;
9250
9251diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
9252index dd38075..e7cac83 100644
9253--- a/arch/sparc/include/asm/thread_info_32.h
9254+++ b/arch/sparc/include/asm/thread_info_32.h
9255@@ -49,6 +49,8 @@ struct thread_info {
9256 unsigned long w_saved;
9257
9258 struct restart_block restart_block;
9259+
9260+ unsigned long lowest_stack;
9261 };
9262
9263 /*
9264diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
9265index d5e5042..9bfee76 100644
9266--- a/arch/sparc/include/asm/thread_info_64.h
9267+++ b/arch/sparc/include/asm/thread_info_64.h
9268@@ -63,6 +63,8 @@ struct thread_info {
9269 struct pt_regs *kern_una_regs;
9270 unsigned int kern_una_insn;
9271
9272+ unsigned long lowest_stack;
9273+
9274 unsigned long fpregs[0] __attribute__ ((aligned(64)));
9275 };
9276
9277@@ -192,10 +194,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
9278 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
9279 /* flag bit 6 is available */
9280 #define TIF_32BIT 7 /* 32-bit binary */
9281-/* flag bit 8 is available */
9282+#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
9283 #define TIF_SECCOMP 9 /* secure computing */
9284 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
9285 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
9286+
9287 /* NOTE: Thread flags >= 12 should be ones we have no interest
9288 * in using in assembly, else we can't use the mask as
9289 * an immediate value in instructions such as andcc.
9290@@ -214,12 +217,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
9291 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
9292 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
9293 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
9294+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
9295
9296 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
9297 _TIF_DO_NOTIFY_RESUME_MASK | \
9298 _TIF_NEED_RESCHED)
9299 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
9300
9301+#define _TIF_WORK_SYSCALL \
9302+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
9303+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
9304+
9305+
9306 /*
9307 * Thread-synchronous status.
9308 *
9309diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
9310index 0167d26..767bb0c 100644
9311--- a/arch/sparc/include/asm/uaccess.h
9312+++ b/arch/sparc/include/asm/uaccess.h
9313@@ -1,5 +1,6 @@
9314 #ifndef ___ASM_SPARC_UACCESS_H
9315 #define ___ASM_SPARC_UACCESS_H
9316+
9317 #if defined(__sparc__) && defined(__arch64__)
9318 #include <asm/uaccess_64.h>
9319 #else
9320diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
9321index 53a28dd..50c38c3 100644
9322--- a/arch/sparc/include/asm/uaccess_32.h
9323+++ b/arch/sparc/include/asm/uaccess_32.h
9324@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
9325
9326 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
9327 {
9328- if (n && __access_ok((unsigned long) to, n))
9329+ if ((long)n < 0)
9330+ return n;
9331+
9332+ if (n && __access_ok((unsigned long) to, n)) {
9333+ if (!__builtin_constant_p(n))
9334+ check_object_size(from, n, true);
9335 return __copy_user(to, (__force void __user *) from, n);
9336- else
9337+ } else
9338 return n;
9339 }
9340
9341 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
9342 {
9343+ if ((long)n < 0)
9344+ return n;
9345+
9346+ if (!__builtin_constant_p(n))
9347+ check_object_size(from, n, true);
9348+
9349 return __copy_user(to, (__force void __user *) from, n);
9350 }
9351
9352 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
9353 {
9354- if (n && __access_ok((unsigned long) from, n))
9355+ if ((long)n < 0)
9356+ return n;
9357+
9358+ if (n && __access_ok((unsigned long) from, n)) {
9359+ if (!__builtin_constant_p(n))
9360+ check_object_size(to, n, false);
9361 return __copy_user((__force void __user *) to, from, n);
9362- else
9363+ } else
9364 return n;
9365 }
9366
9367 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
9368 {
9369+ if ((long)n < 0)
9370+ return n;
9371+
9372 return __copy_user((__force void __user *) to, from, n);
9373 }
9374
9375diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
9376index e562d3c..191f176 100644
9377--- a/arch/sparc/include/asm/uaccess_64.h
9378+++ b/arch/sparc/include/asm/uaccess_64.h
9379@@ -10,6 +10,7 @@
9380 #include <linux/compiler.h>
9381 #include <linux/string.h>
9382 #include <linux/thread_info.h>
9383+#include <linux/kernel.h>
9384 #include <asm/asi.h>
9385 #include <asm/spitfire.h>
9386 #include <asm-generic/uaccess-unaligned.h>
9387@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
9388 static inline unsigned long __must_check
9389 copy_from_user(void *to, const void __user *from, unsigned long size)
9390 {
9391- unsigned long ret = ___copy_from_user(to, from, size);
9392+ unsigned long ret;
9393
9394+ if ((long)size < 0 || size > INT_MAX)
9395+ return size;
9396+
9397+ if (!__builtin_constant_p(size))
9398+ check_object_size(to, size, false);
9399+
9400+ ret = ___copy_from_user(to, from, size);
9401 if (unlikely(ret))
9402 ret = copy_from_user_fixup(to, from, size);
9403
9404@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
9405 static inline unsigned long __must_check
9406 copy_to_user(void __user *to, const void *from, unsigned long size)
9407 {
9408- unsigned long ret = ___copy_to_user(to, from, size);
9409+ unsigned long ret;
9410
9411+ if ((long)size < 0 || size > INT_MAX)
9412+ return size;
9413+
9414+ if (!__builtin_constant_p(size))
9415+ check_object_size(from, size, true);
9416+
9417+ ret = ___copy_to_user(to, from, size);
9418 if (unlikely(ret))
9419 ret = copy_to_user_fixup(to, from, size);
9420 return ret;
9421diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
9422index d432fb2..6056af1 100644
9423--- a/arch/sparc/kernel/Makefile
9424+++ b/arch/sparc/kernel/Makefile
9425@@ -3,7 +3,7 @@
9426 #
9427
9428 asflags-y := -ansi
9429-ccflags-y := -Werror
9430+#ccflags-y := -Werror
9431
9432 extra-y := head_$(BITS).o
9433
9434diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
9435index fdd819d..5af08c8 100644
9436--- a/arch/sparc/kernel/process_32.c
9437+++ b/arch/sparc/kernel/process_32.c
9438@@ -116,14 +116,14 @@ void show_regs(struct pt_regs *r)
9439
9440 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
9441 r->psr, r->pc, r->npc, r->y, print_tainted());
9442- printk("PC: <%pS>\n", (void *) r->pc);
9443+ printk("PC: <%pA>\n", (void *) r->pc);
9444 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9445 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
9446 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
9447 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9448 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
9449 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
9450- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
9451+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
9452
9453 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9454 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
9455@@ -160,7 +160,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
9456 rw = (struct reg_window32 *) fp;
9457 pc = rw->ins[7];
9458 printk("[%08lx : ", pc);
9459- printk("%pS ] ", (void *) pc);
9460+ printk("%pA ] ", (void *) pc);
9461 fp = rw->ins[6];
9462 } while (++count < 16);
9463 printk("\n");
9464diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
9465index baebab2..9cd13b1 100644
9466--- a/arch/sparc/kernel/process_64.c
9467+++ b/arch/sparc/kernel/process_64.c
9468@@ -158,7 +158,7 @@ static void show_regwindow(struct pt_regs *regs)
9469 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
9470 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
9471 if (regs->tstate & TSTATE_PRIV)
9472- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
9473+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
9474 }
9475
9476 void show_regs(struct pt_regs *regs)
9477@@ -167,7 +167,7 @@ void show_regs(struct pt_regs *regs)
9478
9479 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
9480 regs->tpc, regs->tnpc, regs->y, print_tainted());
9481- printk("TPC: <%pS>\n", (void *) regs->tpc);
9482+ printk("TPC: <%pA>\n", (void *) regs->tpc);
9483 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
9484 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
9485 regs->u_regs[3]);
9486@@ -180,7 +180,7 @@ void show_regs(struct pt_regs *regs)
9487 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
9488 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
9489 regs->u_regs[15]);
9490- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
9491+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
9492 show_regwindow(regs);
9493 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
9494 }
9495@@ -269,7 +269,7 @@ void arch_trigger_all_cpu_backtrace(void)
9496 ((tp && tp->task) ? tp->task->pid : -1));
9497
9498 if (gp->tstate & TSTATE_PRIV) {
9499- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
9500+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
9501 (void *) gp->tpc,
9502 (void *) gp->o7,
9503 (void *) gp->i7,
9504diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
9505index 79cc0d1..ec62734 100644
9506--- a/arch/sparc/kernel/prom_common.c
9507+++ b/arch/sparc/kernel/prom_common.c
9508@@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
9509
9510 unsigned int prom_early_allocated __initdata;
9511
9512-static struct of_pdt_ops prom_sparc_ops __initdata = {
9513+static struct of_pdt_ops prom_sparc_ops __initconst = {
9514 .nextprop = prom_common_nextprop,
9515 .getproplen = prom_getproplen,
9516 .getproperty = prom_getproperty,
9517diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
9518index 7ff45e4..a58f271 100644
9519--- a/arch/sparc/kernel/ptrace_64.c
9520+++ b/arch/sparc/kernel/ptrace_64.c
9521@@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
9522 return ret;
9523 }
9524
9525+#ifdef CONFIG_GRKERNSEC_SETXID
9526+extern void gr_delayed_cred_worker(void);
9527+#endif
9528+
9529 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
9530 {
9531 int ret = 0;
9532@@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
9533 /* do the secure computing check first */
9534 secure_computing_strict(regs->u_regs[UREG_G1]);
9535
9536+#ifdef CONFIG_GRKERNSEC_SETXID
9537+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9538+ gr_delayed_cred_worker();
9539+#endif
9540+
9541 if (test_thread_flag(TIF_SYSCALL_TRACE))
9542 ret = tracehook_report_syscall_entry(regs);
9543
9544@@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
9545
9546 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
9547 {
9548+#ifdef CONFIG_GRKERNSEC_SETXID
9549+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9550+ gr_delayed_cred_worker();
9551+#endif
9552+
9553 audit_syscall_exit(regs);
9554
9555 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
9556diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
9557index e142545..fd29654 100644
9558--- a/arch/sparc/kernel/smp_64.c
9559+++ b/arch/sparc/kernel/smp_64.c
9560@@ -869,8 +869,8 @@ extern unsigned long xcall_flush_dcache_page_cheetah;
9561 extern unsigned long xcall_flush_dcache_page_spitfire;
9562
9563 #ifdef CONFIG_DEBUG_DCFLUSH
9564-extern atomic_t dcpage_flushes;
9565-extern atomic_t dcpage_flushes_xcall;
9566+extern atomic_unchecked_t dcpage_flushes;
9567+extern atomic_unchecked_t dcpage_flushes_xcall;
9568 #endif
9569
9570 static inline void __local_flush_dcache_page(struct page *page)
9571@@ -894,7 +894,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
9572 return;
9573
9574 #ifdef CONFIG_DEBUG_DCFLUSH
9575- atomic_inc(&dcpage_flushes);
9576+ atomic_inc_unchecked(&dcpage_flushes);
9577 #endif
9578
9579 this_cpu = get_cpu();
9580@@ -918,7 +918,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
9581 xcall_deliver(data0, __pa(pg_addr),
9582 (u64) pg_addr, cpumask_of(cpu));
9583 #ifdef CONFIG_DEBUG_DCFLUSH
9584- atomic_inc(&dcpage_flushes_xcall);
9585+ atomic_inc_unchecked(&dcpage_flushes_xcall);
9586 #endif
9587 }
9588 }
9589@@ -937,7 +937,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
9590 preempt_disable();
9591
9592 #ifdef CONFIG_DEBUG_DCFLUSH
9593- atomic_inc(&dcpage_flushes);
9594+ atomic_inc_unchecked(&dcpage_flushes);
9595 #endif
9596 data0 = 0;
9597 pg_addr = page_address(page);
9598@@ -954,7 +954,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
9599 xcall_deliver(data0, __pa(pg_addr),
9600 (u64) pg_addr, cpu_online_mask);
9601 #ifdef CONFIG_DEBUG_DCFLUSH
9602- atomic_inc(&dcpage_flushes_xcall);
9603+ atomic_inc_unchecked(&dcpage_flushes_xcall);
9604 #endif
9605 }
9606 __local_flush_dcache_page(page);
9607diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
9608index 3a8d184..49498a8 100644
9609--- a/arch/sparc/kernel/sys_sparc_32.c
9610+++ b/arch/sparc/kernel/sys_sparc_32.c
9611@@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9612 if (len > TASK_SIZE - PAGE_SIZE)
9613 return -ENOMEM;
9614 if (!addr)
9615- addr = TASK_UNMAPPED_BASE;
9616+ addr = current->mm->mmap_base;
9617
9618 info.flags = 0;
9619 info.length = len;
9620diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
9621index 51561b8..8256764 100644
9622--- a/arch/sparc/kernel/sys_sparc_64.c
9623+++ b/arch/sparc/kernel/sys_sparc_64.c
9624@@ -90,13 +90,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9625 struct vm_area_struct * vma;
9626 unsigned long task_size = TASK_SIZE;
9627 int do_color_align;
9628+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9629 struct vm_unmapped_area_info info;
9630
9631 if (flags & MAP_FIXED) {
9632 /* We do not accept a shared mapping if it would violate
9633 * cache aliasing constraints.
9634 */
9635- if ((flags & MAP_SHARED) &&
9636+ if ((filp || (flags & MAP_SHARED)) &&
9637 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
9638 return -EINVAL;
9639 return addr;
9640@@ -111,6 +112,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9641 if (filp || (flags & MAP_SHARED))
9642 do_color_align = 1;
9643
9644+#ifdef CONFIG_PAX_RANDMMAP
9645+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9646+#endif
9647+
9648 if (addr) {
9649 if (do_color_align)
9650 addr = COLOR_ALIGN(addr, pgoff);
9651@@ -118,22 +123,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9652 addr = PAGE_ALIGN(addr);
9653
9654 vma = find_vma(mm, addr);
9655- if (task_size - len >= addr &&
9656- (!vma || addr + len <= vma->vm_start))
9657+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9658 return addr;
9659 }
9660
9661 info.flags = 0;
9662 info.length = len;
9663- info.low_limit = TASK_UNMAPPED_BASE;
9664+ info.low_limit = mm->mmap_base;
9665 info.high_limit = min(task_size, VA_EXCLUDE_START);
9666 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
9667 info.align_offset = pgoff << PAGE_SHIFT;
9668+ info.threadstack_offset = offset;
9669 addr = vm_unmapped_area(&info);
9670
9671 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
9672 VM_BUG_ON(addr != -ENOMEM);
9673 info.low_limit = VA_EXCLUDE_END;
9674+
9675+#ifdef CONFIG_PAX_RANDMMAP
9676+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9677+ info.low_limit += mm->delta_mmap;
9678+#endif
9679+
9680 info.high_limit = task_size;
9681 addr = vm_unmapped_area(&info);
9682 }
9683@@ -151,6 +162,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9684 unsigned long task_size = STACK_TOP32;
9685 unsigned long addr = addr0;
9686 int do_color_align;
9687+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9688 struct vm_unmapped_area_info info;
9689
9690 /* This should only ever run for 32-bit processes. */
9691@@ -160,7 +172,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9692 /* We do not accept a shared mapping if it would violate
9693 * cache aliasing constraints.
9694 */
9695- if ((flags & MAP_SHARED) &&
9696+ if ((filp || (flags & MAP_SHARED)) &&
9697 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
9698 return -EINVAL;
9699 return addr;
9700@@ -173,6 +185,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9701 if (filp || (flags & MAP_SHARED))
9702 do_color_align = 1;
9703
9704+#ifdef CONFIG_PAX_RANDMMAP
9705+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9706+#endif
9707+
9708 /* requesting a specific address */
9709 if (addr) {
9710 if (do_color_align)
9711@@ -181,8 +197,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9712 addr = PAGE_ALIGN(addr);
9713
9714 vma = find_vma(mm, addr);
9715- if (task_size - len >= addr &&
9716- (!vma || addr + len <= vma->vm_start))
9717+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9718 return addr;
9719 }
9720
9721@@ -192,6 +207,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9722 info.high_limit = mm->mmap_base;
9723 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
9724 info.align_offset = pgoff << PAGE_SHIFT;
9725+ info.threadstack_offset = offset;
9726 addr = vm_unmapped_area(&info);
9727
9728 /*
9729@@ -204,6 +220,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9730 VM_BUG_ON(addr != -ENOMEM);
9731 info.flags = 0;
9732 info.low_limit = TASK_UNMAPPED_BASE;
9733+
9734+#ifdef CONFIG_PAX_RANDMMAP
9735+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9736+ info.low_limit += mm->delta_mmap;
9737+#endif
9738+
9739 info.high_limit = STACK_TOP32;
9740 addr = vm_unmapped_area(&info);
9741 }
9742@@ -260,10 +282,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
9743 EXPORT_SYMBOL(get_fb_unmapped_area);
9744
9745 /* Essentially the same as PowerPC. */
9746-static unsigned long mmap_rnd(void)
9747+static unsigned long mmap_rnd(struct mm_struct *mm)
9748 {
9749 unsigned long rnd = 0UL;
9750
9751+#ifdef CONFIG_PAX_RANDMMAP
9752+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9753+#endif
9754+
9755 if (current->flags & PF_RANDOMIZE) {
9756 unsigned long val = get_random_int();
9757 if (test_thread_flag(TIF_32BIT))
9758@@ -276,7 +302,7 @@ static unsigned long mmap_rnd(void)
9759
9760 void arch_pick_mmap_layout(struct mm_struct *mm)
9761 {
9762- unsigned long random_factor = mmap_rnd();
9763+ unsigned long random_factor = mmap_rnd(mm);
9764 unsigned long gap;
9765
9766 /*
9767@@ -289,6 +315,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9768 gap == RLIM_INFINITY ||
9769 sysctl_legacy_va_layout) {
9770 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
9771+
9772+#ifdef CONFIG_PAX_RANDMMAP
9773+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9774+ mm->mmap_base += mm->delta_mmap;
9775+#endif
9776+
9777 mm->get_unmapped_area = arch_get_unmapped_area;
9778 } else {
9779 /* We know it's 32-bit */
9780@@ -300,6 +332,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9781 gap = (task_size / 6 * 5);
9782
9783 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
9784+
9785+#ifdef CONFIG_PAX_RANDMMAP
9786+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9787+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9788+#endif
9789+
9790 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9791 }
9792 }
9793diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
9794index 22a1098..6255eb9 100644
9795--- a/arch/sparc/kernel/syscalls.S
9796+++ b/arch/sparc/kernel/syscalls.S
9797@@ -52,7 +52,7 @@ sys32_rt_sigreturn:
9798 #endif
9799 .align 32
9800 1: ldx [%g6 + TI_FLAGS], %l5
9801- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9802+ andcc %l5, _TIF_WORK_SYSCALL, %g0
9803 be,pt %icc, rtrap
9804 nop
9805 call syscall_trace_leave
9806@@ -184,7 +184,7 @@ linux_sparc_syscall32:
9807
9808 srl %i5, 0, %o5 ! IEU1
9809 srl %i2, 0, %o2 ! IEU0 Group
9810- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9811+ andcc %l0, _TIF_WORK_SYSCALL, %g0
9812 bne,pn %icc, linux_syscall_trace32 ! CTI
9813 mov %i0, %l5 ! IEU1
9814 call %l7 ! CTI Group brk forced
9815@@ -207,7 +207,7 @@ linux_sparc_syscall:
9816
9817 mov %i3, %o3 ! IEU1
9818 mov %i4, %o4 ! IEU0 Group
9819- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9820+ andcc %l0, _TIF_WORK_SYSCALL, %g0
9821 bne,pn %icc, linux_syscall_trace ! CTI Group
9822 mov %i0, %l5 ! IEU0
9823 2: call %l7 ! CTI Group brk forced
9824@@ -223,7 +223,7 @@ ret_sys_call:
9825
9826 cmp %o0, -ERESTART_RESTARTBLOCK
9827 bgeu,pn %xcc, 1f
9828- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
9829+ andcc %l0, _TIF_WORK_SYSCALL, %g0
9830 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
9831
9832 2:
9833diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
9834index 6629829..036032d 100644
9835--- a/arch/sparc/kernel/traps_32.c
9836+++ b/arch/sparc/kernel/traps_32.c
9837@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
9838 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
9839 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
9840
9841+extern void gr_handle_kernel_exploit(void);
9842+
9843 void die_if_kernel(char *str, struct pt_regs *regs)
9844 {
9845 static int die_counter;
9846@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
9847 count++ < 30 &&
9848 (((unsigned long) rw) >= PAGE_OFFSET) &&
9849 !(((unsigned long) rw) & 0x7)) {
9850- printk("Caller[%08lx]: %pS\n", rw->ins[7],
9851+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
9852 (void *) rw->ins[7]);
9853 rw = (struct reg_window32 *)rw->ins[6];
9854 }
9855 }
9856 printk("Instruction DUMP:");
9857 instruction_dump ((unsigned long *) regs->pc);
9858- if(regs->psr & PSR_PS)
9859+ if(regs->psr & PSR_PS) {
9860+ gr_handle_kernel_exploit();
9861 do_exit(SIGKILL);
9862+ }
9863 do_exit(SIGSEGV);
9864 }
9865
9866diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
9867index b3f833a..f485f80 100644
9868--- a/arch/sparc/kernel/traps_64.c
9869+++ b/arch/sparc/kernel/traps_64.c
9870@@ -76,7 +76,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
9871 i + 1,
9872 p->trapstack[i].tstate, p->trapstack[i].tpc,
9873 p->trapstack[i].tnpc, p->trapstack[i].tt);
9874- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
9875+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
9876 }
9877 }
9878
9879@@ -96,6 +96,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
9880
9881 lvl -= 0x100;
9882 if (regs->tstate & TSTATE_PRIV) {
9883+
9884+#ifdef CONFIG_PAX_REFCOUNT
9885+ if (lvl == 6)
9886+ pax_report_refcount_overflow(regs);
9887+#endif
9888+
9889 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
9890 die_if_kernel(buffer, regs);
9891 }
9892@@ -114,11 +120,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
9893 void bad_trap_tl1(struct pt_regs *regs, long lvl)
9894 {
9895 char buffer[32];
9896-
9897+
9898 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
9899 0, lvl, SIGTRAP) == NOTIFY_STOP)
9900 return;
9901
9902+#ifdef CONFIG_PAX_REFCOUNT
9903+ if (lvl == 6)
9904+ pax_report_refcount_overflow(regs);
9905+#endif
9906+
9907 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
9908
9909 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
9910@@ -1142,7 +1153,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
9911 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
9912 printk("%s" "ERROR(%d): ",
9913 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
9914- printk("TPC<%pS>\n", (void *) regs->tpc);
9915+ printk("TPC<%pA>\n", (void *) regs->tpc);
9916 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
9917 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
9918 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
9919@@ -1749,7 +1760,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
9920 smp_processor_id(),
9921 (type & 0x1) ? 'I' : 'D',
9922 regs->tpc);
9923- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
9924+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
9925 panic("Irrecoverable Cheetah+ parity error.");
9926 }
9927
9928@@ -1757,7 +1768,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
9929 smp_processor_id(),
9930 (type & 0x1) ? 'I' : 'D',
9931 regs->tpc);
9932- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
9933+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
9934 }
9935
9936 struct sun4v_error_entry {
9937@@ -1830,8 +1841,8 @@ struct sun4v_error_entry {
9938 /*0x38*/u64 reserved_5;
9939 };
9940
9941-static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
9942-static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
9943+static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
9944+static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
9945
9946 static const char *sun4v_err_type_to_str(u8 type)
9947 {
9948@@ -1923,7 +1934,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
9949 }
9950
9951 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
9952- int cpu, const char *pfx, atomic_t *ocnt)
9953+ int cpu, const char *pfx, atomic_unchecked_t *ocnt)
9954 {
9955 u64 *raw_ptr = (u64 *) ent;
9956 u32 attrs;
9957@@ -1981,8 +1992,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
9958
9959 show_regs(regs);
9960
9961- if ((cnt = atomic_read(ocnt)) != 0) {
9962- atomic_set(ocnt, 0);
9963+ if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
9964+ atomic_set_unchecked(ocnt, 0);
9965 wmb();
9966 printk("%s: Queue overflowed %d times.\n",
9967 pfx, cnt);
9968@@ -2036,7 +2047,7 @@ void sun4v_resum_error(struct pt_regs *regs, unsigned long offset)
9969 */
9970 void sun4v_resum_overflow(struct pt_regs *regs)
9971 {
9972- atomic_inc(&sun4v_resum_oflow_cnt);
9973+ atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
9974 }
9975
9976 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
9977@@ -2089,7 +2100,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
9978 /* XXX Actually even this can make not that much sense. Perhaps
9979 * XXX we should just pull the plug and panic directly from here?
9980 */
9981- atomic_inc(&sun4v_nonresum_oflow_cnt);
9982+ atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
9983 }
9984
9985 unsigned long sun4v_err_itlb_vaddr;
9986@@ -2104,9 +2115,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
9987
9988 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
9989 regs->tpc, tl);
9990- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
9991+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
9992 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
9993- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
9994+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
9995 (void *) regs->u_regs[UREG_I7]);
9996 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
9997 "pte[%lx] error[%lx]\n",
9998@@ -2128,9 +2139,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
9999
10000 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
10001 regs->tpc, tl);
10002- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
10003+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
10004 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10005- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
10006+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
10007 (void *) regs->u_regs[UREG_I7]);
10008 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
10009 "pte[%lx] error[%lx]\n",
10010@@ -2336,13 +2347,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10011 fp = (unsigned long)sf->fp + STACK_BIAS;
10012 }
10013
10014- printk(" [%016lx] %pS\n", pc, (void *) pc);
10015+ printk(" [%016lx] %pA\n", pc, (void *) pc);
10016 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
10017 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
10018 int index = tsk->curr_ret_stack;
10019 if (tsk->ret_stack && index >= graph) {
10020 pc = tsk->ret_stack[index - graph].ret;
10021- printk(" [%016lx] %pS\n", pc, (void *) pc);
10022+ printk(" [%016lx] %pA\n", pc, (void *) pc);
10023 graph++;
10024 }
10025 }
10026@@ -2360,6 +2371,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
10027 return (struct reg_window *) (fp + STACK_BIAS);
10028 }
10029
10030+extern void gr_handle_kernel_exploit(void);
10031+
10032 void die_if_kernel(char *str, struct pt_regs *regs)
10033 {
10034 static int die_counter;
10035@@ -2388,7 +2401,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10036 while (rw &&
10037 count++ < 30 &&
10038 kstack_valid(tp, (unsigned long) rw)) {
10039- printk("Caller[%016lx]: %pS\n", rw->ins[7],
10040+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
10041 (void *) rw->ins[7]);
10042
10043 rw = kernel_stack_up(rw);
10044@@ -2401,8 +2414,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10045 }
10046 user_instruction_dump ((unsigned int __user *) regs->tpc);
10047 }
10048- if (regs->tstate & TSTATE_PRIV)
10049+ if (regs->tstate & TSTATE_PRIV) {
10050+ gr_handle_kernel_exploit();
10051 do_exit(SIGKILL);
10052+ }
10053 do_exit(SIGSEGV);
10054 }
10055 EXPORT_SYMBOL(die_if_kernel);
10056diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
10057index 8201c25e..072a2a7 100644
10058--- a/arch/sparc/kernel/unaligned_64.c
10059+++ b/arch/sparc/kernel/unaligned_64.c
10060@@ -286,7 +286,7 @@ static void log_unaligned(struct pt_regs *regs)
10061 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
10062
10063 if (__ratelimit(&ratelimit)) {
10064- printk("Kernel unaligned access at TPC[%lx] %pS\n",
10065+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
10066 regs->tpc, (void *) regs->tpc);
10067 }
10068 }
10069diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
10070index dbe119b..089c7c1 100644
10071--- a/arch/sparc/lib/Makefile
10072+++ b/arch/sparc/lib/Makefile
10073@@ -2,7 +2,7 @@
10074 #
10075
10076 asflags-y := -ansi -DST_DIV0=0x02
10077-ccflags-y := -Werror
10078+#ccflags-y := -Werror
10079
10080 lib-$(CONFIG_SPARC32) += ashrdi3.o
10081 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
10082diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
10083index 85c233d..68500e0 100644
10084--- a/arch/sparc/lib/atomic_64.S
10085+++ b/arch/sparc/lib/atomic_64.S
10086@@ -17,7 +17,12 @@
10087 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10088 BACKOFF_SETUP(%o2)
10089 1: lduw [%o1], %g1
10090- add %g1, %o0, %g7
10091+ addcc %g1, %o0, %g7
10092+
10093+#ifdef CONFIG_PAX_REFCOUNT
10094+ tvs %icc, 6
10095+#endif
10096+
10097 cas [%o1], %g1, %g7
10098 cmp %g1, %g7
10099 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10100@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10101 2: BACKOFF_SPIN(%o2, %o3, 1b)
10102 ENDPROC(atomic_add)
10103
10104+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10105+ BACKOFF_SETUP(%o2)
10106+1: lduw [%o1], %g1
10107+ add %g1, %o0, %g7
10108+ cas [%o1], %g1, %g7
10109+ cmp %g1, %g7
10110+ bne,pn %icc, 2f
10111+ nop
10112+ retl
10113+ nop
10114+2: BACKOFF_SPIN(%o2, %o3, 1b)
10115+ENDPROC(atomic_add_unchecked)
10116+
10117 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10118 BACKOFF_SETUP(%o2)
10119 1: lduw [%o1], %g1
10120- sub %g1, %o0, %g7
10121+ subcc %g1, %o0, %g7
10122+
10123+#ifdef CONFIG_PAX_REFCOUNT
10124+ tvs %icc, 6
10125+#endif
10126+
10127 cas [%o1], %g1, %g7
10128 cmp %g1, %g7
10129 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10130@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10131 2: BACKOFF_SPIN(%o2, %o3, 1b)
10132 ENDPROC(atomic_sub)
10133
10134+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10135+ BACKOFF_SETUP(%o2)
10136+1: lduw [%o1], %g1
10137+ sub %g1, %o0, %g7
10138+ cas [%o1], %g1, %g7
10139+ cmp %g1, %g7
10140+ bne,pn %icc, 2f
10141+ nop
10142+ retl
10143+ nop
10144+2: BACKOFF_SPIN(%o2, %o3, 1b)
10145+ENDPROC(atomic_sub_unchecked)
10146+
10147 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10148 BACKOFF_SETUP(%o2)
10149 1: lduw [%o1], %g1
10150- add %g1, %o0, %g7
10151+ addcc %g1, %o0, %g7
10152+
10153+#ifdef CONFIG_PAX_REFCOUNT
10154+ tvs %icc, 6
10155+#endif
10156+
10157 cas [%o1], %g1, %g7
10158 cmp %g1, %g7
10159 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10160@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10161 2: BACKOFF_SPIN(%o2, %o3, 1b)
10162 ENDPROC(atomic_add_ret)
10163
10164+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10165+ BACKOFF_SETUP(%o2)
10166+1: lduw [%o1], %g1
10167+ addcc %g1, %o0, %g7
10168+ cas [%o1], %g1, %g7
10169+ cmp %g1, %g7
10170+ bne,pn %icc, 2f
10171+ add %g7, %o0, %g7
10172+ sra %g7, 0, %o0
10173+ retl
10174+ nop
10175+2: BACKOFF_SPIN(%o2, %o3, 1b)
10176+ENDPROC(atomic_add_ret_unchecked)
10177+
10178 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10179 BACKOFF_SETUP(%o2)
10180 1: lduw [%o1], %g1
10181- sub %g1, %o0, %g7
10182+ subcc %g1, %o0, %g7
10183+
10184+#ifdef CONFIG_PAX_REFCOUNT
10185+ tvs %icc, 6
10186+#endif
10187+
10188 cas [%o1], %g1, %g7
10189 cmp %g1, %g7
10190 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10191@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
10192 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10193 BACKOFF_SETUP(%o2)
10194 1: ldx [%o1], %g1
10195- add %g1, %o0, %g7
10196+ addcc %g1, %o0, %g7
10197+
10198+#ifdef CONFIG_PAX_REFCOUNT
10199+ tvs %xcc, 6
10200+#endif
10201+
10202 casx [%o1], %g1, %g7
10203 cmp %g1, %g7
10204 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10205@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10206 2: BACKOFF_SPIN(%o2, %o3, 1b)
10207 ENDPROC(atomic64_add)
10208
10209+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10210+ BACKOFF_SETUP(%o2)
10211+1: ldx [%o1], %g1
10212+ addcc %g1, %o0, %g7
10213+ casx [%o1], %g1, %g7
10214+ cmp %g1, %g7
10215+ bne,pn %xcc, 2f
10216+ nop
10217+ retl
10218+ nop
10219+2: BACKOFF_SPIN(%o2, %o3, 1b)
10220+ENDPROC(atomic64_add_unchecked)
10221+
10222 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10223 BACKOFF_SETUP(%o2)
10224 1: ldx [%o1], %g1
10225- sub %g1, %o0, %g7
10226+ subcc %g1, %o0, %g7
10227+
10228+#ifdef CONFIG_PAX_REFCOUNT
10229+ tvs %xcc, 6
10230+#endif
10231+
10232 casx [%o1], %g1, %g7
10233 cmp %g1, %g7
10234 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10235@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10236 2: BACKOFF_SPIN(%o2, %o3, 1b)
10237 ENDPROC(atomic64_sub)
10238
10239+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10240+ BACKOFF_SETUP(%o2)
10241+1: ldx [%o1], %g1
10242+ subcc %g1, %o0, %g7
10243+ casx [%o1], %g1, %g7
10244+ cmp %g1, %g7
10245+ bne,pn %xcc, 2f
10246+ nop
10247+ retl
10248+ nop
10249+2: BACKOFF_SPIN(%o2, %o3, 1b)
10250+ENDPROC(atomic64_sub_unchecked)
10251+
10252 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10253 BACKOFF_SETUP(%o2)
10254 1: ldx [%o1], %g1
10255- add %g1, %o0, %g7
10256+ addcc %g1, %o0, %g7
10257+
10258+#ifdef CONFIG_PAX_REFCOUNT
10259+ tvs %xcc, 6
10260+#endif
10261+
10262 casx [%o1], %g1, %g7
10263 cmp %g1, %g7
10264 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10265@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10266 2: BACKOFF_SPIN(%o2, %o3, 1b)
10267 ENDPROC(atomic64_add_ret)
10268
10269+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10270+ BACKOFF_SETUP(%o2)
10271+1: ldx [%o1], %g1
10272+ addcc %g1, %o0, %g7
10273+ casx [%o1], %g1, %g7
10274+ cmp %g1, %g7
10275+ bne,pn %xcc, 2f
10276+ add %g7, %o0, %g7
10277+ mov %g7, %o0
10278+ retl
10279+ nop
10280+2: BACKOFF_SPIN(%o2, %o3, 1b)
10281+ENDPROC(atomic64_add_ret_unchecked)
10282+
10283 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10284 BACKOFF_SETUP(%o2)
10285 1: ldx [%o1], %g1
10286- sub %g1, %o0, %g7
10287+ subcc %g1, %o0, %g7
10288+
10289+#ifdef CONFIG_PAX_REFCOUNT
10290+ tvs %xcc, 6
10291+#endif
10292+
10293 casx [%o1], %g1, %g7
10294 cmp %g1, %g7
10295 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10296diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
10297index 0c4e35e..745d3e4 100644
10298--- a/arch/sparc/lib/ksyms.c
10299+++ b/arch/sparc/lib/ksyms.c
10300@@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
10301
10302 /* Atomic counter implementation. */
10303 EXPORT_SYMBOL(atomic_add);
10304+EXPORT_SYMBOL(atomic_add_unchecked);
10305 EXPORT_SYMBOL(atomic_add_ret);
10306+EXPORT_SYMBOL(atomic_add_ret_unchecked);
10307 EXPORT_SYMBOL(atomic_sub);
10308+EXPORT_SYMBOL(atomic_sub_unchecked);
10309 EXPORT_SYMBOL(atomic_sub_ret);
10310 EXPORT_SYMBOL(atomic64_add);
10311+EXPORT_SYMBOL(atomic64_add_unchecked);
10312 EXPORT_SYMBOL(atomic64_add_ret);
10313+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
10314 EXPORT_SYMBOL(atomic64_sub);
10315+EXPORT_SYMBOL(atomic64_sub_unchecked);
10316 EXPORT_SYMBOL(atomic64_sub_ret);
10317 EXPORT_SYMBOL(atomic64_dec_if_positive);
10318
10319diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
10320index 30c3ecc..736f015 100644
10321--- a/arch/sparc/mm/Makefile
10322+++ b/arch/sparc/mm/Makefile
10323@@ -2,7 +2,7 @@
10324 #
10325
10326 asflags-y := -ansi
10327-ccflags-y := -Werror
10328+#ccflags-y := -Werror
10329
10330 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
10331 obj-y += fault_$(BITS).o
10332diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
10333index e98bfda..ea8d221 100644
10334--- a/arch/sparc/mm/fault_32.c
10335+++ b/arch/sparc/mm/fault_32.c
10336@@ -21,6 +21,9 @@
10337 #include <linux/perf_event.h>
10338 #include <linux/interrupt.h>
10339 #include <linux/kdebug.h>
10340+#include <linux/slab.h>
10341+#include <linux/pagemap.h>
10342+#include <linux/compiler.h>
10343
10344 #include <asm/page.h>
10345 #include <asm/pgtable.h>
10346@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
10347 return safe_compute_effective_address(regs, insn);
10348 }
10349
10350+#ifdef CONFIG_PAX_PAGEEXEC
10351+#ifdef CONFIG_PAX_DLRESOLVE
10352+static void pax_emuplt_close(struct vm_area_struct *vma)
10353+{
10354+ vma->vm_mm->call_dl_resolve = 0UL;
10355+}
10356+
10357+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
10358+{
10359+ unsigned int *kaddr;
10360+
10361+ vmf->page = alloc_page(GFP_HIGHUSER);
10362+ if (!vmf->page)
10363+ return VM_FAULT_OOM;
10364+
10365+ kaddr = kmap(vmf->page);
10366+ memset(kaddr, 0, PAGE_SIZE);
10367+ kaddr[0] = 0x9DE3BFA8U; /* save */
10368+ flush_dcache_page(vmf->page);
10369+ kunmap(vmf->page);
10370+ return VM_FAULT_MAJOR;
10371+}
10372+
10373+static const struct vm_operations_struct pax_vm_ops = {
10374+ .close = pax_emuplt_close,
10375+ .fault = pax_emuplt_fault
10376+};
10377+
10378+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
10379+{
10380+ int ret;
10381+
10382+ INIT_LIST_HEAD(&vma->anon_vma_chain);
10383+ vma->vm_mm = current->mm;
10384+ vma->vm_start = addr;
10385+ vma->vm_end = addr + PAGE_SIZE;
10386+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
10387+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
10388+ vma->vm_ops = &pax_vm_ops;
10389+
10390+ ret = insert_vm_struct(current->mm, vma);
10391+ if (ret)
10392+ return ret;
10393+
10394+ ++current->mm->total_vm;
10395+ return 0;
10396+}
10397+#endif
10398+
10399+/*
10400+ * PaX: decide what to do with offenders (regs->pc = fault address)
10401+ *
10402+ * returns 1 when task should be killed
10403+ * 2 when patched PLT trampoline was detected
10404+ * 3 when unpatched PLT trampoline was detected
10405+ */
10406+static int pax_handle_fetch_fault(struct pt_regs *regs)
10407+{
10408+
10409+#ifdef CONFIG_PAX_EMUPLT
10410+ int err;
10411+
10412+ do { /* PaX: patched PLT emulation #1 */
10413+ unsigned int sethi1, sethi2, jmpl;
10414+
10415+ err = get_user(sethi1, (unsigned int *)regs->pc);
10416+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
10417+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
10418+
10419+ if (err)
10420+ break;
10421+
10422+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
10423+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
10424+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
10425+ {
10426+ unsigned int addr;
10427+
10428+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
10429+ addr = regs->u_regs[UREG_G1];
10430+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10431+ regs->pc = addr;
10432+ regs->npc = addr+4;
10433+ return 2;
10434+ }
10435+ } while (0);
10436+
10437+ do { /* PaX: patched PLT emulation #2 */
10438+ unsigned int ba;
10439+
10440+ err = get_user(ba, (unsigned int *)regs->pc);
10441+
10442+ if (err)
10443+ break;
10444+
10445+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
10446+ unsigned int addr;
10447+
10448+ if ((ba & 0xFFC00000U) == 0x30800000U)
10449+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
10450+ else
10451+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10452+ regs->pc = addr;
10453+ regs->npc = addr+4;
10454+ return 2;
10455+ }
10456+ } while (0);
10457+
10458+ do { /* PaX: patched PLT emulation #3 */
10459+ unsigned int sethi, bajmpl, nop;
10460+
10461+ err = get_user(sethi, (unsigned int *)regs->pc);
10462+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
10463+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
10464+
10465+ if (err)
10466+ break;
10467+
10468+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10469+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
10470+ nop == 0x01000000U)
10471+ {
10472+ unsigned int addr;
10473+
10474+ addr = (sethi & 0x003FFFFFU) << 10;
10475+ regs->u_regs[UREG_G1] = addr;
10476+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
10477+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10478+ else
10479+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10480+ regs->pc = addr;
10481+ regs->npc = addr+4;
10482+ return 2;
10483+ }
10484+ } while (0);
10485+
10486+ do { /* PaX: unpatched PLT emulation step 1 */
10487+ unsigned int sethi, ba, nop;
10488+
10489+ err = get_user(sethi, (unsigned int *)regs->pc);
10490+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
10491+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
10492+
10493+ if (err)
10494+ break;
10495+
10496+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10497+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
10498+ nop == 0x01000000U)
10499+ {
10500+ unsigned int addr, save, call;
10501+
10502+ if ((ba & 0xFFC00000U) == 0x30800000U)
10503+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
10504+ else
10505+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10506+
10507+ err = get_user(save, (unsigned int *)addr);
10508+ err |= get_user(call, (unsigned int *)(addr+4));
10509+ err |= get_user(nop, (unsigned int *)(addr+8));
10510+ if (err)
10511+ break;
10512+
10513+#ifdef CONFIG_PAX_DLRESOLVE
10514+ if (save == 0x9DE3BFA8U &&
10515+ (call & 0xC0000000U) == 0x40000000U &&
10516+ nop == 0x01000000U)
10517+ {
10518+ struct vm_area_struct *vma;
10519+ unsigned long call_dl_resolve;
10520+
10521+ down_read(&current->mm->mmap_sem);
10522+ call_dl_resolve = current->mm->call_dl_resolve;
10523+ up_read(&current->mm->mmap_sem);
10524+ if (likely(call_dl_resolve))
10525+ goto emulate;
10526+
10527+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
10528+
10529+ down_write(&current->mm->mmap_sem);
10530+ if (current->mm->call_dl_resolve) {
10531+ call_dl_resolve = current->mm->call_dl_resolve;
10532+ up_write(&current->mm->mmap_sem);
10533+ if (vma)
10534+ kmem_cache_free(vm_area_cachep, vma);
10535+ goto emulate;
10536+ }
10537+
10538+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
10539+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
10540+ up_write(&current->mm->mmap_sem);
10541+ if (vma)
10542+ kmem_cache_free(vm_area_cachep, vma);
10543+ return 1;
10544+ }
10545+
10546+ if (pax_insert_vma(vma, call_dl_resolve)) {
10547+ up_write(&current->mm->mmap_sem);
10548+ kmem_cache_free(vm_area_cachep, vma);
10549+ return 1;
10550+ }
10551+
10552+ current->mm->call_dl_resolve = call_dl_resolve;
10553+ up_write(&current->mm->mmap_sem);
10554+
10555+emulate:
10556+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
10557+ regs->pc = call_dl_resolve;
10558+ regs->npc = addr+4;
10559+ return 3;
10560+ }
10561+#endif
10562+
10563+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
10564+ if ((save & 0xFFC00000U) == 0x05000000U &&
10565+ (call & 0xFFFFE000U) == 0x85C0A000U &&
10566+ nop == 0x01000000U)
10567+ {
10568+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
10569+ regs->u_regs[UREG_G2] = addr + 4;
10570+ addr = (save & 0x003FFFFFU) << 10;
10571+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10572+ regs->pc = addr;
10573+ regs->npc = addr+4;
10574+ return 3;
10575+ }
10576+ }
10577+ } while (0);
10578+
10579+ do { /* PaX: unpatched PLT emulation step 2 */
10580+ unsigned int save, call, nop;
10581+
10582+ err = get_user(save, (unsigned int *)(regs->pc-4));
10583+ err |= get_user(call, (unsigned int *)regs->pc);
10584+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
10585+ if (err)
10586+ break;
10587+
10588+ if (save == 0x9DE3BFA8U &&
10589+ (call & 0xC0000000U) == 0x40000000U &&
10590+ nop == 0x01000000U)
10591+ {
10592+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
10593+
10594+ regs->u_regs[UREG_RETPC] = regs->pc;
10595+ regs->pc = dl_resolve;
10596+ regs->npc = dl_resolve+4;
10597+ return 3;
10598+ }
10599+ } while (0);
10600+#endif
10601+
10602+ return 1;
10603+}
10604+
10605+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
10606+{
10607+ unsigned long i;
10608+
10609+ printk(KERN_ERR "PAX: bytes at PC: ");
10610+ for (i = 0; i < 8; i++) {
10611+ unsigned int c;
10612+ if (get_user(c, (unsigned int *)pc+i))
10613+ printk(KERN_CONT "???????? ");
10614+ else
10615+ printk(KERN_CONT "%08x ", c);
10616+ }
10617+ printk("\n");
10618+}
10619+#endif
10620+
10621 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
10622 int text_fault)
10623 {
10624@@ -230,6 +504,24 @@ good_area:
10625 if (!(vma->vm_flags & VM_WRITE))
10626 goto bad_area;
10627 } else {
10628+
10629+#ifdef CONFIG_PAX_PAGEEXEC
10630+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
10631+ up_read(&mm->mmap_sem);
10632+ switch (pax_handle_fetch_fault(regs)) {
10633+
10634+#ifdef CONFIG_PAX_EMUPLT
10635+ case 2:
10636+ case 3:
10637+ return;
10638+#endif
10639+
10640+ }
10641+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
10642+ do_group_exit(SIGKILL);
10643+ }
10644+#endif
10645+
10646 /* Allow reads even for write-only mappings */
10647 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
10648 goto bad_area;
10649diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
10650index 5062ff3..e0b75f3 100644
10651--- a/arch/sparc/mm/fault_64.c
10652+++ b/arch/sparc/mm/fault_64.c
10653@@ -21,6 +21,9 @@
10654 #include <linux/kprobes.h>
10655 #include <linux/kdebug.h>
10656 #include <linux/percpu.h>
10657+#include <linux/slab.h>
10658+#include <linux/pagemap.h>
10659+#include <linux/compiler.h>
10660
10661 #include <asm/page.h>
10662 #include <asm/pgtable.h>
10663@@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
10664 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
10665 regs->tpc);
10666 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
10667- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
10668+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
10669 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
10670 dump_stack();
10671 unhandled_fault(regs->tpc, current, regs);
10672@@ -270,6 +273,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
10673 show_regs(regs);
10674 }
10675
10676+#ifdef CONFIG_PAX_PAGEEXEC
10677+#ifdef CONFIG_PAX_DLRESOLVE
10678+static void pax_emuplt_close(struct vm_area_struct *vma)
10679+{
10680+ vma->vm_mm->call_dl_resolve = 0UL;
10681+}
10682+
10683+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
10684+{
10685+ unsigned int *kaddr;
10686+
10687+ vmf->page = alloc_page(GFP_HIGHUSER);
10688+ if (!vmf->page)
10689+ return VM_FAULT_OOM;
10690+
10691+ kaddr = kmap(vmf->page);
10692+ memset(kaddr, 0, PAGE_SIZE);
10693+ kaddr[0] = 0x9DE3BFA8U; /* save */
10694+ flush_dcache_page(vmf->page);
10695+ kunmap(vmf->page);
10696+ return VM_FAULT_MAJOR;
10697+}
10698+
10699+static const struct vm_operations_struct pax_vm_ops = {
10700+ .close = pax_emuplt_close,
10701+ .fault = pax_emuplt_fault
10702+};
10703+
10704+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
10705+{
10706+ int ret;
10707+
10708+ INIT_LIST_HEAD(&vma->anon_vma_chain);
10709+ vma->vm_mm = current->mm;
10710+ vma->vm_start = addr;
10711+ vma->vm_end = addr + PAGE_SIZE;
10712+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
10713+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
10714+ vma->vm_ops = &pax_vm_ops;
10715+
10716+ ret = insert_vm_struct(current->mm, vma);
10717+ if (ret)
10718+ return ret;
10719+
10720+ ++current->mm->total_vm;
10721+ return 0;
10722+}
10723+#endif
10724+
10725+/*
10726+ * PaX: decide what to do with offenders (regs->tpc = fault address)
10727+ *
10728+ * returns 1 when task should be killed
10729+ * 2 when patched PLT trampoline was detected
10730+ * 3 when unpatched PLT trampoline was detected
10731+ */
10732+static int pax_handle_fetch_fault(struct pt_regs *regs)
10733+{
10734+
10735+#ifdef CONFIG_PAX_EMUPLT
10736+ int err;
10737+
10738+ do { /* PaX: patched PLT emulation #1 */
10739+ unsigned int sethi1, sethi2, jmpl;
10740+
10741+ err = get_user(sethi1, (unsigned int *)regs->tpc);
10742+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
10743+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
10744+
10745+ if (err)
10746+ break;
10747+
10748+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
10749+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
10750+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
10751+ {
10752+ unsigned long addr;
10753+
10754+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
10755+ addr = regs->u_regs[UREG_G1];
10756+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
10757+
10758+ if (test_thread_flag(TIF_32BIT))
10759+ addr &= 0xFFFFFFFFUL;
10760+
10761+ regs->tpc = addr;
10762+ regs->tnpc = addr+4;
10763+ return 2;
10764+ }
10765+ } while (0);
10766+
10767+ do { /* PaX: patched PLT emulation #2 */
10768+ unsigned int ba;
10769+
10770+ err = get_user(ba, (unsigned int *)regs->tpc);
10771+
10772+ if (err)
10773+ break;
10774+
10775+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
10776+ unsigned long addr;
10777+
10778+ if ((ba & 0xFFC00000U) == 0x30800000U)
10779+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
10780+ else
10781+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
10782+
10783+ if (test_thread_flag(TIF_32BIT))
10784+ addr &= 0xFFFFFFFFUL;
10785+
10786+ regs->tpc = addr;
10787+ regs->tnpc = addr+4;
10788+ return 2;
10789+ }
10790+ } while (0);
10791+
10792+ do { /* PaX: patched PLT emulation #3 */
10793+ unsigned int sethi, bajmpl, nop;
10794+
10795+ err = get_user(sethi, (unsigned int *)regs->tpc);
10796+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
10797+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
10798+
10799+ if (err)
10800+ break;
10801+
10802+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10803+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
10804+ nop == 0x01000000U)
10805+ {
10806+ unsigned long addr;
10807+
10808+ addr = (sethi & 0x003FFFFFU) << 10;
10809+ regs->u_regs[UREG_G1] = addr;
10810+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
10811+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
10812+ else
10813+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
10814+
10815+ if (test_thread_flag(TIF_32BIT))
10816+ addr &= 0xFFFFFFFFUL;
10817+
10818+ regs->tpc = addr;
10819+ regs->tnpc = addr+4;
10820+ return 2;
10821+ }
10822+ } while (0);
10823+
10824+ do { /* PaX: patched PLT emulation #4 */
10825+ unsigned int sethi, mov1, call, mov2;
10826+
10827+ err = get_user(sethi, (unsigned int *)regs->tpc);
10828+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
10829+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
10830+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
10831+
10832+ if (err)
10833+ break;
10834+
10835+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10836+ mov1 == 0x8210000FU &&
10837+ (call & 0xC0000000U) == 0x40000000U &&
10838+ mov2 == 0x9E100001U)
10839+ {
10840+ unsigned long addr;
10841+
10842+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
10843+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
10844+
10845+ if (test_thread_flag(TIF_32BIT))
10846+ addr &= 0xFFFFFFFFUL;
10847+
10848+ regs->tpc = addr;
10849+ regs->tnpc = addr+4;
10850+ return 2;
10851+ }
10852+ } while (0);
10853+
10854+ do { /* PaX: patched PLT emulation #5 */
10855+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
10856+
10857+ err = get_user(sethi, (unsigned int *)regs->tpc);
10858+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
10859+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
10860+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
10861+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
10862+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
10863+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
10864+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
10865+
10866+ if (err)
10867+ break;
10868+
10869+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10870+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
10871+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
10872+ (or1 & 0xFFFFE000U) == 0x82106000U &&
10873+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
10874+ sllx == 0x83287020U &&
10875+ jmpl == 0x81C04005U &&
10876+ nop == 0x01000000U)
10877+ {
10878+ unsigned long addr;
10879+
10880+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
10881+ regs->u_regs[UREG_G1] <<= 32;
10882+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
10883+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
10884+ regs->tpc = addr;
10885+ regs->tnpc = addr+4;
10886+ return 2;
10887+ }
10888+ } while (0);
10889+
10890+ do { /* PaX: patched PLT emulation #6 */
10891+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
10892+
10893+ err = get_user(sethi, (unsigned int *)regs->tpc);
10894+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
10895+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
10896+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
10897+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
10898+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
10899+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
10900+
10901+ if (err)
10902+ break;
10903+
10904+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10905+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
10906+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
10907+ sllx == 0x83287020U &&
10908+ (or & 0xFFFFE000U) == 0x8A116000U &&
10909+ jmpl == 0x81C04005U &&
10910+ nop == 0x01000000U)
10911+ {
10912+ unsigned long addr;
10913+
10914+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
10915+ regs->u_regs[UREG_G1] <<= 32;
10916+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
10917+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
10918+ regs->tpc = addr;
10919+ regs->tnpc = addr+4;
10920+ return 2;
10921+ }
10922+ } while (0);
10923+
10924+ do { /* PaX: unpatched PLT emulation step 1 */
10925+ unsigned int sethi, ba, nop;
10926+
10927+ err = get_user(sethi, (unsigned int *)regs->tpc);
10928+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
10929+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
10930+
10931+ if (err)
10932+ break;
10933+
10934+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
10935+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
10936+ nop == 0x01000000U)
10937+ {
10938+ unsigned long addr;
10939+ unsigned int save, call;
10940+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
10941+
10942+ if ((ba & 0xFFC00000U) == 0x30800000U)
10943+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
10944+ else
10945+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
10946+
10947+ if (test_thread_flag(TIF_32BIT))
10948+ addr &= 0xFFFFFFFFUL;
10949+
10950+ err = get_user(save, (unsigned int *)addr);
10951+ err |= get_user(call, (unsigned int *)(addr+4));
10952+ err |= get_user(nop, (unsigned int *)(addr+8));
10953+ if (err)
10954+ break;
10955+
10956+#ifdef CONFIG_PAX_DLRESOLVE
10957+ if (save == 0x9DE3BFA8U &&
10958+ (call & 0xC0000000U) == 0x40000000U &&
10959+ nop == 0x01000000U)
10960+ {
10961+ struct vm_area_struct *vma;
10962+ unsigned long call_dl_resolve;
10963+
10964+ down_read(&current->mm->mmap_sem);
10965+ call_dl_resolve = current->mm->call_dl_resolve;
10966+ up_read(&current->mm->mmap_sem);
10967+ if (likely(call_dl_resolve))
10968+ goto emulate;
10969+
10970+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
10971+
10972+ down_write(&current->mm->mmap_sem);
10973+ if (current->mm->call_dl_resolve) {
10974+ call_dl_resolve = current->mm->call_dl_resolve;
10975+ up_write(&current->mm->mmap_sem);
10976+ if (vma)
10977+ kmem_cache_free(vm_area_cachep, vma);
10978+ goto emulate;
10979+ }
10980+
10981+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
10982+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
10983+ up_write(&current->mm->mmap_sem);
10984+ if (vma)
10985+ kmem_cache_free(vm_area_cachep, vma);
10986+ return 1;
10987+ }
10988+
10989+ if (pax_insert_vma(vma, call_dl_resolve)) {
10990+ up_write(&current->mm->mmap_sem);
10991+ kmem_cache_free(vm_area_cachep, vma);
10992+ return 1;
10993+ }
10994+
10995+ current->mm->call_dl_resolve = call_dl_resolve;
10996+ up_write(&current->mm->mmap_sem);
10997+
10998+emulate:
10999+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11000+ regs->tpc = call_dl_resolve;
11001+ regs->tnpc = addr+4;
11002+ return 3;
11003+ }
11004+#endif
11005+
11006+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11007+ if ((save & 0xFFC00000U) == 0x05000000U &&
11008+ (call & 0xFFFFE000U) == 0x85C0A000U &&
11009+ nop == 0x01000000U)
11010+ {
11011+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11012+ regs->u_regs[UREG_G2] = addr + 4;
11013+ addr = (save & 0x003FFFFFU) << 10;
11014+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11015+
11016+ if (test_thread_flag(TIF_32BIT))
11017+ addr &= 0xFFFFFFFFUL;
11018+
11019+ regs->tpc = addr;
11020+ regs->tnpc = addr+4;
11021+ return 3;
11022+ }
11023+
11024+ /* PaX: 64-bit PLT stub */
11025+ err = get_user(sethi1, (unsigned int *)addr);
11026+ err |= get_user(sethi2, (unsigned int *)(addr+4));
11027+ err |= get_user(or1, (unsigned int *)(addr+8));
11028+ err |= get_user(or2, (unsigned int *)(addr+12));
11029+ err |= get_user(sllx, (unsigned int *)(addr+16));
11030+ err |= get_user(add, (unsigned int *)(addr+20));
11031+ err |= get_user(jmpl, (unsigned int *)(addr+24));
11032+ err |= get_user(nop, (unsigned int *)(addr+28));
11033+ if (err)
11034+ break;
11035+
11036+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
11037+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11038+ (or1 & 0xFFFFE000U) == 0x88112000U &&
11039+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
11040+ sllx == 0x89293020U &&
11041+ add == 0x8A010005U &&
11042+ jmpl == 0x89C14000U &&
11043+ nop == 0x01000000U)
11044+ {
11045+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11046+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11047+ regs->u_regs[UREG_G4] <<= 32;
11048+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11049+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
11050+ regs->u_regs[UREG_G4] = addr + 24;
11051+ addr = regs->u_regs[UREG_G5];
11052+ regs->tpc = addr;
11053+ regs->tnpc = addr+4;
11054+ return 3;
11055+ }
11056+ }
11057+ } while (0);
11058+
11059+#ifdef CONFIG_PAX_DLRESOLVE
11060+ do { /* PaX: unpatched PLT emulation step 2 */
11061+ unsigned int save, call, nop;
11062+
11063+ err = get_user(save, (unsigned int *)(regs->tpc-4));
11064+ err |= get_user(call, (unsigned int *)regs->tpc);
11065+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
11066+ if (err)
11067+ break;
11068+
11069+ if (save == 0x9DE3BFA8U &&
11070+ (call & 0xC0000000U) == 0x40000000U &&
11071+ nop == 0x01000000U)
11072+ {
11073+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11074+
11075+ if (test_thread_flag(TIF_32BIT))
11076+ dl_resolve &= 0xFFFFFFFFUL;
11077+
11078+ regs->u_regs[UREG_RETPC] = regs->tpc;
11079+ regs->tpc = dl_resolve;
11080+ regs->tnpc = dl_resolve+4;
11081+ return 3;
11082+ }
11083+ } while (0);
11084+#endif
11085+
11086+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
11087+ unsigned int sethi, ba, nop;
11088+
11089+ err = get_user(sethi, (unsigned int *)regs->tpc);
11090+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11091+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11092+
11093+ if (err)
11094+ break;
11095+
11096+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11097+ (ba & 0xFFF00000U) == 0x30600000U &&
11098+ nop == 0x01000000U)
11099+ {
11100+ unsigned long addr;
11101+
11102+ addr = (sethi & 0x003FFFFFU) << 10;
11103+ regs->u_regs[UREG_G1] = addr;
11104+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11105+
11106+ if (test_thread_flag(TIF_32BIT))
11107+ addr &= 0xFFFFFFFFUL;
11108+
11109+ regs->tpc = addr;
11110+ regs->tnpc = addr+4;
11111+ return 2;
11112+ }
11113+ } while (0);
11114+
11115+#endif
11116+
11117+ return 1;
11118+}
11119+
11120+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11121+{
11122+ unsigned long i;
11123+
11124+ printk(KERN_ERR "PAX: bytes at PC: ");
11125+ for (i = 0; i < 8; i++) {
11126+ unsigned int c;
11127+ if (get_user(c, (unsigned int *)pc+i))
11128+ printk(KERN_CONT "???????? ");
11129+ else
11130+ printk(KERN_CONT "%08x ", c);
11131+ }
11132+ printk("\n");
11133+}
11134+#endif
11135+
11136 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
11137 {
11138 struct mm_struct *mm = current->mm;
11139@@ -341,6 +804,29 @@ retry:
11140 if (!vma)
11141 goto bad_area;
11142
11143+#ifdef CONFIG_PAX_PAGEEXEC
11144+ /* PaX: detect ITLB misses on non-exec pages */
11145+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
11146+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
11147+ {
11148+ if (address != regs->tpc)
11149+ goto good_area;
11150+
11151+ up_read(&mm->mmap_sem);
11152+ switch (pax_handle_fetch_fault(regs)) {
11153+
11154+#ifdef CONFIG_PAX_EMUPLT
11155+ case 2:
11156+ case 3:
11157+ return;
11158+#endif
11159+
11160+ }
11161+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
11162+ do_group_exit(SIGKILL);
11163+ }
11164+#endif
11165+
11166 /* Pure DTLB misses do not tell us whether the fault causing
11167 * load/store/atomic was a write or not, it only says that there
11168 * was no match. So in such a case we (carefully) read the
11169diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
11170index d2b5944..d878f3c 100644
11171--- a/arch/sparc/mm/hugetlbpage.c
11172+++ b/arch/sparc/mm/hugetlbpage.c
11173@@ -28,7 +28,8 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11174 unsigned long addr,
11175 unsigned long len,
11176 unsigned long pgoff,
11177- unsigned long flags)
11178+ unsigned long flags,
11179+ unsigned long offset)
11180 {
11181 unsigned long task_size = TASK_SIZE;
11182 struct vm_unmapped_area_info info;
11183@@ -38,15 +39,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11184
11185 info.flags = 0;
11186 info.length = len;
11187- info.low_limit = TASK_UNMAPPED_BASE;
11188+ info.low_limit = mm->mmap_base;
11189 info.high_limit = min(task_size, VA_EXCLUDE_START);
11190 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11191 info.align_offset = 0;
11192+ info.threadstack_offset = offset;
11193 addr = vm_unmapped_area(&info);
11194
11195 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
11196 VM_BUG_ON(addr != -ENOMEM);
11197 info.low_limit = VA_EXCLUDE_END;
11198+
11199+#ifdef CONFIG_PAX_RANDMMAP
11200+ if (mm->pax_flags & MF_PAX_RANDMMAP)
11201+ info.low_limit += mm->delta_mmap;
11202+#endif
11203+
11204 info.high_limit = task_size;
11205 addr = vm_unmapped_area(&info);
11206 }
11207@@ -58,7 +66,8 @@ static unsigned long
11208 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11209 const unsigned long len,
11210 const unsigned long pgoff,
11211- const unsigned long flags)
11212+ const unsigned long flags,
11213+ const unsigned long offset)
11214 {
11215 struct mm_struct *mm = current->mm;
11216 unsigned long addr = addr0;
11217@@ -73,6 +82,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11218 info.high_limit = mm->mmap_base;
11219 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11220 info.align_offset = 0;
11221+ info.threadstack_offset = offset;
11222 addr = vm_unmapped_area(&info);
11223
11224 /*
11225@@ -85,6 +95,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11226 VM_BUG_ON(addr != -ENOMEM);
11227 info.flags = 0;
11228 info.low_limit = TASK_UNMAPPED_BASE;
11229+
11230+#ifdef CONFIG_PAX_RANDMMAP
11231+ if (mm->pax_flags & MF_PAX_RANDMMAP)
11232+ info.low_limit += mm->delta_mmap;
11233+#endif
11234+
11235 info.high_limit = STACK_TOP32;
11236 addr = vm_unmapped_area(&info);
11237 }
11238@@ -99,6 +115,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11239 struct mm_struct *mm = current->mm;
11240 struct vm_area_struct *vma;
11241 unsigned long task_size = TASK_SIZE;
11242+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
11243
11244 if (test_thread_flag(TIF_32BIT))
11245 task_size = STACK_TOP32;
11246@@ -114,19 +131,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11247 return addr;
11248 }
11249
11250+#ifdef CONFIG_PAX_RANDMMAP
11251+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
11252+#endif
11253+
11254 if (addr) {
11255 addr = ALIGN(addr, HPAGE_SIZE);
11256 vma = find_vma(mm, addr);
11257- if (task_size - len >= addr &&
11258- (!vma || addr + len <= vma->vm_start))
11259+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
11260 return addr;
11261 }
11262 if (mm->get_unmapped_area == arch_get_unmapped_area)
11263 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
11264- pgoff, flags);
11265+ pgoff, flags, offset);
11266 else
11267 return hugetlb_get_unmapped_area_topdown(file, addr, len,
11268- pgoff, flags);
11269+ pgoff, flags, offset);
11270 }
11271
11272 pte_t *huge_pte_alloc(struct mm_struct *mm,
11273diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
11274index ed82eda..0d80e77 100644
11275--- a/arch/sparc/mm/init_64.c
11276+++ b/arch/sparc/mm/init_64.c
11277@@ -188,9 +188,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
11278 int num_kernel_image_mappings;
11279
11280 #ifdef CONFIG_DEBUG_DCFLUSH
11281-atomic_t dcpage_flushes = ATOMIC_INIT(0);
11282+atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
11283 #ifdef CONFIG_SMP
11284-atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11285+atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11286 #endif
11287 #endif
11288
11289@@ -198,7 +198,7 @@ inline void flush_dcache_page_impl(struct page *page)
11290 {
11291 BUG_ON(tlb_type == hypervisor);
11292 #ifdef CONFIG_DEBUG_DCFLUSH
11293- atomic_inc(&dcpage_flushes);
11294+ atomic_inc_unchecked(&dcpage_flushes);
11295 #endif
11296
11297 #ifdef DCACHE_ALIASING_POSSIBLE
11298@@ -466,10 +466,10 @@ void mmu_info(struct seq_file *m)
11299
11300 #ifdef CONFIG_DEBUG_DCFLUSH
11301 seq_printf(m, "DCPageFlushes\t: %d\n",
11302- atomic_read(&dcpage_flushes));
11303+ atomic_read_unchecked(&dcpage_flushes));
11304 #ifdef CONFIG_SMP
11305 seq_printf(m, "DCPageFlushesXC\t: %d\n",
11306- atomic_read(&dcpage_flushes_xcall));
11307+ atomic_read_unchecked(&dcpage_flushes_xcall));
11308 #endif /* CONFIG_SMP */
11309 #endif /* CONFIG_DEBUG_DCFLUSH */
11310 }
11311diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
11312index f4500c6..889656c 100644
11313--- a/arch/tile/include/asm/atomic_64.h
11314+++ b/arch/tile/include/asm/atomic_64.h
11315@@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
11316
11317 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
11318
11319+#define atomic64_read_unchecked(v) atomic64_read(v)
11320+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
11321+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
11322+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
11323+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
11324+#define atomic64_inc_unchecked(v) atomic64_inc(v)
11325+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
11326+#define atomic64_dec_unchecked(v) atomic64_dec(v)
11327+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
11328+
11329 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
11330 #define smp_mb__before_atomic_dec() smp_mb()
11331 #define smp_mb__after_atomic_dec() smp_mb()
11332diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
11333index a9a5299..0fce79e 100644
11334--- a/arch/tile/include/asm/cache.h
11335+++ b/arch/tile/include/asm/cache.h
11336@@ -15,11 +15,12 @@
11337 #ifndef _ASM_TILE_CACHE_H
11338 #define _ASM_TILE_CACHE_H
11339
11340+#include <linux/const.h>
11341 #include <arch/chip.h>
11342
11343 /* bytes per L1 data cache line */
11344 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
11345-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11346+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11347
11348 /* bytes per L2 cache line */
11349 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
11350diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
11351index e4d44bd..99927a3 100644
11352--- a/arch/tile/include/asm/uaccess.h
11353+++ b/arch/tile/include/asm/uaccess.h
11354@@ -408,9 +408,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
11355 const void __user *from,
11356 unsigned long n)
11357 {
11358- int sz = __compiletime_object_size(to);
11359+ size_t sz = __compiletime_object_size(to);
11360
11361- if (likely(sz == -1 || sz >= n))
11362+ if (likely(sz == (size_t)-1 || sz >= n))
11363 n = _copy_from_user(to, from, n);
11364 else
11365 copy_from_user_overflow();
11366diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
11367index 650ccff..45fe2d6 100644
11368--- a/arch/tile/mm/hugetlbpage.c
11369+++ b/arch/tile/mm/hugetlbpage.c
11370@@ -239,6 +239,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
11371 info.high_limit = TASK_SIZE;
11372 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
11373 info.align_offset = 0;
11374+ info.threadstack_offset = 0;
11375 return vm_unmapped_area(&info);
11376 }
11377
11378@@ -256,6 +257,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
11379 info.high_limit = current->mm->mmap_base;
11380 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
11381 info.align_offset = 0;
11382+ info.threadstack_offset = 0;
11383 addr = vm_unmapped_area(&info);
11384
11385 /*
11386diff --git a/arch/um/Makefile b/arch/um/Makefile
11387index 133f7de..1d6f2f1 100644
11388--- a/arch/um/Makefile
11389+++ b/arch/um/Makefile
11390@@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
11391 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
11392 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
11393
11394+ifdef CONSTIFY_PLUGIN
11395+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11396+endif
11397+
11398 #This will adjust *FLAGS accordingly to the platform.
11399 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
11400
11401diff --git a/arch/um/defconfig b/arch/um/defconfig
11402index 08107a7..ab22afe 100644
11403--- a/arch/um/defconfig
11404+++ b/arch/um/defconfig
11405@@ -51,7 +51,6 @@ CONFIG_X86_CMPXCHG=y
11406 CONFIG_X86_L1_CACHE_SHIFT=5
11407 CONFIG_X86_XADD=y
11408 CONFIG_X86_PPRO_FENCE=y
11409-CONFIG_X86_WP_WORKS_OK=y
11410 CONFIG_X86_INVLPG=y
11411 CONFIG_X86_BSWAP=y
11412 CONFIG_X86_POPAD_OK=y
11413diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
11414index 19e1bdd..3665b77 100644
11415--- a/arch/um/include/asm/cache.h
11416+++ b/arch/um/include/asm/cache.h
11417@@ -1,6 +1,7 @@
11418 #ifndef __UM_CACHE_H
11419 #define __UM_CACHE_H
11420
11421+#include <linux/const.h>
11422
11423 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
11424 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
11425@@ -12,6 +13,6 @@
11426 # define L1_CACHE_SHIFT 5
11427 #endif
11428
11429-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11430+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11431
11432 #endif
11433diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
11434index 2e0a6b1..a64d0f5 100644
11435--- a/arch/um/include/asm/kmap_types.h
11436+++ b/arch/um/include/asm/kmap_types.h
11437@@ -8,6 +8,6 @@
11438
11439 /* No more #include "asm/arch/kmap_types.h" ! */
11440
11441-#define KM_TYPE_NR 14
11442+#define KM_TYPE_NR 15
11443
11444 #endif
11445diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
11446index 5ff53d9..5850cdf 100644
11447--- a/arch/um/include/asm/page.h
11448+++ b/arch/um/include/asm/page.h
11449@@ -14,6 +14,9 @@
11450 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
11451 #define PAGE_MASK (~(PAGE_SIZE-1))
11452
11453+#define ktla_ktva(addr) (addr)
11454+#define ktva_ktla(addr) (addr)
11455+
11456 #ifndef __ASSEMBLY__
11457
11458 struct page;
11459diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
11460index 0032f92..cd151e0 100644
11461--- a/arch/um/include/asm/pgtable-3level.h
11462+++ b/arch/um/include/asm/pgtable-3level.h
11463@@ -58,6 +58,7 @@
11464 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
11465 #define pud_populate(mm, pud, pmd) \
11466 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
11467+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
11468
11469 #ifdef CONFIG_64BIT
11470 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
11471diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
11472index bbcef52..6a2a483 100644
11473--- a/arch/um/kernel/process.c
11474+++ b/arch/um/kernel/process.c
11475@@ -367,22 +367,6 @@ int singlestepping(void * t)
11476 return 2;
11477 }
11478
11479-/*
11480- * Only x86 and x86_64 have an arch_align_stack().
11481- * All other arches have "#define arch_align_stack(x) (x)"
11482- * in their asm/system.h
11483- * As this is included in UML from asm-um/system-generic.h,
11484- * we can use it to behave as the subarch does.
11485- */
11486-#ifndef arch_align_stack
11487-unsigned long arch_align_stack(unsigned long sp)
11488-{
11489- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
11490- sp -= get_random_int() % 8192;
11491- return sp & ~0xf;
11492-}
11493-#endif
11494-
11495 unsigned long get_wchan(struct task_struct *p)
11496 {
11497 unsigned long stack_page, sp, ip;
11498diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
11499index ad8f795..2c7eec6 100644
11500--- a/arch/unicore32/include/asm/cache.h
11501+++ b/arch/unicore32/include/asm/cache.h
11502@@ -12,8 +12,10 @@
11503 #ifndef __UNICORE_CACHE_H__
11504 #define __UNICORE_CACHE_H__
11505
11506-#define L1_CACHE_SHIFT (5)
11507-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11508+#include <linux/const.h>
11509+
11510+#define L1_CACHE_SHIFT 5
11511+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11512
11513 /*
11514 * Memory returned by kmalloc() may be used for DMA, so we must make
11515diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
11516index b32ebf9..5704f98 100644
11517--- a/arch/x86/Kconfig
11518+++ b/arch/x86/Kconfig
11519@@ -248,7 +248,7 @@ config X86_HT
11520
11521 config X86_32_LAZY_GS
11522 def_bool y
11523- depends on X86_32 && !CC_STACKPROTECTOR
11524+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
11525
11526 config ARCH_HWEIGHT_CFLAGS
11527 string
11528@@ -1088,6 +1088,7 @@ config MICROCODE_EARLY
11529
11530 config X86_MSR
11531 tristate "/dev/cpu/*/msr - Model-specific register support"
11532+ depends on !GRKERNSEC_KMEM
11533 ---help---
11534 This device gives privileged processes access to the x86
11535 Model-Specific Registers (MSRs). It is a character device with
11536@@ -1111,7 +1112,7 @@ choice
11537
11538 config NOHIGHMEM
11539 bool "off"
11540- depends on !X86_NUMAQ
11541+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
11542 ---help---
11543 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
11544 However, the address space of 32-bit x86 processors is only 4
11545@@ -1148,7 +1149,7 @@ config NOHIGHMEM
11546
11547 config HIGHMEM4G
11548 bool "4GB"
11549- depends on !X86_NUMAQ
11550+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
11551 ---help---
11552 Select this if you have a 32-bit processor and between 1 and 4
11553 gigabytes of physical RAM.
11554@@ -1201,7 +1202,7 @@ config PAGE_OFFSET
11555 hex
11556 default 0xB0000000 if VMSPLIT_3G_OPT
11557 default 0x80000000 if VMSPLIT_2G
11558- default 0x78000000 if VMSPLIT_2G_OPT
11559+ default 0x70000000 if VMSPLIT_2G_OPT
11560 default 0x40000000 if VMSPLIT_1G
11561 default 0xC0000000
11562 depends on X86_32
11563@@ -1599,6 +1600,7 @@ config SECCOMP
11564
11565 config CC_STACKPROTECTOR
11566 bool "Enable -fstack-protector buffer overflow detection"
11567+ depends on X86_64 || !PAX_MEMORY_UDEREF
11568 ---help---
11569 This option turns on the -fstack-protector GCC feature. This
11570 feature puts, at the beginning of functions, a canary value on
11571@@ -1718,6 +1720,8 @@ config X86_NEED_RELOCS
11572 config PHYSICAL_ALIGN
11573 hex "Alignment value to which kernel should be aligned" if X86_32
11574 default "0x1000000"
11575+ range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
11576+ range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
11577 range 0x2000 0x1000000
11578 ---help---
11579 This value puts the alignment restrictions on physical address
11580@@ -1793,9 +1797,10 @@ config DEBUG_HOTPLUG_CPU0
11581 If unsure, say N.
11582
11583 config COMPAT_VDSO
11584- def_bool y
11585+ def_bool n
11586 prompt "Compat VDSO support"
11587 depends on X86_32 || IA32_EMULATION
11588+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
11589 ---help---
11590 Map the 32-bit VDSO to the predictable old-style address too.
11591
11592diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
11593index c026cca..14657ae 100644
11594--- a/arch/x86/Kconfig.cpu
11595+++ b/arch/x86/Kconfig.cpu
11596@@ -319,7 +319,7 @@ config X86_PPRO_FENCE
11597
11598 config X86_F00F_BUG
11599 def_bool y
11600- depends on M586MMX || M586TSC || M586 || M486
11601+ depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
11602
11603 config X86_INVD_BUG
11604 def_bool y
11605@@ -327,7 +327,7 @@ config X86_INVD_BUG
11606
11607 config X86_ALIGNMENT_16
11608 def_bool y
11609- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
11610+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
11611
11612 config X86_INTEL_USERCOPY
11613 def_bool y
11614@@ -373,7 +373,7 @@ config X86_CMPXCHG64
11615 # generates cmov.
11616 config X86_CMOV
11617 def_bool y
11618- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
11619+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
11620
11621 config X86_MINIMUM_CPU_FAMILY
11622 int
11623diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
11624index 78d91af..8ceb94b 100644
11625--- a/arch/x86/Kconfig.debug
11626+++ b/arch/x86/Kconfig.debug
11627@@ -74,7 +74,7 @@ config X86_PTDUMP
11628 config DEBUG_RODATA
11629 bool "Write protect kernel read-only data structures"
11630 default y
11631- depends on DEBUG_KERNEL
11632+ depends on DEBUG_KERNEL && BROKEN
11633 ---help---
11634 Mark the kernel read-only data as write-protected in the pagetables,
11635 in order to catch accidental (and incorrect) writes to such const
11636@@ -92,7 +92,7 @@ config DEBUG_RODATA_TEST
11637
11638 config DEBUG_SET_MODULE_RONX
11639 bool "Set loadable kernel module data as NX and text as RO"
11640- depends on MODULES
11641+ depends on MODULES && BROKEN
11642 ---help---
11643 This option helps catch unintended modifications to loadable
11644 kernel module's text and read-only data. It also prevents execution
11645diff --git a/arch/x86/Makefile b/arch/x86/Makefile
11646index 07639c6..6f2c901 100644
11647--- a/arch/x86/Makefile
11648+++ b/arch/x86/Makefile
11649@@ -54,6 +54,7 @@ else
11650 UTS_MACHINE := x86_64
11651 CHECKFLAGS += -D__x86_64__ -m64
11652
11653+ biarch := $(call cc-option,-m64)
11654 KBUILD_AFLAGS += -m64
11655 KBUILD_CFLAGS += -m64
11656
11657@@ -241,3 +242,12 @@ define archhelp
11658 echo ' FDINITRD=file initrd for the booted kernel'
11659 echo ' kvmconfig - Enable additional options for guest kernel support'
11660 endef
11661+
11662+define OLD_LD
11663+
11664+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
11665+*** Please upgrade your binutils to 2.18 or newer
11666+endef
11667+
11668+archprepare:
11669+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
11670diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
11671index 379814b..add62ce 100644
11672--- a/arch/x86/boot/Makefile
11673+++ b/arch/x86/boot/Makefile
11674@@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
11675 $(call cc-option, -fno-stack-protector) \
11676 $(call cc-option, -mpreferred-stack-boundary=2)
11677 KBUILD_CFLAGS += $(call cc-option, -m32)
11678+ifdef CONSTIFY_PLUGIN
11679+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11680+endif
11681 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
11682 GCOV_PROFILE := n
11683
11684diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
11685index 878e4b9..20537ab 100644
11686--- a/arch/x86/boot/bitops.h
11687+++ b/arch/x86/boot/bitops.h
11688@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
11689 u8 v;
11690 const u32 *p = (const u32 *)addr;
11691
11692- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
11693+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
11694 return v;
11695 }
11696
11697@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
11698
11699 static inline void set_bit(int nr, void *addr)
11700 {
11701- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
11702+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
11703 }
11704
11705 #endif /* BOOT_BITOPS_H */
11706diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
11707index 5b75319..331a4ca 100644
11708--- a/arch/x86/boot/boot.h
11709+++ b/arch/x86/boot/boot.h
11710@@ -85,7 +85,7 @@ static inline void io_delay(void)
11711 static inline u16 ds(void)
11712 {
11713 u16 seg;
11714- asm("movw %%ds,%0" : "=rm" (seg));
11715+ asm volatile("movw %%ds,%0" : "=rm" (seg));
11716 return seg;
11717 }
11718
11719@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
11720 static inline int memcmp(const void *s1, const void *s2, size_t len)
11721 {
11722 u8 diff;
11723- asm("repe; cmpsb; setnz %0"
11724+ asm volatile("repe; cmpsb; setnz %0"
11725 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
11726 return diff;
11727 }
11728diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
11729index dcd90df..c830d7d 100644
11730--- a/arch/x86/boot/compressed/Makefile
11731+++ b/arch/x86/boot/compressed/Makefile
11732@@ -15,6 +15,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
11733 KBUILD_CFLAGS += $(cflags-y)
11734 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
11735 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
11736+ifdef CONSTIFY_PLUGIN
11737+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11738+endif
11739
11740 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
11741 GCOV_PROFILE := n
11742diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
11743index b7388a4..03844ec 100644
11744--- a/arch/x86/boot/compressed/eboot.c
11745+++ b/arch/x86/boot/compressed/eboot.c
11746@@ -150,7 +150,6 @@ again:
11747 *addr = max_addr;
11748 }
11749
11750-free_pool:
11751 efi_call_phys1(sys_table->boottime->free_pool, map);
11752
11753 fail:
11754@@ -214,7 +213,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
11755 if (i == map_size / desc_size)
11756 status = EFI_NOT_FOUND;
11757
11758-free_pool:
11759 efi_call_phys1(sys_table->boottime->free_pool, map);
11760 fail:
11761 return status;
11762diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
11763index a53440e..c3dbf1e 100644
11764--- a/arch/x86/boot/compressed/efi_stub_32.S
11765+++ b/arch/x86/boot/compressed/efi_stub_32.S
11766@@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
11767 * parameter 2, ..., param n. To make things easy, we save the return
11768 * address of efi_call_phys in a global variable.
11769 */
11770- popl %ecx
11771- movl %ecx, saved_return_addr(%edx)
11772- /* get the function pointer into ECX*/
11773- popl %ecx
11774- movl %ecx, efi_rt_function_ptr(%edx)
11775+ popl saved_return_addr(%edx)
11776+ popl efi_rt_function_ptr(%edx)
11777
11778 /*
11779 * 3. Call the physical function.
11780 */
11781- call *%ecx
11782+ call *efi_rt_function_ptr(%edx)
11783
11784 /*
11785 * 4. Balance the stack. And because EAX contain the return value,
11786@@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
11787 1: popl %edx
11788 subl $1b, %edx
11789
11790- movl efi_rt_function_ptr(%edx), %ecx
11791- pushl %ecx
11792+ pushl efi_rt_function_ptr(%edx)
11793
11794 /*
11795 * 10. Push the saved return address onto the stack and return.
11796 */
11797- movl saved_return_addr(%edx), %ecx
11798- pushl %ecx
11799- ret
11800+ jmpl *saved_return_addr(%edx)
11801 ENDPROC(efi_call_phys)
11802 .previous
11803
11804diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
11805index 1e3184f..0d11e2e 100644
11806--- a/arch/x86/boot/compressed/head_32.S
11807+++ b/arch/x86/boot/compressed/head_32.S
11808@@ -118,7 +118,7 @@ preferred_addr:
11809 notl %eax
11810 andl %eax, %ebx
11811 #else
11812- movl $LOAD_PHYSICAL_ADDR, %ebx
11813+ movl $____LOAD_PHYSICAL_ADDR, %ebx
11814 #endif
11815
11816 /* Target address to relocate to for decompression */
11817@@ -204,7 +204,7 @@ relocated:
11818 * and where it was actually loaded.
11819 */
11820 movl %ebp, %ebx
11821- subl $LOAD_PHYSICAL_ADDR, %ebx
11822+ subl $____LOAD_PHYSICAL_ADDR, %ebx
11823 jz 2f /* Nothing to be done if loaded at compiled addr. */
11824 /*
11825 * Process relocations.
11826@@ -212,8 +212,7 @@ relocated:
11827
11828 1: subl $4, %edi
11829 movl (%edi), %ecx
11830- testl %ecx, %ecx
11831- jz 2f
11832+ jecxz 2f
11833 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
11834 jmp 1b
11835 2:
11836diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
11837index 06e71c2..88a98264 100644
11838--- a/arch/x86/boot/compressed/head_64.S
11839+++ b/arch/x86/boot/compressed/head_64.S
11840@@ -95,7 +95,7 @@ ENTRY(startup_32)
11841 notl %eax
11842 andl %eax, %ebx
11843 #else
11844- movl $LOAD_PHYSICAL_ADDR, %ebx
11845+ movl $____LOAD_PHYSICAL_ADDR, %ebx
11846 #endif
11847
11848 /* Target address to relocate to for decompression */
11849@@ -270,7 +270,7 @@ preferred_addr:
11850 notq %rax
11851 andq %rax, %rbp
11852 #else
11853- movq $LOAD_PHYSICAL_ADDR, %rbp
11854+ movq $____LOAD_PHYSICAL_ADDR, %rbp
11855 #endif
11856
11857 /* Target address to relocate to for decompression */
11858@@ -361,8 +361,8 @@ gdt:
11859 .long gdt
11860 .word 0
11861 .quad 0x0000000000000000 /* NULL descriptor */
11862- .quad 0x00af9a000000ffff /* __KERNEL_CS */
11863- .quad 0x00cf92000000ffff /* __KERNEL_DS */
11864+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
11865+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
11866 .quad 0x0080890000000000 /* TS descriptor */
11867 .quad 0x0000000000000000 /* TS continued */
11868 gdt_end:
11869diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
11870index 0319c88..7c1931f 100644
11871--- a/arch/x86/boot/compressed/misc.c
11872+++ b/arch/x86/boot/compressed/misc.c
11873@@ -307,7 +307,7 @@ static void parse_elf(void *output)
11874 case PT_LOAD:
11875 #ifdef CONFIG_RELOCATABLE
11876 dest = output;
11877- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
11878+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
11879 #else
11880 dest = (void *)(phdr->p_paddr);
11881 #endif
11882@@ -358,7 +358,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
11883 error("Destination address too large");
11884 #endif
11885 #ifndef CONFIG_RELOCATABLE
11886- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
11887+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
11888 error("Wrong destination address");
11889 #endif
11890
11891diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
11892index 4d3ff03..e4972ff 100644
11893--- a/arch/x86/boot/cpucheck.c
11894+++ b/arch/x86/boot/cpucheck.c
11895@@ -74,7 +74,7 @@ static int has_fpu(void)
11896 u16 fcw = -1, fsw = -1;
11897 u32 cr0;
11898
11899- asm("movl %%cr0,%0" : "=r" (cr0));
11900+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
11901 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
11902 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
11903 asm volatile("movl %0,%%cr0" : : "r" (cr0));
11904@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
11905 {
11906 u32 f0, f1;
11907
11908- asm("pushfl ; "
11909+ asm volatile("pushfl ; "
11910 "pushfl ; "
11911 "popl %0 ; "
11912 "movl %0,%1 ; "
11913@@ -115,7 +115,7 @@ static void get_flags(void)
11914 set_bit(X86_FEATURE_FPU, cpu.flags);
11915
11916 if (has_eflag(X86_EFLAGS_ID)) {
11917- asm("cpuid"
11918+ asm volatile("cpuid"
11919 : "=a" (max_intel_level),
11920 "=b" (cpu_vendor[0]),
11921 "=d" (cpu_vendor[1]),
11922@@ -124,7 +124,7 @@ static void get_flags(void)
11923
11924 if (max_intel_level >= 0x00000001 &&
11925 max_intel_level <= 0x0000ffff) {
11926- asm("cpuid"
11927+ asm volatile("cpuid"
11928 : "=a" (tfms),
11929 "=c" (cpu.flags[4]),
11930 "=d" (cpu.flags[0])
11931@@ -136,7 +136,7 @@ static void get_flags(void)
11932 cpu.model += ((tfms >> 16) & 0xf) << 4;
11933 }
11934
11935- asm("cpuid"
11936+ asm volatile("cpuid"
11937 : "=a" (max_amd_level)
11938 : "a" (0x80000000)
11939 : "ebx", "ecx", "edx");
11940@@ -144,7 +144,7 @@ static void get_flags(void)
11941 if (max_amd_level >= 0x80000001 &&
11942 max_amd_level <= 0x8000ffff) {
11943 u32 eax = 0x80000001;
11944- asm("cpuid"
11945+ asm volatile("cpuid"
11946 : "+a" (eax),
11947 "=c" (cpu.flags[6]),
11948 "=d" (cpu.flags[1])
11949@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
11950 u32 ecx = MSR_K7_HWCR;
11951 u32 eax, edx;
11952
11953- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
11954+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
11955 eax &= ~(1 << 15);
11956- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
11957+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
11958
11959 get_flags(); /* Make sure it really did something */
11960 err = check_flags();
11961@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
11962 u32 ecx = MSR_VIA_FCR;
11963 u32 eax, edx;
11964
11965- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
11966+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
11967 eax |= (1<<1)|(1<<7);
11968- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
11969+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
11970
11971 set_bit(X86_FEATURE_CX8, cpu.flags);
11972 err = check_flags();
11973@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
11974 u32 eax, edx;
11975 u32 level = 1;
11976
11977- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
11978- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
11979- asm("cpuid"
11980+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
11981+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
11982+ asm volatile("cpuid"
11983 : "+a" (level), "=d" (cpu.flags[0])
11984 : : "ecx", "ebx");
11985- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
11986+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
11987
11988 err = check_flags();
11989 }
11990diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
11991index 9ec06a1..2c25e79 100644
11992--- a/arch/x86/boot/header.S
11993+++ b/arch/x86/boot/header.S
11994@@ -409,10 +409,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
11995 # single linked list of
11996 # struct setup_data
11997
11998-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
11999+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
12000
12001 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
12002+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
12003+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
12004+#else
12005 #define VO_INIT_SIZE (VO__end - VO__text)
12006+#endif
12007 #if ZO_INIT_SIZE > VO_INIT_SIZE
12008 #define INIT_SIZE ZO_INIT_SIZE
12009 #else
12010diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
12011index db75d07..8e6d0af 100644
12012--- a/arch/x86/boot/memory.c
12013+++ b/arch/x86/boot/memory.c
12014@@ -19,7 +19,7 @@
12015
12016 static int detect_memory_e820(void)
12017 {
12018- int count = 0;
12019+ unsigned int count = 0;
12020 struct biosregs ireg, oreg;
12021 struct e820entry *desc = boot_params.e820_map;
12022 static struct e820entry buf; /* static so it is zeroed */
12023diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
12024index 11e8c6e..fdbb1ed 100644
12025--- a/arch/x86/boot/video-vesa.c
12026+++ b/arch/x86/boot/video-vesa.c
12027@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
12028
12029 boot_params.screen_info.vesapm_seg = oreg.es;
12030 boot_params.screen_info.vesapm_off = oreg.di;
12031+ boot_params.screen_info.vesapm_size = oreg.cx;
12032 }
12033
12034 /*
12035diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
12036index 43eda28..5ab5fdb 100644
12037--- a/arch/x86/boot/video.c
12038+++ b/arch/x86/boot/video.c
12039@@ -96,7 +96,7 @@ static void store_mode_params(void)
12040 static unsigned int get_entry(void)
12041 {
12042 char entry_buf[4];
12043- int i, len = 0;
12044+ unsigned int i, len = 0;
12045 int key;
12046 unsigned int v;
12047
12048diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
12049index 9105655..5e37f27 100644
12050--- a/arch/x86/crypto/aes-x86_64-asm_64.S
12051+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
12052@@ -8,6 +8,8 @@
12053 * including this sentence is retained in full.
12054 */
12055
12056+#include <asm/alternative-asm.h>
12057+
12058 .extern crypto_ft_tab
12059 .extern crypto_it_tab
12060 .extern crypto_fl_tab
12061@@ -70,6 +72,8 @@
12062 je B192; \
12063 leaq 32(r9),r9;
12064
12065+#define ret pax_force_retaddr 0, 1; ret
12066+
12067 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
12068 movq r1,r2; \
12069 movq r3,r4; \
12070diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
12071index 477e9d7..3ab339f 100644
12072--- a/arch/x86/crypto/aesni-intel_asm.S
12073+++ b/arch/x86/crypto/aesni-intel_asm.S
12074@@ -31,6 +31,7 @@
12075
12076 #include <linux/linkage.h>
12077 #include <asm/inst.h>
12078+#include <asm/alternative-asm.h>
12079
12080 #ifdef __x86_64__
12081 .data
12082@@ -1441,6 +1442,7 @@ _return_T_done_decrypt:
12083 pop %r14
12084 pop %r13
12085 pop %r12
12086+ pax_force_retaddr 0, 1
12087 ret
12088 ENDPROC(aesni_gcm_dec)
12089
12090@@ -1705,6 +1707,7 @@ _return_T_done_encrypt:
12091 pop %r14
12092 pop %r13
12093 pop %r12
12094+ pax_force_retaddr 0, 1
12095 ret
12096 ENDPROC(aesni_gcm_enc)
12097
12098@@ -1722,6 +1725,7 @@ _key_expansion_256a:
12099 pxor %xmm1, %xmm0
12100 movaps %xmm0, (TKEYP)
12101 add $0x10, TKEYP
12102+ pax_force_retaddr_bts
12103 ret
12104 ENDPROC(_key_expansion_128)
12105 ENDPROC(_key_expansion_256a)
12106@@ -1748,6 +1752,7 @@ _key_expansion_192a:
12107 shufps $0b01001110, %xmm2, %xmm1
12108 movaps %xmm1, 0x10(TKEYP)
12109 add $0x20, TKEYP
12110+ pax_force_retaddr_bts
12111 ret
12112 ENDPROC(_key_expansion_192a)
12113
12114@@ -1768,6 +1773,7 @@ _key_expansion_192b:
12115
12116 movaps %xmm0, (TKEYP)
12117 add $0x10, TKEYP
12118+ pax_force_retaddr_bts
12119 ret
12120 ENDPROC(_key_expansion_192b)
12121
12122@@ -1781,6 +1787,7 @@ _key_expansion_256b:
12123 pxor %xmm1, %xmm2
12124 movaps %xmm2, (TKEYP)
12125 add $0x10, TKEYP
12126+ pax_force_retaddr_bts
12127 ret
12128 ENDPROC(_key_expansion_256b)
12129
12130@@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
12131 #ifndef __x86_64__
12132 popl KEYP
12133 #endif
12134+ pax_force_retaddr 0, 1
12135 ret
12136 ENDPROC(aesni_set_key)
12137
12138@@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
12139 popl KLEN
12140 popl KEYP
12141 #endif
12142+ pax_force_retaddr 0, 1
12143 ret
12144 ENDPROC(aesni_enc)
12145
12146@@ -1974,6 +1983,7 @@ _aesni_enc1:
12147 AESENC KEY STATE
12148 movaps 0x70(TKEYP), KEY
12149 AESENCLAST KEY STATE
12150+ pax_force_retaddr_bts
12151 ret
12152 ENDPROC(_aesni_enc1)
12153
12154@@ -2083,6 +2093,7 @@ _aesni_enc4:
12155 AESENCLAST KEY STATE2
12156 AESENCLAST KEY STATE3
12157 AESENCLAST KEY STATE4
12158+ pax_force_retaddr_bts
12159 ret
12160 ENDPROC(_aesni_enc4)
12161
12162@@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
12163 popl KLEN
12164 popl KEYP
12165 #endif
12166+ pax_force_retaddr 0, 1
12167 ret
12168 ENDPROC(aesni_dec)
12169
12170@@ -2164,6 +2176,7 @@ _aesni_dec1:
12171 AESDEC KEY STATE
12172 movaps 0x70(TKEYP), KEY
12173 AESDECLAST KEY STATE
12174+ pax_force_retaddr_bts
12175 ret
12176 ENDPROC(_aesni_dec1)
12177
12178@@ -2273,6 +2286,7 @@ _aesni_dec4:
12179 AESDECLAST KEY STATE2
12180 AESDECLAST KEY STATE3
12181 AESDECLAST KEY STATE4
12182+ pax_force_retaddr_bts
12183 ret
12184 ENDPROC(_aesni_dec4)
12185
12186@@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
12187 popl KEYP
12188 popl LEN
12189 #endif
12190+ pax_force_retaddr 0, 1
12191 ret
12192 ENDPROC(aesni_ecb_enc)
12193
12194@@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
12195 popl KEYP
12196 popl LEN
12197 #endif
12198+ pax_force_retaddr 0, 1
12199 ret
12200 ENDPROC(aesni_ecb_dec)
12201
12202@@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
12203 popl LEN
12204 popl IVP
12205 #endif
12206+ pax_force_retaddr 0, 1
12207 ret
12208 ENDPROC(aesni_cbc_enc)
12209
12210@@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
12211 popl LEN
12212 popl IVP
12213 #endif
12214+ pax_force_retaddr 0, 1
12215 ret
12216 ENDPROC(aesni_cbc_dec)
12217
12218@@ -2550,6 +2568,7 @@ _aesni_inc_init:
12219 mov $1, TCTR_LOW
12220 MOVQ_R64_XMM TCTR_LOW INC
12221 MOVQ_R64_XMM CTR TCTR_LOW
12222+ pax_force_retaddr_bts
12223 ret
12224 ENDPROC(_aesni_inc_init)
12225
12226@@ -2579,6 +2598,7 @@ _aesni_inc:
12227 .Linc_low:
12228 movaps CTR, IV
12229 PSHUFB_XMM BSWAP_MASK IV
12230+ pax_force_retaddr_bts
12231 ret
12232 ENDPROC(_aesni_inc)
12233
12234@@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
12235 .Lctr_enc_ret:
12236 movups IV, (IVP)
12237 .Lctr_enc_just_ret:
12238+ pax_force_retaddr 0, 1
12239 ret
12240 ENDPROC(aesni_ctr_enc)
12241
12242@@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
12243 pxor INC, STATE4
12244 movdqu STATE4, 0x70(OUTP)
12245
12246+ pax_force_retaddr 0, 1
12247 ret
12248 ENDPROC(aesni_xts_crypt8)
12249
12250diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
12251index 246c670..4d1ed00 100644
12252--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
12253+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
12254@@ -21,6 +21,7 @@
12255 */
12256
12257 #include <linux/linkage.h>
12258+#include <asm/alternative-asm.h>
12259
12260 .file "blowfish-x86_64-asm.S"
12261 .text
12262@@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
12263 jnz .L__enc_xor;
12264
12265 write_block();
12266+ pax_force_retaddr 0, 1
12267 ret;
12268 .L__enc_xor:
12269 xor_block();
12270+ pax_force_retaddr 0, 1
12271 ret;
12272 ENDPROC(__blowfish_enc_blk)
12273
12274@@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
12275
12276 movq %r11, %rbp;
12277
12278+ pax_force_retaddr 0, 1
12279 ret;
12280 ENDPROC(blowfish_dec_blk)
12281
12282@@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
12283
12284 popq %rbx;
12285 popq %rbp;
12286+ pax_force_retaddr 0, 1
12287 ret;
12288
12289 .L__enc_xor4:
12290@@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
12291
12292 popq %rbx;
12293 popq %rbp;
12294+ pax_force_retaddr 0, 1
12295 ret;
12296 ENDPROC(__blowfish_enc_blk_4way)
12297
12298@@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
12299 popq %rbx;
12300 popq %rbp;
12301
12302+ pax_force_retaddr 0, 1
12303 ret;
12304 ENDPROC(blowfish_dec_blk_4way)
12305diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12306index ce71f92..2dd5b1e 100644
12307--- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12308+++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12309@@ -16,6 +16,7 @@
12310 */
12311
12312 #include <linux/linkage.h>
12313+#include <asm/alternative-asm.h>
12314
12315 #define CAMELLIA_TABLE_BYTE_LEN 272
12316
12317@@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
12318 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
12319 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
12320 %rcx, (%r9));
12321+ pax_force_retaddr_bts
12322 ret;
12323 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
12324
12325@@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
12326 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
12327 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
12328 %rax, (%r9));
12329+ pax_force_retaddr_bts
12330 ret;
12331 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
12332
12333@@ -780,6 +783,7 @@ __camellia_enc_blk16:
12334 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
12335 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
12336
12337+ pax_force_retaddr_bts
12338 ret;
12339
12340 .align 8
12341@@ -865,6 +869,7 @@ __camellia_dec_blk16:
12342 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
12343 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
12344
12345+ pax_force_retaddr_bts
12346 ret;
12347
12348 .align 8
12349@@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
12350 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12351 %xmm8, %rsi);
12352
12353+ pax_force_retaddr 0, 1
12354 ret;
12355 ENDPROC(camellia_ecb_enc_16way)
12356
12357@@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
12358 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12359 %xmm8, %rsi);
12360
12361+ pax_force_retaddr 0, 1
12362 ret;
12363 ENDPROC(camellia_ecb_dec_16way)
12364
12365@@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
12366 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12367 %xmm8, %rsi);
12368
12369+ pax_force_retaddr 0, 1
12370 ret;
12371 ENDPROC(camellia_cbc_dec_16way)
12372
12373@@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
12374 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12375 %xmm8, %rsi);
12376
12377+ pax_force_retaddr 0, 1
12378 ret;
12379 ENDPROC(camellia_ctr_16way)
12380
12381@@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
12382 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12383 %xmm8, %rsi);
12384
12385+ pax_force_retaddr 0, 1
12386 ret;
12387 ENDPROC(camellia_xts_crypt_16way)
12388
12389diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12390index 0e0b886..8fc756a 100644
12391--- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12392+++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12393@@ -11,6 +11,7 @@
12394 */
12395
12396 #include <linux/linkage.h>
12397+#include <asm/alternative-asm.h>
12398
12399 #define CAMELLIA_TABLE_BYTE_LEN 272
12400
12401@@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
12402 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
12403 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
12404 %rcx, (%r9));
12405+ pax_force_retaddr_bts
12406 ret;
12407 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
12408
12409@@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
12410 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
12411 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
12412 %rax, (%r9));
12413+ pax_force_retaddr_bts
12414 ret;
12415 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
12416
12417@@ -820,6 +823,7 @@ __camellia_enc_blk32:
12418 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
12419 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
12420
12421+ pax_force_retaddr_bts
12422 ret;
12423
12424 .align 8
12425@@ -905,6 +909,7 @@ __camellia_dec_blk32:
12426 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
12427 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
12428
12429+ pax_force_retaddr_bts
12430 ret;
12431
12432 .align 8
12433@@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
12434
12435 vzeroupper;
12436
12437+ pax_force_retaddr 0, 1
12438 ret;
12439 ENDPROC(camellia_ecb_enc_32way)
12440
12441@@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
12442
12443 vzeroupper;
12444
12445+ pax_force_retaddr 0, 1
12446 ret;
12447 ENDPROC(camellia_ecb_dec_32way)
12448
12449@@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
12450
12451 vzeroupper;
12452
12453+ pax_force_retaddr 0, 1
12454 ret;
12455 ENDPROC(camellia_cbc_dec_32way)
12456
12457@@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
12458
12459 vzeroupper;
12460
12461+ pax_force_retaddr 0, 1
12462 ret;
12463 ENDPROC(camellia_ctr_32way)
12464
12465@@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
12466
12467 vzeroupper;
12468
12469+ pax_force_retaddr 0, 1
12470 ret;
12471 ENDPROC(camellia_xts_crypt_32way)
12472
12473diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
12474index 310319c..ce174a4 100644
12475--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
12476+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
12477@@ -21,6 +21,7 @@
12478 */
12479
12480 #include <linux/linkage.h>
12481+#include <asm/alternative-asm.h>
12482
12483 .file "camellia-x86_64-asm_64.S"
12484 .text
12485@@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
12486 enc_outunpack(mov, RT1);
12487
12488 movq RRBP, %rbp;
12489+ pax_force_retaddr 0, 1
12490 ret;
12491
12492 .L__enc_xor:
12493 enc_outunpack(xor, RT1);
12494
12495 movq RRBP, %rbp;
12496+ pax_force_retaddr 0, 1
12497 ret;
12498 ENDPROC(__camellia_enc_blk)
12499
12500@@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
12501 dec_outunpack();
12502
12503 movq RRBP, %rbp;
12504+ pax_force_retaddr 0, 1
12505 ret;
12506 ENDPROC(camellia_dec_blk)
12507
12508@@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
12509
12510 movq RRBP, %rbp;
12511 popq %rbx;
12512+ pax_force_retaddr 0, 1
12513 ret;
12514
12515 .L__enc2_xor:
12516@@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
12517
12518 movq RRBP, %rbp;
12519 popq %rbx;
12520+ pax_force_retaddr 0, 1
12521 ret;
12522 ENDPROC(__camellia_enc_blk_2way)
12523
12524@@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
12525
12526 movq RRBP, %rbp;
12527 movq RXOR, %rbx;
12528+ pax_force_retaddr 0, 1
12529 ret;
12530 ENDPROC(camellia_dec_blk_2way)
12531diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12532index c35fd5d..c1ee236 100644
12533--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12534+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12535@@ -24,6 +24,7 @@
12536 */
12537
12538 #include <linux/linkage.h>
12539+#include <asm/alternative-asm.h>
12540
12541 .file "cast5-avx-x86_64-asm_64.S"
12542
12543@@ -281,6 +282,7 @@ __cast5_enc_blk16:
12544 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
12545 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
12546
12547+ pax_force_retaddr 0, 1
12548 ret;
12549 ENDPROC(__cast5_enc_blk16)
12550
12551@@ -352,6 +354,7 @@ __cast5_dec_blk16:
12552 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
12553 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
12554
12555+ pax_force_retaddr 0, 1
12556 ret;
12557
12558 .L__skip_dec:
12559@@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
12560 vmovdqu RR4, (6*4*4)(%r11);
12561 vmovdqu RL4, (7*4*4)(%r11);
12562
12563+ pax_force_retaddr
12564 ret;
12565 ENDPROC(cast5_ecb_enc_16way)
12566
12567@@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
12568 vmovdqu RR4, (6*4*4)(%r11);
12569 vmovdqu RL4, (7*4*4)(%r11);
12570
12571+ pax_force_retaddr
12572 ret;
12573 ENDPROC(cast5_ecb_dec_16way)
12574
12575@@ -469,6 +474,7 @@ ENTRY(cast5_cbc_dec_16way)
12576
12577 popq %r12;
12578
12579+ pax_force_retaddr
12580 ret;
12581 ENDPROC(cast5_cbc_dec_16way)
12582
12583@@ -542,5 +548,6 @@ ENTRY(cast5_ctr_16way)
12584
12585 popq %r12;
12586
12587+ pax_force_retaddr
12588 ret;
12589 ENDPROC(cast5_ctr_16way)
12590diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
12591index e3531f8..18ded3a 100644
12592--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
12593+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
12594@@ -24,6 +24,7 @@
12595 */
12596
12597 #include <linux/linkage.h>
12598+#include <asm/alternative-asm.h>
12599 #include "glue_helper-asm-avx.S"
12600
12601 .file "cast6-avx-x86_64-asm_64.S"
12602@@ -295,6 +296,7 @@ __cast6_enc_blk8:
12603 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
12604 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
12605
12606+ pax_force_retaddr 0, 1
12607 ret;
12608 ENDPROC(__cast6_enc_blk8)
12609
12610@@ -340,6 +342,7 @@ __cast6_dec_blk8:
12611 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
12612 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
12613
12614+ pax_force_retaddr 0, 1
12615 ret;
12616 ENDPROC(__cast6_dec_blk8)
12617
12618@@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
12619
12620 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12621
12622+ pax_force_retaddr
12623 ret;
12624 ENDPROC(cast6_ecb_enc_8way)
12625
12626@@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
12627
12628 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12629
12630+ pax_force_retaddr
12631 ret;
12632 ENDPROC(cast6_ecb_dec_8way)
12633
12634@@ -399,6 +404,7 @@ ENTRY(cast6_cbc_dec_8way)
12635
12636 popq %r12;
12637
12638+ pax_force_retaddr
12639 ret;
12640 ENDPROC(cast6_cbc_dec_8way)
12641
12642@@ -424,6 +430,7 @@ ENTRY(cast6_ctr_8way)
12643
12644 popq %r12;
12645
12646+ pax_force_retaddr
12647 ret;
12648 ENDPROC(cast6_ctr_8way)
12649
12650@@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
12651 /* dst <= regs xor IVs(in dst) */
12652 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12653
12654+ pax_force_retaddr
12655 ret;
12656 ENDPROC(cast6_xts_enc_8way)
12657
12658@@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
12659 /* dst <= regs xor IVs(in dst) */
12660 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12661
12662+ pax_force_retaddr
12663 ret;
12664 ENDPROC(cast6_xts_dec_8way)
12665diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
12666index dbc4339..3d868c5 100644
12667--- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
12668+++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
12669@@ -45,6 +45,7 @@
12670
12671 #include <asm/inst.h>
12672 #include <linux/linkage.h>
12673+#include <asm/alternative-asm.h>
12674
12675 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
12676
12677@@ -312,6 +313,7 @@ do_return:
12678 popq %rsi
12679 popq %rdi
12680 popq %rbx
12681+ pax_force_retaddr 0, 1
12682 ret
12683
12684 ################################################################
12685diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
12686index 586f41a..d02851e 100644
12687--- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
12688+++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
12689@@ -18,6 +18,7 @@
12690
12691 #include <linux/linkage.h>
12692 #include <asm/inst.h>
12693+#include <asm/alternative-asm.h>
12694
12695 .data
12696
12697@@ -93,6 +94,7 @@ __clmul_gf128mul_ble:
12698 psrlq $1, T2
12699 pxor T2, T1
12700 pxor T1, DATA
12701+ pax_force_retaddr
12702 ret
12703 ENDPROC(__clmul_gf128mul_ble)
12704
12705@@ -105,6 +107,7 @@ ENTRY(clmul_ghash_mul)
12706 call __clmul_gf128mul_ble
12707 PSHUFB_XMM BSWAP DATA
12708 movups DATA, (%rdi)
12709+ pax_force_retaddr
12710 ret
12711 ENDPROC(clmul_ghash_mul)
12712
12713@@ -132,6 +135,7 @@ ENTRY(clmul_ghash_update)
12714 PSHUFB_XMM BSWAP DATA
12715 movups DATA, (%rdi)
12716 .Lupdate_just_ret:
12717+ pax_force_retaddr
12718 ret
12719 ENDPROC(clmul_ghash_update)
12720
12721@@ -157,5 +161,6 @@ ENTRY(clmul_ghash_setkey)
12722 pand .Lpoly, %xmm1
12723 pxor %xmm1, %xmm0
12724 movups %xmm0, (%rdi)
12725+ pax_force_retaddr
12726 ret
12727 ENDPROC(clmul_ghash_setkey)
12728diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
12729index 9279e0b..9270820 100644
12730--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
12731+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
12732@@ -1,4 +1,5 @@
12733 #include <linux/linkage.h>
12734+#include <asm/alternative-asm.h>
12735
12736 # enter salsa20_encrypt_bytes
12737 ENTRY(salsa20_encrypt_bytes)
12738@@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
12739 add %r11,%rsp
12740 mov %rdi,%rax
12741 mov %rsi,%rdx
12742+ pax_force_retaddr 0, 1
12743 ret
12744 # bytesatleast65:
12745 ._bytesatleast65:
12746@@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
12747 add %r11,%rsp
12748 mov %rdi,%rax
12749 mov %rsi,%rdx
12750+ pax_force_retaddr
12751 ret
12752 ENDPROC(salsa20_keysetup)
12753
12754@@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
12755 add %r11,%rsp
12756 mov %rdi,%rax
12757 mov %rsi,%rdx
12758+ pax_force_retaddr
12759 ret
12760 ENDPROC(salsa20_ivsetup)
12761diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
12762index 2f202f4..d9164d6 100644
12763--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
12764+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
12765@@ -24,6 +24,7 @@
12766 */
12767
12768 #include <linux/linkage.h>
12769+#include <asm/alternative-asm.h>
12770 #include "glue_helper-asm-avx.S"
12771
12772 .file "serpent-avx-x86_64-asm_64.S"
12773@@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
12774 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
12775 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
12776
12777+ pax_force_retaddr
12778 ret;
12779 ENDPROC(__serpent_enc_blk8_avx)
12780
12781@@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
12782 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
12783 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
12784
12785+ pax_force_retaddr
12786 ret;
12787 ENDPROC(__serpent_dec_blk8_avx)
12788
12789@@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
12790
12791 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12792
12793+ pax_force_retaddr
12794 ret;
12795 ENDPROC(serpent_ecb_enc_8way_avx)
12796
12797@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
12798
12799 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
12800
12801+ pax_force_retaddr
12802 ret;
12803 ENDPROC(serpent_ecb_dec_8way_avx)
12804
12805@@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
12806
12807 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
12808
12809+ pax_force_retaddr
12810 ret;
12811 ENDPROC(serpent_cbc_dec_8way_avx)
12812
12813@@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
12814
12815 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12816
12817+ pax_force_retaddr
12818 ret;
12819 ENDPROC(serpent_ctr_8way_avx)
12820
12821@@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
12822 /* dst <= regs xor IVs(in dst) */
12823 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
12824
12825+ pax_force_retaddr
12826 ret;
12827 ENDPROC(serpent_xts_enc_8way_avx)
12828
12829@@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
12830 /* dst <= regs xor IVs(in dst) */
12831 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
12832
12833+ pax_force_retaddr
12834 ret;
12835 ENDPROC(serpent_xts_dec_8way_avx)
12836diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
12837index b222085..abd483c 100644
12838--- a/arch/x86/crypto/serpent-avx2-asm_64.S
12839+++ b/arch/x86/crypto/serpent-avx2-asm_64.S
12840@@ -15,6 +15,7 @@
12841 */
12842
12843 #include <linux/linkage.h>
12844+#include <asm/alternative-asm.h>
12845 #include "glue_helper-asm-avx2.S"
12846
12847 .file "serpent-avx2-asm_64.S"
12848@@ -610,6 +611,7 @@ __serpent_enc_blk16:
12849 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
12850 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
12851
12852+ pax_force_retaddr
12853 ret;
12854 ENDPROC(__serpent_enc_blk16)
12855
12856@@ -664,6 +666,7 @@ __serpent_dec_blk16:
12857 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
12858 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
12859
12860+ pax_force_retaddr
12861 ret;
12862 ENDPROC(__serpent_dec_blk16)
12863
12864@@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
12865
12866 vzeroupper;
12867
12868+ pax_force_retaddr
12869 ret;
12870 ENDPROC(serpent_ecb_enc_16way)
12871
12872@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
12873
12874 vzeroupper;
12875
12876+ pax_force_retaddr
12877 ret;
12878 ENDPROC(serpent_ecb_dec_16way)
12879
12880@@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
12881
12882 vzeroupper;
12883
12884+ pax_force_retaddr
12885 ret;
12886 ENDPROC(serpent_cbc_dec_16way)
12887
12888@@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
12889
12890 vzeroupper;
12891
12892+ pax_force_retaddr
12893 ret;
12894 ENDPROC(serpent_ctr_16way)
12895
12896@@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
12897
12898 vzeroupper;
12899
12900+ pax_force_retaddr
12901 ret;
12902 ENDPROC(serpent_xts_enc_16way)
12903
12904@@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
12905
12906 vzeroupper;
12907
12908+ pax_force_retaddr
12909 ret;
12910 ENDPROC(serpent_xts_dec_16way)
12911diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
12912index acc066c..1559cc4 100644
12913--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
12914+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
12915@@ -25,6 +25,7 @@
12916 */
12917
12918 #include <linux/linkage.h>
12919+#include <asm/alternative-asm.h>
12920
12921 .file "serpent-sse2-x86_64-asm_64.S"
12922 .text
12923@@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
12924 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
12925 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
12926
12927+ pax_force_retaddr
12928 ret;
12929
12930 .L__enc_xor8:
12931 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
12932 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
12933
12934+ pax_force_retaddr
12935 ret;
12936 ENDPROC(__serpent_enc_blk_8way)
12937
12938@@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
12939 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
12940 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
12941
12942+ pax_force_retaddr
12943 ret;
12944 ENDPROC(serpent_dec_blk_8way)
12945diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
12946index a410950..3356d42 100644
12947--- a/arch/x86/crypto/sha1_ssse3_asm.S
12948+++ b/arch/x86/crypto/sha1_ssse3_asm.S
12949@@ -29,6 +29,7 @@
12950 */
12951
12952 #include <linux/linkage.h>
12953+#include <asm/alternative-asm.h>
12954
12955 #define CTX %rdi // arg1
12956 #define BUF %rsi // arg2
12957@@ -104,6 +105,7 @@
12958 pop %r12
12959 pop %rbp
12960 pop %rbx
12961+ pax_force_retaddr 0, 1
12962 ret
12963
12964 ENDPROC(\name)
12965diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
12966index 642f156..4ab07b9 100644
12967--- a/arch/x86/crypto/sha256-avx-asm.S
12968+++ b/arch/x86/crypto/sha256-avx-asm.S
12969@@ -49,6 +49,7 @@
12970
12971 #ifdef CONFIG_AS_AVX
12972 #include <linux/linkage.h>
12973+#include <asm/alternative-asm.h>
12974
12975 ## assume buffers not aligned
12976 #define VMOVDQ vmovdqu
12977@@ -460,6 +461,7 @@ done_hash:
12978 popq %r13
12979 popq %rbp
12980 popq %rbx
12981+ pax_force_retaddr 0, 1
12982 ret
12983 ENDPROC(sha256_transform_avx)
12984
12985diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
12986index 9e86944..2e7f95a 100644
12987--- a/arch/x86/crypto/sha256-avx2-asm.S
12988+++ b/arch/x86/crypto/sha256-avx2-asm.S
12989@@ -50,6 +50,7 @@
12990
12991 #ifdef CONFIG_AS_AVX2
12992 #include <linux/linkage.h>
12993+#include <asm/alternative-asm.h>
12994
12995 ## assume buffers not aligned
12996 #define VMOVDQ vmovdqu
12997@@ -720,6 +721,7 @@ done_hash:
12998 popq %r12
12999 popq %rbp
13000 popq %rbx
13001+ pax_force_retaddr 0, 1
13002 ret
13003 ENDPROC(sha256_transform_rorx)
13004
13005diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
13006index f833b74..c36ed14 100644
13007--- a/arch/x86/crypto/sha256-ssse3-asm.S
13008+++ b/arch/x86/crypto/sha256-ssse3-asm.S
13009@@ -47,6 +47,7 @@
13010 ########################################################################
13011
13012 #include <linux/linkage.h>
13013+#include <asm/alternative-asm.h>
13014
13015 ## assume buffers not aligned
13016 #define MOVDQ movdqu
13017@@ -471,6 +472,7 @@ done_hash:
13018 popq %rbp
13019 popq %rbx
13020
13021+ pax_force_retaddr 0, 1
13022 ret
13023 ENDPROC(sha256_transform_ssse3)
13024
13025diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
13026index 974dde9..4533d34 100644
13027--- a/arch/x86/crypto/sha512-avx-asm.S
13028+++ b/arch/x86/crypto/sha512-avx-asm.S
13029@@ -49,6 +49,7 @@
13030
13031 #ifdef CONFIG_AS_AVX
13032 #include <linux/linkage.h>
13033+#include <asm/alternative-asm.h>
13034
13035 .text
13036
13037@@ -364,6 +365,7 @@ updateblock:
13038 mov frame_RSPSAVE(%rsp), %rsp
13039
13040 nowork:
13041+ pax_force_retaddr 0, 1
13042 ret
13043 ENDPROC(sha512_transform_avx)
13044
13045diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
13046index 568b961..061ef1d 100644
13047--- a/arch/x86/crypto/sha512-avx2-asm.S
13048+++ b/arch/x86/crypto/sha512-avx2-asm.S
13049@@ -51,6 +51,7 @@
13050
13051 #ifdef CONFIG_AS_AVX2
13052 #include <linux/linkage.h>
13053+#include <asm/alternative-asm.h>
13054
13055 .text
13056
13057@@ -678,6 +679,7 @@ done_hash:
13058
13059 # Restore Stack Pointer
13060 mov frame_RSPSAVE(%rsp), %rsp
13061+ pax_force_retaddr 0, 1
13062 ret
13063 ENDPROC(sha512_transform_rorx)
13064
13065diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
13066index fb56855..e23914f 100644
13067--- a/arch/x86/crypto/sha512-ssse3-asm.S
13068+++ b/arch/x86/crypto/sha512-ssse3-asm.S
13069@@ -48,6 +48,7 @@
13070 ########################################################################
13071
13072 #include <linux/linkage.h>
13073+#include <asm/alternative-asm.h>
13074
13075 .text
13076
13077@@ -363,6 +364,7 @@ updateblock:
13078 mov frame_RSPSAVE(%rsp), %rsp
13079
13080 nowork:
13081+ pax_force_retaddr 0, 1
13082 ret
13083 ENDPROC(sha512_transform_ssse3)
13084
13085diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13086index 0505813..63b1d00 100644
13087--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13088+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13089@@ -24,6 +24,7 @@
13090 */
13091
13092 #include <linux/linkage.h>
13093+#include <asm/alternative-asm.h>
13094 #include "glue_helper-asm-avx.S"
13095
13096 .file "twofish-avx-x86_64-asm_64.S"
13097@@ -284,6 +285,7 @@ __twofish_enc_blk8:
13098 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
13099 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
13100
13101+ pax_force_retaddr 0, 1
13102 ret;
13103 ENDPROC(__twofish_enc_blk8)
13104
13105@@ -324,6 +326,7 @@ __twofish_dec_blk8:
13106 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
13107 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
13108
13109+ pax_force_retaddr 0, 1
13110 ret;
13111 ENDPROC(__twofish_dec_blk8)
13112
13113@@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
13114
13115 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13116
13117+ pax_force_retaddr 0, 1
13118 ret;
13119 ENDPROC(twofish_ecb_enc_8way)
13120
13121@@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
13122
13123 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13124
13125+ pax_force_retaddr 0, 1
13126 ret;
13127 ENDPROC(twofish_ecb_dec_8way)
13128
13129@@ -383,6 +388,7 @@ ENTRY(twofish_cbc_dec_8way)
13130
13131 popq %r12;
13132
13133+ pax_force_retaddr 0, 1
13134 ret;
13135 ENDPROC(twofish_cbc_dec_8way)
13136
13137@@ -408,6 +414,7 @@ ENTRY(twofish_ctr_8way)
13138
13139 popq %r12;
13140
13141+ pax_force_retaddr 0, 1
13142 ret;
13143 ENDPROC(twofish_ctr_8way)
13144
13145@@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
13146 /* dst <= regs xor IVs(in dst) */
13147 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13148
13149+ pax_force_retaddr 0, 1
13150 ret;
13151 ENDPROC(twofish_xts_enc_8way)
13152
13153@@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
13154 /* dst <= regs xor IVs(in dst) */
13155 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13156
13157+ pax_force_retaddr 0, 1
13158 ret;
13159 ENDPROC(twofish_xts_dec_8way)
13160diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13161index 1c3b7ce..b365c5e 100644
13162--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13163+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13164@@ -21,6 +21,7 @@
13165 */
13166
13167 #include <linux/linkage.h>
13168+#include <asm/alternative-asm.h>
13169
13170 .file "twofish-x86_64-asm-3way.S"
13171 .text
13172@@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
13173 popq %r13;
13174 popq %r14;
13175 popq %r15;
13176+ pax_force_retaddr 0, 1
13177 ret;
13178
13179 .L__enc_xor3:
13180@@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
13181 popq %r13;
13182 popq %r14;
13183 popq %r15;
13184+ pax_force_retaddr 0, 1
13185 ret;
13186 ENDPROC(__twofish_enc_blk_3way)
13187
13188@@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
13189 popq %r13;
13190 popq %r14;
13191 popq %r15;
13192+ pax_force_retaddr 0, 1
13193 ret;
13194 ENDPROC(twofish_dec_blk_3way)
13195diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
13196index a039d21..29e7615 100644
13197--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
13198+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
13199@@ -22,6 +22,7 @@
13200
13201 #include <linux/linkage.h>
13202 #include <asm/asm-offsets.h>
13203+#include <asm/alternative-asm.h>
13204
13205 #define a_offset 0
13206 #define b_offset 4
13207@@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
13208
13209 popq R1
13210 movq $1,%rax
13211+ pax_force_retaddr 0, 1
13212 ret
13213 ENDPROC(twofish_enc_blk)
13214
13215@@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
13216
13217 popq R1
13218 movq $1,%rax
13219+ pax_force_retaddr 0, 1
13220 ret
13221 ENDPROC(twofish_dec_blk)
13222diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
13223index bae3aba..c1788c1 100644
13224--- a/arch/x86/ia32/ia32_aout.c
13225+++ b/arch/x86/ia32/ia32_aout.c
13226@@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
13227 unsigned long dump_start, dump_size;
13228 struct user32 dump;
13229
13230+ memset(&dump, 0, sizeof(dump));
13231+
13232 fs = get_fs();
13233 set_fs(KERNEL_DS);
13234 has_dumped = 1;
13235diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
13236index bccfca6..a312009 100644
13237--- a/arch/x86/ia32/ia32_signal.c
13238+++ b/arch/x86/ia32/ia32_signal.c
13239@@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
13240 sp -= frame_size;
13241 /* Align the stack pointer according to the i386 ABI,
13242 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
13243- sp = ((sp + 4) & -16ul) - 4;
13244+ sp = ((sp - 12) & -16ul) - 4;
13245 return (void __user *) sp;
13246 }
13247
13248@@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
13249 * These are actually not used anymore, but left because some
13250 * gdb versions depend on them as a marker.
13251 */
13252- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
13253+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
13254 } put_user_catch(err);
13255
13256 if (err)
13257@@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
13258 0xb8,
13259 __NR_ia32_rt_sigreturn,
13260 0x80cd,
13261- 0,
13262+ 0
13263 };
13264
13265 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
13266@@ -457,20 +457,22 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
13267 else
13268 put_user_ex(0, &frame->uc.uc_flags);
13269 put_user_ex(0, &frame->uc.uc_link);
13270- err |= __compat_save_altstack(&frame->uc.uc_stack, regs->sp);
13271+ __compat_save_altstack_ex(&frame->uc.uc_stack, regs->sp);
13272
13273 if (ksig->ka.sa.sa_flags & SA_RESTORER)
13274 restorer = ksig->ka.sa.sa_restorer;
13275+ else if (current->mm->context.vdso)
13276+ /* Return stub is in 32bit vsyscall page */
13277+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
13278 else
13279- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
13280- rt_sigreturn);
13281+ restorer = &frame->retcode;
13282 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
13283
13284 /*
13285 * Not actually used anymore, but left because some gdb
13286 * versions need it.
13287 */
13288- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
13289+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
13290 } put_user_catch(err);
13291
13292 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
13293diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
13294index 474dc1b..9297c58 100644
13295--- a/arch/x86/ia32/ia32entry.S
13296+++ b/arch/x86/ia32/ia32entry.S
13297@@ -15,8 +15,10 @@
13298 #include <asm/irqflags.h>
13299 #include <asm/asm.h>
13300 #include <asm/smap.h>
13301+#include <asm/pgtable.h>
13302 #include <linux/linkage.h>
13303 #include <linux/err.h>
13304+#include <asm/alternative-asm.h>
13305
13306 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
13307 #include <linux/elf-em.h>
13308@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
13309 ENDPROC(native_irq_enable_sysexit)
13310 #endif
13311
13312+ .macro pax_enter_kernel_user
13313+ pax_set_fptr_mask
13314+#ifdef CONFIG_PAX_MEMORY_UDEREF
13315+ call pax_enter_kernel_user
13316+#endif
13317+ .endm
13318+
13319+ .macro pax_exit_kernel_user
13320+#ifdef CONFIG_PAX_MEMORY_UDEREF
13321+ call pax_exit_kernel_user
13322+#endif
13323+#ifdef CONFIG_PAX_RANDKSTACK
13324+ pushq %rax
13325+ pushq %r11
13326+ call pax_randomize_kstack
13327+ popq %r11
13328+ popq %rax
13329+#endif
13330+ .endm
13331+
13332+ .macro pax_erase_kstack
13333+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
13334+ call pax_erase_kstack
13335+#endif
13336+ .endm
13337+
13338 /*
13339 * 32bit SYSENTER instruction entry.
13340 *
13341@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
13342 CFI_REGISTER rsp,rbp
13343 SWAPGS_UNSAFE_STACK
13344 movq PER_CPU_VAR(kernel_stack), %rsp
13345- addq $(KERNEL_STACK_OFFSET),%rsp
13346- /*
13347- * No need to follow this irqs on/off section: the syscall
13348- * disabled irqs, here we enable it straight after entry:
13349- */
13350- ENABLE_INTERRUPTS(CLBR_NONE)
13351 movl %ebp,%ebp /* zero extension */
13352 pushq_cfi $__USER32_DS
13353 /*CFI_REL_OFFSET ss,0*/
13354@@ -135,24 +157,49 @@ ENTRY(ia32_sysenter_target)
13355 CFI_REL_OFFSET rsp,0
13356 pushfq_cfi
13357 /*CFI_REL_OFFSET rflags,0*/
13358- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
13359- CFI_REGISTER rip,r10
13360+ orl $X86_EFLAGS_IF,(%rsp)
13361+ GET_THREAD_INFO(%r11)
13362+ movl TI_sysenter_return(%r11), %r11d
13363+ CFI_REGISTER rip,r11
13364 pushq_cfi $__USER32_CS
13365 /*CFI_REL_OFFSET cs,0*/
13366 movl %eax, %eax
13367- pushq_cfi %r10
13368+ pushq_cfi %r11
13369 CFI_REL_OFFSET rip,0
13370 pushq_cfi %rax
13371 cld
13372 SAVE_ARGS 0,1,0
13373+ pax_enter_kernel_user
13374+
13375+#ifdef CONFIG_PAX_RANDKSTACK
13376+ pax_erase_kstack
13377+#endif
13378+
13379+ /*
13380+ * No need to follow this irqs on/off section: the syscall
13381+ * disabled irqs, here we enable it straight after entry:
13382+ */
13383+ ENABLE_INTERRUPTS(CLBR_NONE)
13384 /* no need to do an access_ok check here because rbp has been
13385 32bit zero extended */
13386+
13387+#ifdef CONFIG_PAX_MEMORY_UDEREF
13388+ addq pax_user_shadow_base,%rbp
13389+ ASM_PAX_OPEN_USERLAND
13390+#endif
13391+
13392 ASM_STAC
13393 1: movl (%rbp),%ebp
13394 _ASM_EXTABLE(1b,ia32_badarg)
13395 ASM_CLAC
13396- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13397- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13398+
13399+#ifdef CONFIG_PAX_MEMORY_UDEREF
13400+ ASM_PAX_CLOSE_USERLAND
13401+#endif
13402+
13403+ GET_THREAD_INFO(%r11)
13404+ orl $TS_COMPAT,TI_status(%r11)
13405+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
13406 CFI_REMEMBER_STATE
13407 jnz sysenter_tracesys
13408 cmpq $(IA32_NR_syscalls-1),%rax
13409@@ -162,12 +209,15 @@ sysenter_do_call:
13410 sysenter_dispatch:
13411 call *ia32_sys_call_table(,%rax,8)
13412 movq %rax,RAX-ARGOFFSET(%rsp)
13413+ GET_THREAD_INFO(%r11)
13414 DISABLE_INTERRUPTS(CLBR_NONE)
13415 TRACE_IRQS_OFF
13416- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13417+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
13418 jnz sysexit_audit
13419 sysexit_from_sys_call:
13420- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13421+ pax_exit_kernel_user
13422+ pax_erase_kstack
13423+ andl $~TS_COMPAT,TI_status(%r11)
13424 /* clear IF, that popfq doesn't enable interrupts early */
13425 andl $~0x200,EFLAGS-R11(%rsp)
13426 movl RIP-R11(%rsp),%edx /* User %eip */
13427@@ -193,6 +243,9 @@ sysexit_from_sys_call:
13428 movl %eax,%esi /* 2nd arg: syscall number */
13429 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
13430 call __audit_syscall_entry
13431+
13432+ pax_erase_kstack
13433+
13434 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
13435 cmpq $(IA32_NR_syscalls-1),%rax
13436 ja ia32_badsys
13437@@ -204,7 +257,7 @@ sysexit_from_sys_call:
13438 .endm
13439
13440 .macro auditsys_exit exit
13441- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13442+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
13443 jnz ia32_ret_from_sys_call
13444 TRACE_IRQS_ON
13445 ENABLE_INTERRUPTS(CLBR_NONE)
13446@@ -215,11 +268,12 @@ sysexit_from_sys_call:
13447 1: setbe %al /* 1 if error, 0 if not */
13448 movzbl %al,%edi /* zero-extend that into %edi */
13449 call __audit_syscall_exit
13450+ GET_THREAD_INFO(%r11)
13451 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
13452 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
13453 DISABLE_INTERRUPTS(CLBR_NONE)
13454 TRACE_IRQS_OFF
13455- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13456+ testl %edi,TI_flags(%r11)
13457 jz \exit
13458 CLEAR_RREGS -ARGOFFSET
13459 jmp int_with_check
13460@@ -237,7 +291,7 @@ sysexit_audit:
13461
13462 sysenter_tracesys:
13463 #ifdef CONFIG_AUDITSYSCALL
13464- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13465+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
13466 jz sysenter_auditsys
13467 #endif
13468 SAVE_REST
13469@@ -249,6 +303,9 @@ sysenter_tracesys:
13470 RESTORE_REST
13471 cmpq $(IA32_NR_syscalls-1),%rax
13472 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
13473+
13474+ pax_erase_kstack
13475+
13476 jmp sysenter_do_call
13477 CFI_ENDPROC
13478 ENDPROC(ia32_sysenter_target)
13479@@ -276,19 +333,25 @@ ENDPROC(ia32_sysenter_target)
13480 ENTRY(ia32_cstar_target)
13481 CFI_STARTPROC32 simple
13482 CFI_SIGNAL_FRAME
13483- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
13484+ CFI_DEF_CFA rsp,0
13485 CFI_REGISTER rip,rcx
13486 /*CFI_REGISTER rflags,r11*/
13487 SWAPGS_UNSAFE_STACK
13488 movl %esp,%r8d
13489 CFI_REGISTER rsp,r8
13490 movq PER_CPU_VAR(kernel_stack),%rsp
13491+ SAVE_ARGS 8*6,0,0
13492+ pax_enter_kernel_user
13493+
13494+#ifdef CONFIG_PAX_RANDKSTACK
13495+ pax_erase_kstack
13496+#endif
13497+
13498 /*
13499 * No need to follow this irqs on/off section: the syscall
13500 * disabled irqs and here we enable it straight after entry:
13501 */
13502 ENABLE_INTERRUPTS(CLBR_NONE)
13503- SAVE_ARGS 8,0,0
13504 movl %eax,%eax /* zero extension */
13505 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
13506 movq %rcx,RIP-ARGOFFSET(%rsp)
13507@@ -304,12 +367,25 @@ ENTRY(ia32_cstar_target)
13508 /* no need to do an access_ok check here because r8 has been
13509 32bit zero extended */
13510 /* hardware stack frame is complete now */
13511+
13512+#ifdef CONFIG_PAX_MEMORY_UDEREF
13513+ ASM_PAX_OPEN_USERLAND
13514+ movq pax_user_shadow_base,%r8
13515+ addq RSP-ARGOFFSET(%rsp),%r8
13516+#endif
13517+
13518 ASM_STAC
13519 1: movl (%r8),%r9d
13520 _ASM_EXTABLE(1b,ia32_badarg)
13521 ASM_CLAC
13522- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13523- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13524+
13525+#ifdef CONFIG_PAX_MEMORY_UDEREF
13526+ ASM_PAX_CLOSE_USERLAND
13527+#endif
13528+
13529+ GET_THREAD_INFO(%r11)
13530+ orl $TS_COMPAT,TI_status(%r11)
13531+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
13532 CFI_REMEMBER_STATE
13533 jnz cstar_tracesys
13534 cmpq $IA32_NR_syscalls-1,%rax
13535@@ -319,12 +395,15 @@ cstar_do_call:
13536 cstar_dispatch:
13537 call *ia32_sys_call_table(,%rax,8)
13538 movq %rax,RAX-ARGOFFSET(%rsp)
13539+ GET_THREAD_INFO(%r11)
13540 DISABLE_INTERRUPTS(CLBR_NONE)
13541 TRACE_IRQS_OFF
13542- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13543+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
13544 jnz sysretl_audit
13545 sysretl_from_sys_call:
13546- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13547+ pax_exit_kernel_user
13548+ pax_erase_kstack
13549+ andl $~TS_COMPAT,TI_status(%r11)
13550 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
13551 movl RIP-ARGOFFSET(%rsp),%ecx
13552 CFI_REGISTER rip,rcx
13553@@ -352,7 +431,7 @@ sysretl_audit:
13554
13555 cstar_tracesys:
13556 #ifdef CONFIG_AUDITSYSCALL
13557- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13558+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
13559 jz cstar_auditsys
13560 #endif
13561 xchgl %r9d,%ebp
13562@@ -366,11 +445,19 @@ cstar_tracesys:
13563 xchgl %ebp,%r9d
13564 cmpq $(IA32_NR_syscalls-1),%rax
13565 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
13566+
13567+ pax_erase_kstack
13568+
13569 jmp cstar_do_call
13570 END(ia32_cstar_target)
13571
13572 ia32_badarg:
13573 ASM_CLAC
13574+
13575+#ifdef CONFIG_PAX_MEMORY_UDEREF
13576+ ASM_PAX_CLOSE_USERLAND
13577+#endif
13578+
13579 movq $-EFAULT,%rax
13580 jmp ia32_sysret
13581 CFI_ENDPROC
13582@@ -407,19 +494,26 @@ ENTRY(ia32_syscall)
13583 CFI_REL_OFFSET rip,RIP-RIP
13584 PARAVIRT_ADJUST_EXCEPTION_FRAME
13585 SWAPGS
13586- /*
13587- * No need to follow this irqs on/off section: the syscall
13588- * disabled irqs and here we enable it straight after entry:
13589- */
13590- ENABLE_INTERRUPTS(CLBR_NONE)
13591 movl %eax,%eax
13592 pushq_cfi %rax
13593 cld
13594 /* note the registers are not zero extended to the sf.
13595 this could be a problem. */
13596 SAVE_ARGS 0,1,0
13597- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13598- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13599+ pax_enter_kernel_user
13600+
13601+#ifdef CONFIG_PAX_RANDKSTACK
13602+ pax_erase_kstack
13603+#endif
13604+
13605+ /*
13606+ * No need to follow this irqs on/off section: the syscall
13607+ * disabled irqs and here we enable it straight after entry:
13608+ */
13609+ ENABLE_INTERRUPTS(CLBR_NONE)
13610+ GET_THREAD_INFO(%r11)
13611+ orl $TS_COMPAT,TI_status(%r11)
13612+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
13613 jnz ia32_tracesys
13614 cmpq $(IA32_NR_syscalls-1),%rax
13615 ja ia32_badsys
13616@@ -442,6 +536,9 @@ ia32_tracesys:
13617 RESTORE_REST
13618 cmpq $(IA32_NR_syscalls-1),%rax
13619 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
13620+
13621+ pax_erase_kstack
13622+
13623 jmp ia32_do_call
13624 END(ia32_syscall)
13625
13626diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
13627index 8e0ceec..af13504 100644
13628--- a/arch/x86/ia32/sys_ia32.c
13629+++ b/arch/x86/ia32/sys_ia32.c
13630@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
13631 */
13632 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
13633 {
13634- typeof(ubuf->st_uid) uid = 0;
13635- typeof(ubuf->st_gid) gid = 0;
13636+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
13637+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
13638 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
13639 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
13640 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
13641diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
13642index 372231c..a5aa1a1 100644
13643--- a/arch/x86/include/asm/alternative-asm.h
13644+++ b/arch/x86/include/asm/alternative-asm.h
13645@@ -18,6 +18,45 @@
13646 .endm
13647 #endif
13648
13649+#ifdef KERNEXEC_PLUGIN
13650+ .macro pax_force_retaddr_bts rip=0
13651+ btsq $63,\rip(%rsp)
13652+ .endm
13653+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
13654+ .macro pax_force_retaddr rip=0, reload=0
13655+ btsq $63,\rip(%rsp)
13656+ .endm
13657+ .macro pax_force_fptr ptr
13658+ btsq $63,\ptr
13659+ .endm
13660+ .macro pax_set_fptr_mask
13661+ .endm
13662+#endif
13663+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
13664+ .macro pax_force_retaddr rip=0, reload=0
13665+ .if \reload
13666+ pax_set_fptr_mask
13667+ .endif
13668+ orq %r10,\rip(%rsp)
13669+ .endm
13670+ .macro pax_force_fptr ptr
13671+ orq %r10,\ptr
13672+ .endm
13673+ .macro pax_set_fptr_mask
13674+ movabs $0x8000000000000000,%r10
13675+ .endm
13676+#endif
13677+#else
13678+ .macro pax_force_retaddr rip=0, reload=0
13679+ .endm
13680+ .macro pax_force_fptr ptr
13681+ .endm
13682+ .macro pax_force_retaddr_bts rip=0
13683+ .endm
13684+ .macro pax_set_fptr_mask
13685+ .endm
13686+#endif
13687+
13688 .macro altinstruction_entry orig alt feature orig_len alt_len
13689 .long \orig - .
13690 .long \alt - .
13691diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
13692index 58ed6d9..f1cbe58 100644
13693--- a/arch/x86/include/asm/alternative.h
13694+++ b/arch/x86/include/asm/alternative.h
13695@@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
13696 ".pushsection .discard,\"aw\",@progbits\n" \
13697 DISCARD_ENTRY(1) \
13698 ".popsection\n" \
13699- ".pushsection .altinstr_replacement, \"ax\"\n" \
13700+ ".pushsection .altinstr_replacement, \"a\"\n" \
13701 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
13702 ".popsection"
13703
13704@@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
13705 DISCARD_ENTRY(1) \
13706 DISCARD_ENTRY(2) \
13707 ".popsection\n" \
13708- ".pushsection .altinstr_replacement, \"ax\"\n" \
13709+ ".pushsection .altinstr_replacement, \"a\"\n" \
13710 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
13711 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
13712 ".popsection"
13713diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
13714index f8119b5..7209d5b 100644
13715--- a/arch/x86/include/asm/apic.h
13716+++ b/arch/x86/include/asm/apic.h
13717@@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
13718
13719 #ifdef CONFIG_X86_LOCAL_APIC
13720
13721-extern unsigned int apic_verbosity;
13722+extern int apic_verbosity;
13723 extern int local_apic_timer_c2_ok;
13724
13725 extern int disable_apic;
13726diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
13727index 20370c6..a2eb9b0 100644
13728--- a/arch/x86/include/asm/apm.h
13729+++ b/arch/x86/include/asm/apm.h
13730@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
13731 __asm__ __volatile__(APM_DO_ZERO_SEGS
13732 "pushl %%edi\n\t"
13733 "pushl %%ebp\n\t"
13734- "lcall *%%cs:apm_bios_entry\n\t"
13735+ "lcall *%%ss:apm_bios_entry\n\t"
13736 "setc %%al\n\t"
13737 "popl %%ebp\n\t"
13738 "popl %%edi\n\t"
13739@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
13740 __asm__ __volatile__(APM_DO_ZERO_SEGS
13741 "pushl %%edi\n\t"
13742 "pushl %%ebp\n\t"
13743- "lcall *%%cs:apm_bios_entry\n\t"
13744+ "lcall *%%ss:apm_bios_entry\n\t"
13745 "setc %%bl\n\t"
13746 "popl %%ebp\n\t"
13747 "popl %%edi\n\t"
13748diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
13749index 722aa3b..3a0bb27 100644
13750--- a/arch/x86/include/asm/atomic.h
13751+++ b/arch/x86/include/asm/atomic.h
13752@@ -22,7 +22,18 @@
13753 */
13754 static inline int atomic_read(const atomic_t *v)
13755 {
13756- return (*(volatile int *)&(v)->counter);
13757+ return (*(volatile const int *)&(v)->counter);
13758+}
13759+
13760+/**
13761+ * atomic_read_unchecked - read atomic variable
13762+ * @v: pointer of type atomic_unchecked_t
13763+ *
13764+ * Atomically reads the value of @v.
13765+ */
13766+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
13767+{
13768+ return (*(volatile const int *)&(v)->counter);
13769 }
13770
13771 /**
13772@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
13773 }
13774
13775 /**
13776+ * atomic_set_unchecked - set atomic variable
13777+ * @v: pointer of type atomic_unchecked_t
13778+ * @i: required value
13779+ *
13780+ * Atomically sets the value of @v to @i.
13781+ */
13782+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
13783+{
13784+ v->counter = i;
13785+}
13786+
13787+/**
13788 * atomic_add - add integer to atomic variable
13789 * @i: integer value to add
13790 * @v: pointer of type atomic_t
13791@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
13792 */
13793 static inline void atomic_add(int i, atomic_t *v)
13794 {
13795- asm volatile(LOCK_PREFIX "addl %1,%0"
13796+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
13797+
13798+#ifdef CONFIG_PAX_REFCOUNT
13799+ "jno 0f\n"
13800+ LOCK_PREFIX "subl %1,%0\n"
13801+ "int $4\n0:\n"
13802+ _ASM_EXTABLE(0b, 0b)
13803+#endif
13804+
13805+ : "+m" (v->counter)
13806+ : "ir" (i));
13807+}
13808+
13809+/**
13810+ * atomic_add_unchecked - add integer to atomic variable
13811+ * @i: integer value to add
13812+ * @v: pointer of type atomic_unchecked_t
13813+ *
13814+ * Atomically adds @i to @v.
13815+ */
13816+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
13817+{
13818+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
13819 : "+m" (v->counter)
13820 : "ir" (i));
13821 }
13822@@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
13823 */
13824 static inline void atomic_sub(int i, atomic_t *v)
13825 {
13826- asm volatile(LOCK_PREFIX "subl %1,%0"
13827+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
13828+
13829+#ifdef CONFIG_PAX_REFCOUNT
13830+ "jno 0f\n"
13831+ LOCK_PREFIX "addl %1,%0\n"
13832+ "int $4\n0:\n"
13833+ _ASM_EXTABLE(0b, 0b)
13834+#endif
13835+
13836+ : "+m" (v->counter)
13837+ : "ir" (i));
13838+}
13839+
13840+/**
13841+ * atomic_sub_unchecked - subtract integer from atomic variable
13842+ * @i: integer value to subtract
13843+ * @v: pointer of type atomic_unchecked_t
13844+ *
13845+ * Atomically subtracts @i from @v.
13846+ */
13847+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
13848+{
13849+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
13850 : "+m" (v->counter)
13851 : "ir" (i));
13852 }
13853@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
13854 {
13855 unsigned char c;
13856
13857- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
13858+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
13859+
13860+#ifdef CONFIG_PAX_REFCOUNT
13861+ "jno 0f\n"
13862+ LOCK_PREFIX "addl %2,%0\n"
13863+ "int $4\n0:\n"
13864+ _ASM_EXTABLE(0b, 0b)
13865+#endif
13866+
13867+ "sete %1\n"
13868 : "+m" (v->counter), "=qm" (c)
13869 : "ir" (i) : "memory");
13870 return c;
13871@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
13872 */
13873 static inline void atomic_inc(atomic_t *v)
13874 {
13875- asm volatile(LOCK_PREFIX "incl %0"
13876+ asm volatile(LOCK_PREFIX "incl %0\n"
13877+
13878+#ifdef CONFIG_PAX_REFCOUNT
13879+ "jno 0f\n"
13880+ LOCK_PREFIX "decl %0\n"
13881+ "int $4\n0:\n"
13882+ _ASM_EXTABLE(0b, 0b)
13883+#endif
13884+
13885+ : "+m" (v->counter));
13886+}
13887+
13888+/**
13889+ * atomic_inc_unchecked - increment atomic variable
13890+ * @v: pointer of type atomic_unchecked_t
13891+ *
13892+ * Atomically increments @v by 1.
13893+ */
13894+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
13895+{
13896+ asm volatile(LOCK_PREFIX "incl %0\n"
13897 : "+m" (v->counter));
13898 }
13899
13900@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
13901 */
13902 static inline void atomic_dec(atomic_t *v)
13903 {
13904- asm volatile(LOCK_PREFIX "decl %0"
13905+ asm volatile(LOCK_PREFIX "decl %0\n"
13906+
13907+#ifdef CONFIG_PAX_REFCOUNT
13908+ "jno 0f\n"
13909+ LOCK_PREFIX "incl %0\n"
13910+ "int $4\n0:\n"
13911+ _ASM_EXTABLE(0b, 0b)
13912+#endif
13913+
13914+ : "+m" (v->counter));
13915+}
13916+
13917+/**
13918+ * atomic_dec_unchecked - decrement atomic variable
13919+ * @v: pointer of type atomic_unchecked_t
13920+ *
13921+ * Atomically decrements @v by 1.
13922+ */
13923+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
13924+{
13925+ asm volatile(LOCK_PREFIX "decl %0\n"
13926 : "+m" (v->counter));
13927 }
13928
13929@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
13930 {
13931 unsigned char c;
13932
13933- asm volatile(LOCK_PREFIX "decl %0; sete %1"
13934+ asm volatile(LOCK_PREFIX "decl %0\n"
13935+
13936+#ifdef CONFIG_PAX_REFCOUNT
13937+ "jno 0f\n"
13938+ LOCK_PREFIX "incl %0\n"
13939+ "int $4\n0:\n"
13940+ _ASM_EXTABLE(0b, 0b)
13941+#endif
13942+
13943+ "sete %1\n"
13944 : "+m" (v->counter), "=qm" (c)
13945 : : "memory");
13946 return c != 0;
13947@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
13948 {
13949 unsigned char c;
13950
13951- asm volatile(LOCK_PREFIX "incl %0; sete %1"
13952+ asm volatile(LOCK_PREFIX "incl %0\n"
13953+
13954+#ifdef CONFIG_PAX_REFCOUNT
13955+ "jno 0f\n"
13956+ LOCK_PREFIX "decl %0\n"
13957+ "int $4\n0:\n"
13958+ _ASM_EXTABLE(0b, 0b)
13959+#endif
13960+
13961+ "sete %1\n"
13962+ : "+m" (v->counter), "=qm" (c)
13963+ : : "memory");
13964+ return c != 0;
13965+}
13966+
13967+/**
13968+ * atomic_inc_and_test_unchecked - increment and test
13969+ * @v: pointer of type atomic_unchecked_t
13970+ *
13971+ * Atomically increments @v by 1
13972+ * and returns true if the result is zero, or false for all
13973+ * other cases.
13974+ */
13975+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
13976+{
13977+ unsigned char c;
13978+
13979+ asm volatile(LOCK_PREFIX "incl %0\n"
13980+ "sete %1\n"
13981 : "+m" (v->counter), "=qm" (c)
13982 : : "memory");
13983 return c != 0;
13984@@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
13985 {
13986 unsigned char c;
13987
13988- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
13989+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
13990+
13991+#ifdef CONFIG_PAX_REFCOUNT
13992+ "jno 0f\n"
13993+ LOCK_PREFIX "subl %2,%0\n"
13994+ "int $4\n0:\n"
13995+ _ASM_EXTABLE(0b, 0b)
13996+#endif
13997+
13998+ "sets %1\n"
13999 : "+m" (v->counter), "=qm" (c)
14000 : "ir" (i) : "memory");
14001 return c;
14002@@ -172,6 +334,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
14003 */
14004 static inline int atomic_add_return(int i, atomic_t *v)
14005 {
14006+ return i + xadd_check_overflow(&v->counter, i);
14007+}
14008+
14009+/**
14010+ * atomic_add_return_unchecked - add integer and return
14011+ * @i: integer value to add
14012+ * @v: pointer of type atomic_unchecked_t
14013+ *
14014+ * Atomically adds @i to @v and returns @i + @v
14015+ */
14016+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
14017+{
14018 return i + xadd(&v->counter, i);
14019 }
14020
14021@@ -188,6 +362,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
14022 }
14023
14024 #define atomic_inc_return(v) (atomic_add_return(1, v))
14025+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
14026+{
14027+ return atomic_add_return_unchecked(1, v);
14028+}
14029 #define atomic_dec_return(v) (atomic_sub_return(1, v))
14030
14031 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
14032@@ -195,11 +373,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
14033 return cmpxchg(&v->counter, old, new);
14034 }
14035
14036+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
14037+{
14038+ return cmpxchg(&v->counter, old, new);
14039+}
14040+
14041 static inline int atomic_xchg(atomic_t *v, int new)
14042 {
14043 return xchg(&v->counter, new);
14044 }
14045
14046+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
14047+{
14048+ return xchg(&v->counter, new);
14049+}
14050+
14051 /**
14052 * __atomic_add_unless - add unless the number is already a given value
14053 * @v: pointer of type atomic_t
14054@@ -211,12 +399,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
14055 */
14056 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
14057 {
14058- int c, old;
14059+ int c, old, new;
14060 c = atomic_read(v);
14061 for (;;) {
14062- if (unlikely(c == (u)))
14063+ if (unlikely(c == u))
14064 break;
14065- old = atomic_cmpxchg((v), c, c + (a));
14066+
14067+ asm volatile("addl %2,%0\n"
14068+
14069+#ifdef CONFIG_PAX_REFCOUNT
14070+ "jno 0f\n"
14071+ "subl %2,%0\n"
14072+ "int $4\n0:\n"
14073+ _ASM_EXTABLE(0b, 0b)
14074+#endif
14075+
14076+ : "=r" (new)
14077+ : "0" (c), "ir" (a));
14078+
14079+ old = atomic_cmpxchg(v, c, new);
14080 if (likely(old == c))
14081 break;
14082 c = old;
14083@@ -225,6 +426,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
14084 }
14085
14086 /**
14087+ * atomic_inc_not_zero_hint - increment if not null
14088+ * @v: pointer of type atomic_t
14089+ * @hint: probable value of the atomic before the increment
14090+ *
14091+ * This version of atomic_inc_not_zero() gives a hint of probable
14092+ * value of the atomic. This helps processor to not read the memory
14093+ * before doing the atomic read/modify/write cycle, lowering
14094+ * number of bus transactions on some arches.
14095+ *
14096+ * Returns: 0 if increment was not done, 1 otherwise.
14097+ */
14098+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
14099+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
14100+{
14101+ int val, c = hint, new;
14102+
14103+ /* sanity test, should be removed by compiler if hint is a constant */
14104+ if (!hint)
14105+ return __atomic_add_unless(v, 1, 0);
14106+
14107+ do {
14108+ asm volatile("incl %0\n"
14109+
14110+#ifdef CONFIG_PAX_REFCOUNT
14111+ "jno 0f\n"
14112+ "decl %0\n"
14113+ "int $4\n0:\n"
14114+ _ASM_EXTABLE(0b, 0b)
14115+#endif
14116+
14117+ : "=r" (new)
14118+ : "0" (c));
14119+
14120+ val = atomic_cmpxchg(v, c, new);
14121+ if (val == c)
14122+ return 1;
14123+ c = val;
14124+ } while (c);
14125+
14126+ return 0;
14127+}
14128+
14129+/**
14130 * atomic_inc_short - increment of a short integer
14131 * @v: pointer to type int
14132 *
14133@@ -253,14 +497,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
14134 #endif
14135
14136 /* These are x86-specific, used by some header files */
14137-#define atomic_clear_mask(mask, addr) \
14138- asm volatile(LOCK_PREFIX "andl %0,%1" \
14139- : : "r" (~(mask)), "m" (*(addr)) : "memory")
14140+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
14141+{
14142+ asm volatile(LOCK_PREFIX "andl %1,%0"
14143+ : "+m" (v->counter)
14144+ : "r" (~(mask))
14145+ : "memory");
14146+}
14147
14148-#define atomic_set_mask(mask, addr) \
14149- asm volatile(LOCK_PREFIX "orl %0,%1" \
14150- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
14151- : "memory")
14152+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
14153+{
14154+ asm volatile(LOCK_PREFIX "andl %1,%0"
14155+ : "+m" (v->counter)
14156+ : "r" (~(mask))
14157+ : "memory");
14158+}
14159+
14160+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
14161+{
14162+ asm volatile(LOCK_PREFIX "orl %1,%0"
14163+ : "+m" (v->counter)
14164+ : "r" (mask)
14165+ : "memory");
14166+}
14167+
14168+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
14169+{
14170+ asm volatile(LOCK_PREFIX "orl %1,%0"
14171+ : "+m" (v->counter)
14172+ : "r" (mask)
14173+ : "memory");
14174+}
14175
14176 /* Atomic operations are already serializing on x86 */
14177 #define smp_mb__before_atomic_dec() barrier()
14178diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
14179index b154de7..aadebd8 100644
14180--- a/arch/x86/include/asm/atomic64_32.h
14181+++ b/arch/x86/include/asm/atomic64_32.h
14182@@ -12,6 +12,14 @@ typedef struct {
14183 u64 __aligned(8) counter;
14184 } atomic64_t;
14185
14186+#ifdef CONFIG_PAX_REFCOUNT
14187+typedef struct {
14188+ u64 __aligned(8) counter;
14189+} atomic64_unchecked_t;
14190+#else
14191+typedef atomic64_t atomic64_unchecked_t;
14192+#endif
14193+
14194 #define ATOMIC64_INIT(val) { (val) }
14195
14196 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
14197@@ -37,21 +45,31 @@ typedef struct {
14198 ATOMIC64_DECL_ONE(sym##_386)
14199
14200 ATOMIC64_DECL_ONE(add_386);
14201+ATOMIC64_DECL_ONE(add_unchecked_386);
14202 ATOMIC64_DECL_ONE(sub_386);
14203+ATOMIC64_DECL_ONE(sub_unchecked_386);
14204 ATOMIC64_DECL_ONE(inc_386);
14205+ATOMIC64_DECL_ONE(inc_unchecked_386);
14206 ATOMIC64_DECL_ONE(dec_386);
14207+ATOMIC64_DECL_ONE(dec_unchecked_386);
14208 #endif
14209
14210 #define alternative_atomic64(f, out, in...) \
14211 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
14212
14213 ATOMIC64_DECL(read);
14214+ATOMIC64_DECL(read_unchecked);
14215 ATOMIC64_DECL(set);
14216+ATOMIC64_DECL(set_unchecked);
14217 ATOMIC64_DECL(xchg);
14218 ATOMIC64_DECL(add_return);
14219+ATOMIC64_DECL(add_return_unchecked);
14220 ATOMIC64_DECL(sub_return);
14221+ATOMIC64_DECL(sub_return_unchecked);
14222 ATOMIC64_DECL(inc_return);
14223+ATOMIC64_DECL(inc_return_unchecked);
14224 ATOMIC64_DECL(dec_return);
14225+ATOMIC64_DECL(dec_return_unchecked);
14226 ATOMIC64_DECL(dec_if_positive);
14227 ATOMIC64_DECL(inc_not_zero);
14228 ATOMIC64_DECL(add_unless);
14229@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
14230 }
14231
14232 /**
14233+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
14234+ * @p: pointer to type atomic64_unchecked_t
14235+ * @o: expected value
14236+ * @n: new value
14237+ *
14238+ * Atomically sets @v to @n if it was equal to @o and returns
14239+ * the old value.
14240+ */
14241+
14242+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
14243+{
14244+ return cmpxchg64(&v->counter, o, n);
14245+}
14246+
14247+/**
14248 * atomic64_xchg - xchg atomic64 variable
14249 * @v: pointer to type atomic64_t
14250 * @n: value to assign
14251@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
14252 }
14253
14254 /**
14255+ * atomic64_set_unchecked - set atomic64 variable
14256+ * @v: pointer to type atomic64_unchecked_t
14257+ * @n: value to assign
14258+ *
14259+ * Atomically sets the value of @v to @n.
14260+ */
14261+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
14262+{
14263+ unsigned high = (unsigned)(i >> 32);
14264+ unsigned low = (unsigned)i;
14265+ alternative_atomic64(set, /* no output */,
14266+ "S" (v), "b" (low), "c" (high)
14267+ : "eax", "edx", "memory");
14268+}
14269+
14270+/**
14271 * atomic64_read - read atomic64 variable
14272 * @v: pointer to type atomic64_t
14273 *
14274@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
14275 }
14276
14277 /**
14278+ * atomic64_read_unchecked - read atomic64 variable
14279+ * @v: pointer to type atomic64_unchecked_t
14280+ *
14281+ * Atomically reads the value of @v and returns it.
14282+ */
14283+static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
14284+{
14285+ long long r;
14286+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
14287+ return r;
14288+ }
14289+
14290+/**
14291 * atomic64_add_return - add and return
14292 * @i: integer value to add
14293 * @v: pointer to type atomic64_t
14294@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
14295 return i;
14296 }
14297
14298+/**
14299+ * atomic64_add_return_unchecked - add and return
14300+ * @i: integer value to add
14301+ * @v: pointer to type atomic64_unchecked_t
14302+ *
14303+ * Atomically adds @i to @v and returns @i + *@v
14304+ */
14305+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
14306+{
14307+ alternative_atomic64(add_return_unchecked,
14308+ ASM_OUTPUT2("+A" (i), "+c" (v)),
14309+ ASM_NO_INPUT_CLOBBER("memory"));
14310+ return i;
14311+}
14312+
14313 /*
14314 * Other variants with different arithmetic operators:
14315 */
14316@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
14317 return a;
14318 }
14319
14320+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
14321+{
14322+ long long a;
14323+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
14324+ "S" (v) : "memory", "ecx");
14325+ return a;
14326+}
14327+
14328 static inline long long atomic64_dec_return(atomic64_t *v)
14329 {
14330 long long a;
14331@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
14332 }
14333
14334 /**
14335+ * atomic64_add_unchecked - add integer to atomic64 variable
14336+ * @i: integer value to add
14337+ * @v: pointer to type atomic64_unchecked_t
14338+ *
14339+ * Atomically adds @i to @v.
14340+ */
14341+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
14342+{
14343+ __alternative_atomic64(add_unchecked, add_return_unchecked,
14344+ ASM_OUTPUT2("+A" (i), "+c" (v)),
14345+ ASM_NO_INPUT_CLOBBER("memory"));
14346+ return i;
14347+}
14348+
14349+/**
14350 * atomic64_sub - subtract the atomic64 variable
14351 * @i: integer value to subtract
14352 * @v: pointer to type atomic64_t
14353diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
14354index 0e1cbfc..5623683 100644
14355--- a/arch/x86/include/asm/atomic64_64.h
14356+++ b/arch/x86/include/asm/atomic64_64.h
14357@@ -18,7 +18,19 @@
14358 */
14359 static inline long atomic64_read(const atomic64_t *v)
14360 {
14361- return (*(volatile long *)&(v)->counter);
14362+ return (*(volatile const long *)&(v)->counter);
14363+}
14364+
14365+/**
14366+ * atomic64_read_unchecked - read atomic64 variable
14367+ * @v: pointer of type atomic64_unchecked_t
14368+ *
14369+ * Atomically reads the value of @v.
14370+ * Doesn't imply a read memory barrier.
14371+ */
14372+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
14373+{
14374+ return (*(volatile const long *)&(v)->counter);
14375 }
14376
14377 /**
14378@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
14379 }
14380
14381 /**
14382+ * atomic64_set_unchecked - set atomic64 variable
14383+ * @v: pointer to type atomic64_unchecked_t
14384+ * @i: required value
14385+ *
14386+ * Atomically sets the value of @v to @i.
14387+ */
14388+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
14389+{
14390+ v->counter = i;
14391+}
14392+
14393+/**
14394 * atomic64_add - add integer to atomic64 variable
14395 * @i: integer value to add
14396 * @v: pointer to type atomic64_t
14397@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
14398 */
14399 static inline void atomic64_add(long i, atomic64_t *v)
14400 {
14401+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
14402+
14403+#ifdef CONFIG_PAX_REFCOUNT
14404+ "jno 0f\n"
14405+ LOCK_PREFIX "subq %1,%0\n"
14406+ "int $4\n0:\n"
14407+ _ASM_EXTABLE(0b, 0b)
14408+#endif
14409+
14410+ : "=m" (v->counter)
14411+ : "er" (i), "m" (v->counter));
14412+}
14413+
14414+/**
14415+ * atomic64_add_unchecked - add integer to atomic64 variable
14416+ * @i: integer value to add
14417+ * @v: pointer to type atomic64_unchecked_t
14418+ *
14419+ * Atomically adds @i to @v.
14420+ */
14421+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
14422+{
14423 asm volatile(LOCK_PREFIX "addq %1,%0"
14424 : "=m" (v->counter)
14425 : "er" (i), "m" (v->counter));
14426@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
14427 */
14428 static inline void atomic64_sub(long i, atomic64_t *v)
14429 {
14430- asm volatile(LOCK_PREFIX "subq %1,%0"
14431+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
14432+
14433+#ifdef CONFIG_PAX_REFCOUNT
14434+ "jno 0f\n"
14435+ LOCK_PREFIX "addq %1,%0\n"
14436+ "int $4\n0:\n"
14437+ _ASM_EXTABLE(0b, 0b)
14438+#endif
14439+
14440+ : "=m" (v->counter)
14441+ : "er" (i), "m" (v->counter));
14442+}
14443+
14444+/**
14445+ * atomic64_sub_unchecked - subtract the atomic64 variable
14446+ * @i: integer value to subtract
14447+ * @v: pointer to type atomic64_unchecked_t
14448+ *
14449+ * Atomically subtracts @i from @v.
14450+ */
14451+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
14452+{
14453+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
14454 : "=m" (v->counter)
14455 : "er" (i), "m" (v->counter));
14456 }
14457@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
14458 {
14459 unsigned char c;
14460
14461- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
14462+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
14463+
14464+#ifdef CONFIG_PAX_REFCOUNT
14465+ "jno 0f\n"
14466+ LOCK_PREFIX "addq %2,%0\n"
14467+ "int $4\n0:\n"
14468+ _ASM_EXTABLE(0b, 0b)
14469+#endif
14470+
14471+ "sete %1\n"
14472 : "=m" (v->counter), "=qm" (c)
14473 : "er" (i), "m" (v->counter) : "memory");
14474 return c;
14475@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
14476 */
14477 static inline void atomic64_inc(atomic64_t *v)
14478 {
14479+ asm volatile(LOCK_PREFIX "incq %0\n"
14480+
14481+#ifdef CONFIG_PAX_REFCOUNT
14482+ "jno 0f\n"
14483+ LOCK_PREFIX "decq %0\n"
14484+ "int $4\n0:\n"
14485+ _ASM_EXTABLE(0b, 0b)
14486+#endif
14487+
14488+ : "=m" (v->counter)
14489+ : "m" (v->counter));
14490+}
14491+
14492+/**
14493+ * atomic64_inc_unchecked - increment atomic64 variable
14494+ * @v: pointer to type atomic64_unchecked_t
14495+ *
14496+ * Atomically increments @v by 1.
14497+ */
14498+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
14499+{
14500 asm volatile(LOCK_PREFIX "incq %0"
14501 : "=m" (v->counter)
14502 : "m" (v->counter));
14503@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
14504 */
14505 static inline void atomic64_dec(atomic64_t *v)
14506 {
14507- asm volatile(LOCK_PREFIX "decq %0"
14508+ asm volatile(LOCK_PREFIX "decq %0\n"
14509+
14510+#ifdef CONFIG_PAX_REFCOUNT
14511+ "jno 0f\n"
14512+ LOCK_PREFIX "incq %0\n"
14513+ "int $4\n0:\n"
14514+ _ASM_EXTABLE(0b, 0b)
14515+#endif
14516+
14517+ : "=m" (v->counter)
14518+ : "m" (v->counter));
14519+}
14520+
14521+/**
14522+ * atomic64_dec_unchecked - decrement atomic64 variable
14523+ * @v: pointer to type atomic64_t
14524+ *
14525+ * Atomically decrements @v by 1.
14526+ */
14527+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
14528+{
14529+ asm volatile(LOCK_PREFIX "decq %0\n"
14530 : "=m" (v->counter)
14531 : "m" (v->counter));
14532 }
14533@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
14534 {
14535 unsigned char c;
14536
14537- asm volatile(LOCK_PREFIX "decq %0; sete %1"
14538+ asm volatile(LOCK_PREFIX "decq %0\n"
14539+
14540+#ifdef CONFIG_PAX_REFCOUNT
14541+ "jno 0f\n"
14542+ LOCK_PREFIX "incq %0\n"
14543+ "int $4\n0:\n"
14544+ _ASM_EXTABLE(0b, 0b)
14545+#endif
14546+
14547+ "sete %1\n"
14548 : "=m" (v->counter), "=qm" (c)
14549 : "m" (v->counter) : "memory");
14550 return c != 0;
14551@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
14552 {
14553 unsigned char c;
14554
14555- asm volatile(LOCK_PREFIX "incq %0; sete %1"
14556+ asm volatile(LOCK_PREFIX "incq %0\n"
14557+
14558+#ifdef CONFIG_PAX_REFCOUNT
14559+ "jno 0f\n"
14560+ LOCK_PREFIX "decq %0\n"
14561+ "int $4\n0:\n"
14562+ _ASM_EXTABLE(0b, 0b)
14563+#endif
14564+
14565+ "sete %1\n"
14566 : "=m" (v->counter), "=qm" (c)
14567 : "m" (v->counter) : "memory");
14568 return c != 0;
14569@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
14570 {
14571 unsigned char c;
14572
14573- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
14574+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
14575+
14576+#ifdef CONFIG_PAX_REFCOUNT
14577+ "jno 0f\n"
14578+ LOCK_PREFIX "subq %2,%0\n"
14579+ "int $4\n0:\n"
14580+ _ASM_EXTABLE(0b, 0b)
14581+#endif
14582+
14583+ "sets %1\n"
14584 : "=m" (v->counter), "=qm" (c)
14585 : "er" (i), "m" (v->counter) : "memory");
14586 return c;
14587@@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
14588 */
14589 static inline long atomic64_add_return(long i, atomic64_t *v)
14590 {
14591+ return i + xadd_check_overflow(&v->counter, i);
14592+}
14593+
14594+/**
14595+ * atomic64_add_return_unchecked - add and return
14596+ * @i: integer value to add
14597+ * @v: pointer to type atomic64_unchecked_t
14598+ *
14599+ * Atomically adds @i to @v and returns @i + @v
14600+ */
14601+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
14602+{
14603 return i + xadd(&v->counter, i);
14604 }
14605
14606@@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
14607 }
14608
14609 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
14610+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
14611+{
14612+ return atomic64_add_return_unchecked(1, v);
14613+}
14614 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
14615
14616 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
14617@@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
14618 return cmpxchg(&v->counter, old, new);
14619 }
14620
14621+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
14622+{
14623+ return cmpxchg(&v->counter, old, new);
14624+}
14625+
14626 static inline long atomic64_xchg(atomic64_t *v, long new)
14627 {
14628 return xchg(&v->counter, new);
14629@@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
14630 */
14631 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
14632 {
14633- long c, old;
14634+ long c, old, new;
14635 c = atomic64_read(v);
14636 for (;;) {
14637- if (unlikely(c == (u)))
14638+ if (unlikely(c == u))
14639 break;
14640- old = atomic64_cmpxchg((v), c, c + (a));
14641+
14642+ asm volatile("add %2,%0\n"
14643+
14644+#ifdef CONFIG_PAX_REFCOUNT
14645+ "jno 0f\n"
14646+ "sub %2,%0\n"
14647+ "int $4\n0:\n"
14648+ _ASM_EXTABLE(0b, 0b)
14649+#endif
14650+
14651+ : "=r" (new)
14652+ : "0" (c), "ir" (a));
14653+
14654+ old = atomic64_cmpxchg(v, c, new);
14655 if (likely(old == c))
14656 break;
14657 c = old;
14658 }
14659- return c != (u);
14660+ return c != u;
14661 }
14662
14663 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
14664diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
14665index 6dfd019..28e188d 100644
14666--- a/arch/x86/include/asm/bitops.h
14667+++ b/arch/x86/include/asm/bitops.h
14668@@ -40,7 +40,7 @@
14669 * a mask operation on a byte.
14670 */
14671 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
14672-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
14673+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
14674 #define CONST_MASK(nr) (1 << ((nr) & 7))
14675
14676 /**
14677@@ -486,7 +486,7 @@ static inline int fls(int x)
14678 * at position 64.
14679 */
14680 #ifdef CONFIG_X86_64
14681-static __always_inline int fls64(__u64 x)
14682+static __always_inline long fls64(__u64 x)
14683 {
14684 int bitpos = -1;
14685 /*
14686diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
14687index 4fa687a..60f2d39 100644
14688--- a/arch/x86/include/asm/boot.h
14689+++ b/arch/x86/include/asm/boot.h
14690@@ -6,10 +6,15 @@
14691 #include <uapi/asm/boot.h>
14692
14693 /* Physical address where kernel should be loaded. */
14694-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
14695+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
14696 + (CONFIG_PHYSICAL_ALIGN - 1)) \
14697 & ~(CONFIG_PHYSICAL_ALIGN - 1))
14698
14699+#ifndef __ASSEMBLY__
14700+extern unsigned char __LOAD_PHYSICAL_ADDR[];
14701+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
14702+#endif
14703+
14704 /* Minimum kernel alignment, as a power of two */
14705 #ifdef CONFIG_X86_64
14706 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
14707diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
14708index 48f99f1..d78ebf9 100644
14709--- a/arch/x86/include/asm/cache.h
14710+++ b/arch/x86/include/asm/cache.h
14711@@ -5,12 +5,13 @@
14712
14713 /* L1 cache line size */
14714 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
14715-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
14716+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
14717
14718 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
14719+#define __read_only __attribute__((__section__(".data..read_only")))
14720
14721 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
14722-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
14723+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
14724
14725 #ifdef CONFIG_X86_VSMP
14726 #ifdef CONFIG_SMP
14727diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
14728index 9863ee3..4a1f8e1 100644
14729--- a/arch/x86/include/asm/cacheflush.h
14730+++ b/arch/x86/include/asm/cacheflush.h
14731@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
14732 unsigned long pg_flags = pg->flags & _PGMT_MASK;
14733
14734 if (pg_flags == _PGMT_DEFAULT)
14735- return -1;
14736+ return ~0UL;
14737 else if (pg_flags == _PGMT_WC)
14738 return _PAGE_CACHE_WC;
14739 else if (pg_flags == _PGMT_UC_MINUS)
14740diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
14741index 46fc474..b02b0f9 100644
14742--- a/arch/x86/include/asm/checksum_32.h
14743+++ b/arch/x86/include/asm/checksum_32.h
14744@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
14745 int len, __wsum sum,
14746 int *src_err_ptr, int *dst_err_ptr);
14747
14748+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
14749+ int len, __wsum sum,
14750+ int *src_err_ptr, int *dst_err_ptr);
14751+
14752+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
14753+ int len, __wsum sum,
14754+ int *src_err_ptr, int *dst_err_ptr);
14755+
14756 /*
14757 * Note: when you get a NULL pointer exception here this means someone
14758 * passed in an incorrect kernel address to one of these functions.
14759@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
14760 int *err_ptr)
14761 {
14762 might_sleep();
14763- return csum_partial_copy_generic((__force void *)src, dst,
14764+ return csum_partial_copy_generic_from_user((__force void *)src, dst,
14765 len, sum, err_ptr, NULL);
14766 }
14767
14768@@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
14769 {
14770 might_sleep();
14771 if (access_ok(VERIFY_WRITE, dst, len))
14772- return csum_partial_copy_generic(src, (__force void *)dst,
14773+ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
14774 len, sum, NULL, err_ptr);
14775
14776 if (len)
14777diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
14778index d47786a..ce1b05d 100644
14779--- a/arch/x86/include/asm/cmpxchg.h
14780+++ b/arch/x86/include/asm/cmpxchg.h
14781@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
14782 __compiletime_error("Bad argument size for cmpxchg");
14783 extern void __xadd_wrong_size(void)
14784 __compiletime_error("Bad argument size for xadd");
14785+extern void __xadd_check_overflow_wrong_size(void)
14786+ __compiletime_error("Bad argument size for xadd_check_overflow");
14787 extern void __add_wrong_size(void)
14788 __compiletime_error("Bad argument size for add");
14789+extern void __add_check_overflow_wrong_size(void)
14790+ __compiletime_error("Bad argument size for add_check_overflow");
14791
14792 /*
14793 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
14794@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
14795 __ret; \
14796 })
14797
14798+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
14799+ ({ \
14800+ __typeof__ (*(ptr)) __ret = (arg); \
14801+ switch (sizeof(*(ptr))) { \
14802+ case __X86_CASE_L: \
14803+ asm volatile (lock #op "l %0, %1\n" \
14804+ "jno 0f\n" \
14805+ "mov %0,%1\n" \
14806+ "int $4\n0:\n" \
14807+ _ASM_EXTABLE(0b, 0b) \
14808+ : "+r" (__ret), "+m" (*(ptr)) \
14809+ : : "memory", "cc"); \
14810+ break; \
14811+ case __X86_CASE_Q: \
14812+ asm volatile (lock #op "q %q0, %1\n" \
14813+ "jno 0f\n" \
14814+ "mov %0,%1\n" \
14815+ "int $4\n0:\n" \
14816+ _ASM_EXTABLE(0b, 0b) \
14817+ : "+r" (__ret), "+m" (*(ptr)) \
14818+ : : "memory", "cc"); \
14819+ break; \
14820+ default: \
14821+ __ ## op ## _check_overflow_wrong_size(); \
14822+ } \
14823+ __ret; \
14824+ })
14825+
14826 /*
14827 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
14828 * Since this is generally used to protect other memory information, we
14829@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
14830 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
14831 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
14832
14833+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
14834+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
14835+
14836 #define __add(ptr, inc, lock) \
14837 ({ \
14838 __typeof__ (*(ptr)) __ret = (inc); \
14839diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
14840index 59c6c40..5e0b22c 100644
14841--- a/arch/x86/include/asm/compat.h
14842+++ b/arch/x86/include/asm/compat.h
14843@@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
14844 typedef u32 compat_uint_t;
14845 typedef u32 compat_ulong_t;
14846 typedef u64 __attribute__((aligned(4))) compat_u64;
14847-typedef u32 compat_uptr_t;
14848+typedef u32 __user compat_uptr_t;
14849
14850 struct compat_timespec {
14851 compat_time_t tv_sec;
14852diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
14853index 47538a6..44902d1 100644
14854--- a/arch/x86/include/asm/cpufeature.h
14855+++ b/arch/x86/include/asm/cpufeature.h
14856@@ -203,7 +203,7 @@
14857 #define X86_FEATURE_DECODEASSISTS (8*32+12) /* AMD Decode Assists support */
14858 #define X86_FEATURE_PAUSEFILTER (8*32+13) /* AMD filtered pause intercept */
14859 #define X86_FEATURE_PFTHRESHOLD (8*32+14) /* AMD pause filter threshold */
14860-
14861+#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
14862
14863 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
14864 #define X86_FEATURE_FSGSBASE (9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
14865@@ -211,7 +211,7 @@
14866 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
14867 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
14868 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
14869-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
14870+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
14871 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
14872 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
14873 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
14874@@ -353,6 +353,7 @@ extern const char * const x86_power_flags[32];
14875 #undef cpu_has_centaur_mcr
14876 #define cpu_has_centaur_mcr 0
14877
14878+#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
14879 #endif /* CONFIG_X86_64 */
14880
14881 #if __GNUC__ >= 4
14882@@ -403,7 +404,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
14883
14884 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
14885 t_warn:
14886- warn_pre_alternatives();
14887+ if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
14888+ warn_pre_alternatives();
14889 return false;
14890 #endif
14891 #else /* GCC_VERSION >= 40500 */
14892@@ -421,7 +423,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
14893 ".section .discard,\"aw\",@progbits\n"
14894 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
14895 ".previous\n"
14896- ".section .altinstr_replacement,\"ax\"\n"
14897+ ".section .altinstr_replacement,\"a\"\n"
14898 "3: movb $1,%0\n"
14899 "4:\n"
14900 ".previous\n"
14901@@ -457,7 +459,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
14902 " .byte 2b - 1b\n" /* src len */
14903 " .byte 4f - 3f\n" /* repl len */
14904 ".previous\n"
14905- ".section .altinstr_replacement,\"ax\"\n"
14906+ ".section .altinstr_replacement,\"a\"\n"
14907 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
14908 "4:\n"
14909 ".previous\n"
14910@@ -490,7 +492,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
14911 ".section .discard,\"aw\",@progbits\n"
14912 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
14913 ".previous\n"
14914- ".section .altinstr_replacement,\"ax\"\n"
14915+ ".section .altinstr_replacement,\"a\"\n"
14916 "3: movb $0,%0\n"
14917 "4:\n"
14918 ".previous\n"
14919@@ -504,7 +506,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
14920 ".section .discard,\"aw\",@progbits\n"
14921 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
14922 ".previous\n"
14923- ".section .altinstr_replacement,\"ax\"\n"
14924+ ".section .altinstr_replacement,\"a\"\n"
14925 "5: movb $1,%0\n"
14926 "6:\n"
14927 ".previous\n"
14928diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
14929index b90e5df..b462c91 100644
14930--- a/arch/x86/include/asm/desc.h
14931+++ b/arch/x86/include/asm/desc.h
14932@@ -4,6 +4,7 @@
14933 #include <asm/desc_defs.h>
14934 #include <asm/ldt.h>
14935 #include <asm/mmu.h>
14936+#include <asm/pgtable.h>
14937
14938 #include <linux/smp.h>
14939 #include <linux/percpu.h>
14940@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
14941
14942 desc->type = (info->read_exec_only ^ 1) << 1;
14943 desc->type |= info->contents << 2;
14944+ desc->type |= info->seg_not_present ^ 1;
14945
14946 desc->s = 1;
14947 desc->dpl = 0x3;
14948@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
14949 }
14950
14951 extern struct desc_ptr idt_descr;
14952-extern gate_desc idt_table[];
14953-extern struct desc_ptr debug_idt_descr;
14954-extern gate_desc debug_idt_table[];
14955-
14956-struct gdt_page {
14957- struct desc_struct gdt[GDT_ENTRIES];
14958-} __attribute__((aligned(PAGE_SIZE)));
14959-
14960-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
14961+extern gate_desc idt_table[IDT_ENTRIES];
14962+extern const struct desc_ptr debug_idt_descr;
14963+extern gate_desc debug_idt_table[IDT_ENTRIES];
14964
14965+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
14966 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
14967 {
14968- return per_cpu(gdt_page, cpu).gdt;
14969+ return cpu_gdt_table[cpu];
14970 }
14971
14972 #ifdef CONFIG_X86_64
14973@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
14974 unsigned long base, unsigned dpl, unsigned flags,
14975 unsigned short seg)
14976 {
14977- gate->a = (seg << 16) | (base & 0xffff);
14978- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
14979+ gate->gate.offset_low = base;
14980+ gate->gate.seg = seg;
14981+ gate->gate.reserved = 0;
14982+ gate->gate.type = type;
14983+ gate->gate.s = 0;
14984+ gate->gate.dpl = dpl;
14985+ gate->gate.p = 1;
14986+ gate->gate.offset_high = base >> 16;
14987 }
14988
14989 #endif
14990@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
14991
14992 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
14993 {
14994+ pax_open_kernel();
14995 memcpy(&idt[entry], gate, sizeof(*gate));
14996+ pax_close_kernel();
14997 }
14998
14999 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
15000 {
15001+ pax_open_kernel();
15002 memcpy(&ldt[entry], desc, 8);
15003+ pax_close_kernel();
15004 }
15005
15006 static inline void
15007@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
15008 default: size = sizeof(*gdt); break;
15009 }
15010
15011+ pax_open_kernel();
15012 memcpy(&gdt[entry], desc, size);
15013+ pax_close_kernel();
15014 }
15015
15016 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
15017@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
15018
15019 static inline void native_load_tr_desc(void)
15020 {
15021+ pax_open_kernel();
15022 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
15023+ pax_close_kernel();
15024 }
15025
15026 static inline void native_load_gdt(const struct desc_ptr *dtr)
15027@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
15028 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
15029 unsigned int i;
15030
15031+ pax_open_kernel();
15032 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
15033 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
15034+ pax_close_kernel();
15035 }
15036
15037 #define _LDT_empty(info) \
15038@@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
15039 preempt_enable();
15040 }
15041
15042-static inline unsigned long get_desc_base(const struct desc_struct *desc)
15043+static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
15044 {
15045 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
15046 }
15047@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
15048 }
15049
15050 #ifdef CONFIG_X86_64
15051-static inline void set_nmi_gate(int gate, void *addr)
15052+static inline void set_nmi_gate(int gate, const void *addr)
15053 {
15054 gate_desc s;
15055
15056@@ -321,8 +334,8 @@ static inline void set_nmi_gate(int gate, void *addr)
15057 #endif
15058
15059 #ifdef CONFIG_TRACING
15060-extern struct desc_ptr trace_idt_descr;
15061-extern gate_desc trace_idt_table[];
15062+extern const struct desc_ptr trace_idt_descr;
15063+extern gate_desc trace_idt_table[IDT_ENTRIES];
15064 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
15065 {
15066 write_idt_entry(trace_idt_table, entry, gate);
15067@@ -333,7 +346,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
15068 }
15069 #endif
15070
15071-static inline void _set_gate(int gate, unsigned type, void *addr,
15072+static inline void _set_gate(int gate, unsigned type, const void *addr,
15073 unsigned dpl, unsigned ist, unsigned seg)
15074 {
15075 gate_desc s;
15076@@ -353,7 +366,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
15077 * Pentium F0 0F bugfix can have resulted in the mapped
15078 * IDT being write-protected.
15079 */
15080-static inline void set_intr_gate(unsigned int n, void *addr)
15081+static inline void set_intr_gate(unsigned int n, const void *addr)
15082 {
15083 BUG_ON((unsigned)n > 0xFF);
15084 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
15085@@ -410,19 +423,19 @@ static inline void __alloc_intr_gate(unsigned int n, void *addr)
15086 /*
15087 * This routine sets up an interrupt gate at directory privilege level 3.
15088 */
15089-static inline void set_system_intr_gate(unsigned int n, void *addr)
15090+static inline void set_system_intr_gate(unsigned int n, const void *addr)
15091 {
15092 BUG_ON((unsigned)n > 0xFF);
15093 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
15094 }
15095
15096-static inline void set_system_trap_gate(unsigned int n, void *addr)
15097+static inline void set_system_trap_gate(unsigned int n, const void *addr)
15098 {
15099 BUG_ON((unsigned)n > 0xFF);
15100 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
15101 }
15102
15103-static inline void set_trap_gate(unsigned int n, void *addr)
15104+static inline void set_trap_gate(unsigned int n, const void *addr)
15105 {
15106 BUG_ON((unsigned)n > 0xFF);
15107 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
15108@@ -431,16 +444,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
15109 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
15110 {
15111 BUG_ON((unsigned)n > 0xFF);
15112- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
15113+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
15114 }
15115
15116-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
15117+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
15118 {
15119 BUG_ON((unsigned)n > 0xFF);
15120 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
15121 }
15122
15123-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
15124+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
15125 {
15126 BUG_ON((unsigned)n > 0xFF);
15127 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
15128@@ -512,4 +525,17 @@ static inline void load_current_idt(void)
15129 else
15130 load_idt((const struct desc_ptr *)&idt_descr);
15131 }
15132+
15133+#ifdef CONFIG_X86_32
15134+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
15135+{
15136+ struct desc_struct d;
15137+
15138+ if (likely(limit))
15139+ limit = (limit - 1UL) >> PAGE_SHIFT;
15140+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
15141+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
15142+}
15143+#endif
15144+
15145 #endif /* _ASM_X86_DESC_H */
15146diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
15147index 278441f..b95a174 100644
15148--- a/arch/x86/include/asm/desc_defs.h
15149+++ b/arch/x86/include/asm/desc_defs.h
15150@@ -31,6 +31,12 @@ struct desc_struct {
15151 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
15152 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
15153 };
15154+ struct {
15155+ u16 offset_low;
15156+ u16 seg;
15157+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
15158+ unsigned offset_high: 16;
15159+ } gate;
15160 };
15161 } __attribute__((packed));
15162
15163diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
15164index ced283a..ffe04cc 100644
15165--- a/arch/x86/include/asm/div64.h
15166+++ b/arch/x86/include/asm/div64.h
15167@@ -39,7 +39,7 @@
15168 __mod; \
15169 })
15170
15171-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
15172+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
15173 {
15174 union {
15175 u64 v64;
15176diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
15177index 9c999c1..3860cb8 100644
15178--- a/arch/x86/include/asm/elf.h
15179+++ b/arch/x86/include/asm/elf.h
15180@@ -243,7 +243,25 @@ extern int force_personality32;
15181 the loader. We need to make sure that it is out of the way of the program
15182 that it will "exec", and that there is sufficient room for the brk. */
15183
15184+#ifdef CONFIG_PAX_SEGMEXEC
15185+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
15186+#else
15187 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
15188+#endif
15189+
15190+#ifdef CONFIG_PAX_ASLR
15191+#ifdef CONFIG_X86_32
15192+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
15193+
15194+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
15195+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
15196+#else
15197+#define PAX_ELF_ET_DYN_BASE 0x400000UL
15198+
15199+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
15200+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
15201+#endif
15202+#endif
15203
15204 /* This yields a mask that user programs can use to figure out what
15205 instruction set this CPU supports. This could be done in user space,
15206@@ -296,16 +314,12 @@ do { \
15207
15208 #define ARCH_DLINFO \
15209 do { \
15210- if (vdso_enabled) \
15211- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
15212- (unsigned long)current->mm->context.vdso); \
15213+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
15214 } while (0)
15215
15216 #define ARCH_DLINFO_X32 \
15217 do { \
15218- if (vdso_enabled) \
15219- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
15220- (unsigned long)current->mm->context.vdso); \
15221+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
15222 } while (0)
15223
15224 #define AT_SYSINFO 32
15225@@ -320,7 +334,7 @@ else \
15226
15227 #endif /* !CONFIG_X86_32 */
15228
15229-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
15230+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
15231
15232 #define VDSO_ENTRY \
15233 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
15234@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
15235 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
15236 #define compat_arch_setup_additional_pages syscall32_setup_pages
15237
15238-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
15239-#define arch_randomize_brk arch_randomize_brk
15240-
15241 /*
15242 * True on X86_32 or when emulating IA32 on X86_64
15243 */
15244diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
15245index 77a99ac..39ff7f5 100644
15246--- a/arch/x86/include/asm/emergency-restart.h
15247+++ b/arch/x86/include/asm/emergency-restart.h
15248@@ -1,6 +1,6 @@
15249 #ifndef _ASM_X86_EMERGENCY_RESTART_H
15250 #define _ASM_X86_EMERGENCY_RESTART_H
15251
15252-extern void machine_emergency_restart(void);
15253+extern void machine_emergency_restart(void) __noreturn;
15254
15255 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
15256diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
15257index 4d0bda7..221da4d 100644
15258--- a/arch/x86/include/asm/fpu-internal.h
15259+++ b/arch/x86/include/asm/fpu-internal.h
15260@@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
15261 #define user_insn(insn, output, input...) \
15262 ({ \
15263 int err; \
15264+ pax_open_userland(); \
15265 asm volatile(ASM_STAC "\n" \
15266- "1:" #insn "\n\t" \
15267+ "1:" \
15268+ __copyuser_seg \
15269+ #insn "\n\t" \
15270 "2: " ASM_CLAC "\n" \
15271 ".section .fixup,\"ax\"\n" \
15272 "3: movl $-1,%[err]\n" \
15273@@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
15274 _ASM_EXTABLE(1b, 3b) \
15275 : [err] "=r" (err), output \
15276 : "0"(0), input); \
15277+ pax_close_userland(); \
15278 err; \
15279 })
15280
15281@@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
15282 "emms\n\t" /* clear stack tags */
15283 "fildl %P[addr]", /* set F?P to defined value */
15284 X86_FEATURE_FXSAVE_LEAK,
15285- [addr] "m" (tsk->thread.fpu.has_fpu));
15286+ [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
15287
15288 return fpu_restore_checking(&tsk->thread.fpu);
15289 }
15290diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
15291index be27ba1..04a8801 100644
15292--- a/arch/x86/include/asm/futex.h
15293+++ b/arch/x86/include/asm/futex.h
15294@@ -12,6 +12,7 @@
15295 #include <asm/smap.h>
15296
15297 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
15298+ typecheck(u32 __user *, uaddr); \
15299 asm volatile("\t" ASM_STAC "\n" \
15300 "1:\t" insn "\n" \
15301 "2:\t" ASM_CLAC "\n" \
15302@@ -20,15 +21,16 @@
15303 "\tjmp\t2b\n" \
15304 "\t.previous\n" \
15305 _ASM_EXTABLE(1b, 3b) \
15306- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
15307+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
15308 : "i" (-EFAULT), "0" (oparg), "1" (0))
15309
15310 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
15311+ typecheck(u32 __user *, uaddr); \
15312 asm volatile("\t" ASM_STAC "\n" \
15313 "1:\tmovl %2, %0\n" \
15314 "\tmovl\t%0, %3\n" \
15315 "\t" insn "\n" \
15316- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
15317+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
15318 "\tjnz\t1b\n" \
15319 "3:\t" ASM_CLAC "\n" \
15320 "\t.section .fixup,\"ax\"\n" \
15321@@ -38,7 +40,7 @@
15322 _ASM_EXTABLE(1b, 4b) \
15323 _ASM_EXTABLE(2b, 4b) \
15324 : "=&a" (oldval), "=&r" (ret), \
15325- "+m" (*uaddr), "=&r" (tem) \
15326+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
15327 : "r" (oparg), "i" (-EFAULT), "1" (0))
15328
15329 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
15330@@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
15331
15332 pagefault_disable();
15333
15334+ pax_open_userland();
15335 switch (op) {
15336 case FUTEX_OP_SET:
15337- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
15338+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
15339 break;
15340 case FUTEX_OP_ADD:
15341- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
15342+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
15343 uaddr, oparg);
15344 break;
15345 case FUTEX_OP_OR:
15346@@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
15347 default:
15348 ret = -ENOSYS;
15349 }
15350+ pax_close_userland();
15351
15352 pagefault_enable();
15353
15354@@ -115,18 +119,20 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
15355 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
15356 return -EFAULT;
15357
15358+ pax_open_userland();
15359 asm volatile("\t" ASM_STAC "\n"
15360- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
15361+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
15362 "2:\t" ASM_CLAC "\n"
15363 "\t.section .fixup, \"ax\"\n"
15364 "3:\tmov %3, %0\n"
15365 "\tjmp 2b\n"
15366 "\t.previous\n"
15367 _ASM_EXTABLE(1b, 3b)
15368- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
15369+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
15370 : "i" (-EFAULT), "r" (newval), "1" (oldval)
15371 : "memory"
15372 );
15373+ pax_close_userland();
15374
15375 *uval = oldval;
15376 return ret;
15377diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
15378index e4ac559..c1c0c87 100644
15379--- a/arch/x86/include/asm/hw_irq.h
15380+++ b/arch/x86/include/asm/hw_irq.h
15381@@ -165,8 +165,8 @@ extern void setup_ioapic_dest(void);
15382 extern void enable_IO_APIC(void);
15383
15384 /* Statistics */
15385-extern atomic_t irq_err_count;
15386-extern atomic_t irq_mis_count;
15387+extern atomic_unchecked_t irq_err_count;
15388+extern atomic_unchecked_t irq_mis_count;
15389
15390 /* EISA */
15391 extern void eisa_set_level_irq(unsigned int irq);
15392diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
15393index a203659..9889f1c 100644
15394--- a/arch/x86/include/asm/i8259.h
15395+++ b/arch/x86/include/asm/i8259.h
15396@@ -62,7 +62,7 @@ struct legacy_pic {
15397 void (*init)(int auto_eoi);
15398 int (*irq_pending)(unsigned int irq);
15399 void (*make_irq)(unsigned int irq);
15400-};
15401+} __do_const;
15402
15403 extern struct legacy_pic *legacy_pic;
15404 extern struct legacy_pic null_legacy_pic;
15405diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
15406index 34f69cb..6d95446 100644
15407--- a/arch/x86/include/asm/io.h
15408+++ b/arch/x86/include/asm/io.h
15409@@ -51,12 +51,12 @@ static inline void name(type val, volatile void __iomem *addr) \
15410 "m" (*(volatile type __force *)addr) barrier); }
15411
15412 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
15413-build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
15414-build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
15415+build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
15416+build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
15417
15418 build_mmio_read(__readb, "b", unsigned char, "=q", )
15419-build_mmio_read(__readw, "w", unsigned short, "=r", )
15420-build_mmio_read(__readl, "l", unsigned int, "=r", )
15421+build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
15422+build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
15423
15424 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
15425 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
15426@@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
15427 return ioremap_nocache(offset, size);
15428 }
15429
15430-extern void iounmap(volatile void __iomem *addr);
15431+extern void iounmap(const volatile void __iomem *addr);
15432
15433 extern void set_iounmap_nonlazy(void);
15434
15435@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
15436
15437 #include <linux/vmalloc.h>
15438
15439+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
15440+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
15441+{
15442+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
15443+}
15444+
15445+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
15446+{
15447+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
15448+}
15449+
15450 /*
15451 * Convert a virtual cached pointer to an uncached pointer
15452 */
15453diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
15454index bba3cf8..06bc8da 100644
15455--- a/arch/x86/include/asm/irqflags.h
15456+++ b/arch/x86/include/asm/irqflags.h
15457@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
15458 sti; \
15459 sysexit
15460
15461+#define GET_CR0_INTO_RDI mov %cr0, %rdi
15462+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
15463+#define GET_CR3_INTO_RDI mov %cr3, %rdi
15464+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
15465+
15466 #else
15467 #define INTERRUPT_RETURN iret
15468 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
15469diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
15470index 5a6d287..f815789 100644
15471--- a/arch/x86/include/asm/kprobes.h
15472+++ b/arch/x86/include/asm/kprobes.h
15473@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
15474 #define RELATIVEJUMP_SIZE 5
15475 #define RELATIVECALL_OPCODE 0xe8
15476 #define RELATIVE_ADDR_SIZE 4
15477-#define MAX_STACK_SIZE 64
15478-#define MIN_STACK_SIZE(ADDR) \
15479- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
15480- THREAD_SIZE - (unsigned long)(ADDR))) \
15481- ? (MAX_STACK_SIZE) \
15482- : (((unsigned long)current_thread_info()) + \
15483- THREAD_SIZE - (unsigned long)(ADDR)))
15484+#define MAX_STACK_SIZE 64UL
15485+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
15486
15487 #define flush_insn_slot(p) do { } while (0)
15488
15489diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
15490index 2d89e39..baee879 100644
15491--- a/arch/x86/include/asm/local.h
15492+++ b/arch/x86/include/asm/local.h
15493@@ -10,33 +10,97 @@ typedef struct {
15494 atomic_long_t a;
15495 } local_t;
15496
15497+typedef struct {
15498+ atomic_long_unchecked_t a;
15499+} local_unchecked_t;
15500+
15501 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
15502
15503 #define local_read(l) atomic_long_read(&(l)->a)
15504+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
15505 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
15506+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
15507
15508 static inline void local_inc(local_t *l)
15509 {
15510- asm volatile(_ASM_INC "%0"
15511+ asm volatile(_ASM_INC "%0\n"
15512+
15513+#ifdef CONFIG_PAX_REFCOUNT
15514+ "jno 0f\n"
15515+ _ASM_DEC "%0\n"
15516+ "int $4\n0:\n"
15517+ _ASM_EXTABLE(0b, 0b)
15518+#endif
15519+
15520+ : "+m" (l->a.counter));
15521+}
15522+
15523+static inline void local_inc_unchecked(local_unchecked_t *l)
15524+{
15525+ asm volatile(_ASM_INC "%0\n"
15526 : "+m" (l->a.counter));
15527 }
15528
15529 static inline void local_dec(local_t *l)
15530 {
15531- asm volatile(_ASM_DEC "%0"
15532+ asm volatile(_ASM_DEC "%0\n"
15533+
15534+#ifdef CONFIG_PAX_REFCOUNT
15535+ "jno 0f\n"
15536+ _ASM_INC "%0\n"
15537+ "int $4\n0:\n"
15538+ _ASM_EXTABLE(0b, 0b)
15539+#endif
15540+
15541+ : "+m" (l->a.counter));
15542+}
15543+
15544+static inline void local_dec_unchecked(local_unchecked_t *l)
15545+{
15546+ asm volatile(_ASM_DEC "%0\n"
15547 : "+m" (l->a.counter));
15548 }
15549
15550 static inline void local_add(long i, local_t *l)
15551 {
15552- asm volatile(_ASM_ADD "%1,%0"
15553+ asm volatile(_ASM_ADD "%1,%0\n"
15554+
15555+#ifdef CONFIG_PAX_REFCOUNT
15556+ "jno 0f\n"
15557+ _ASM_SUB "%1,%0\n"
15558+ "int $4\n0:\n"
15559+ _ASM_EXTABLE(0b, 0b)
15560+#endif
15561+
15562+ : "+m" (l->a.counter)
15563+ : "ir" (i));
15564+}
15565+
15566+static inline void local_add_unchecked(long i, local_unchecked_t *l)
15567+{
15568+ asm volatile(_ASM_ADD "%1,%0\n"
15569 : "+m" (l->a.counter)
15570 : "ir" (i));
15571 }
15572
15573 static inline void local_sub(long i, local_t *l)
15574 {
15575- asm volatile(_ASM_SUB "%1,%0"
15576+ asm volatile(_ASM_SUB "%1,%0\n"
15577+
15578+#ifdef CONFIG_PAX_REFCOUNT
15579+ "jno 0f\n"
15580+ _ASM_ADD "%1,%0\n"
15581+ "int $4\n0:\n"
15582+ _ASM_EXTABLE(0b, 0b)
15583+#endif
15584+
15585+ : "+m" (l->a.counter)
15586+ : "ir" (i));
15587+}
15588+
15589+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
15590+{
15591+ asm volatile(_ASM_SUB "%1,%0\n"
15592 : "+m" (l->a.counter)
15593 : "ir" (i));
15594 }
15595@@ -54,7 +118,16 @@ static inline int local_sub_and_test(long i, local_t *l)
15596 {
15597 unsigned char c;
15598
15599- asm volatile(_ASM_SUB "%2,%0; sete %1"
15600+ asm volatile(_ASM_SUB "%2,%0\n"
15601+
15602+#ifdef CONFIG_PAX_REFCOUNT
15603+ "jno 0f\n"
15604+ _ASM_ADD "%2,%0\n"
15605+ "int $4\n0:\n"
15606+ _ASM_EXTABLE(0b, 0b)
15607+#endif
15608+
15609+ "sete %1\n"
15610 : "+m" (l->a.counter), "=qm" (c)
15611 : "ir" (i) : "memory");
15612 return c;
15613@@ -72,7 +145,16 @@ static inline int local_dec_and_test(local_t *l)
15614 {
15615 unsigned char c;
15616
15617- asm volatile(_ASM_DEC "%0; sete %1"
15618+ asm volatile(_ASM_DEC "%0\n"
15619+
15620+#ifdef CONFIG_PAX_REFCOUNT
15621+ "jno 0f\n"
15622+ _ASM_INC "%0\n"
15623+ "int $4\n0:\n"
15624+ _ASM_EXTABLE(0b, 0b)
15625+#endif
15626+
15627+ "sete %1\n"
15628 : "+m" (l->a.counter), "=qm" (c)
15629 : : "memory");
15630 return c != 0;
15631@@ -90,7 +172,16 @@ static inline int local_inc_and_test(local_t *l)
15632 {
15633 unsigned char c;
15634
15635- asm volatile(_ASM_INC "%0; sete %1"
15636+ asm volatile(_ASM_INC "%0\n"
15637+
15638+#ifdef CONFIG_PAX_REFCOUNT
15639+ "jno 0f\n"
15640+ _ASM_DEC "%0\n"
15641+ "int $4\n0:\n"
15642+ _ASM_EXTABLE(0b, 0b)
15643+#endif
15644+
15645+ "sete %1\n"
15646 : "+m" (l->a.counter), "=qm" (c)
15647 : : "memory");
15648 return c != 0;
15649@@ -109,7 +200,16 @@ static inline int local_add_negative(long i, local_t *l)
15650 {
15651 unsigned char c;
15652
15653- asm volatile(_ASM_ADD "%2,%0; sets %1"
15654+ asm volatile(_ASM_ADD "%2,%0\n"
15655+
15656+#ifdef CONFIG_PAX_REFCOUNT
15657+ "jno 0f\n"
15658+ _ASM_SUB "%2,%0\n"
15659+ "int $4\n0:\n"
15660+ _ASM_EXTABLE(0b, 0b)
15661+#endif
15662+
15663+ "sets %1\n"
15664 : "+m" (l->a.counter), "=qm" (c)
15665 : "ir" (i) : "memory");
15666 return c;
15667@@ -125,6 +225,30 @@ static inline int local_add_negative(long i, local_t *l)
15668 static inline long local_add_return(long i, local_t *l)
15669 {
15670 long __i = i;
15671+ asm volatile(_ASM_XADD "%0, %1\n"
15672+
15673+#ifdef CONFIG_PAX_REFCOUNT
15674+ "jno 0f\n"
15675+ _ASM_MOV "%0,%1\n"
15676+ "int $4\n0:\n"
15677+ _ASM_EXTABLE(0b, 0b)
15678+#endif
15679+
15680+ : "+r" (i), "+m" (l->a.counter)
15681+ : : "memory");
15682+ return i + __i;
15683+}
15684+
15685+/**
15686+ * local_add_return_unchecked - add and return
15687+ * @i: integer value to add
15688+ * @l: pointer to type local_unchecked_t
15689+ *
15690+ * Atomically adds @i to @l and returns @i + @l
15691+ */
15692+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
15693+{
15694+ long __i = i;
15695 asm volatile(_ASM_XADD "%0, %1;"
15696 : "+r" (i), "+m" (l->a.counter)
15697 : : "memory");
15698@@ -141,6 +265,8 @@ static inline long local_sub_return(long i, local_t *l)
15699
15700 #define local_cmpxchg(l, o, n) \
15701 (cmpxchg_local(&((l)->a.counter), (o), (n)))
15702+#define local_cmpxchg_unchecked(l, o, n) \
15703+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
15704 /* Always has a lock prefix */
15705 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
15706
15707diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
15708new file mode 100644
15709index 0000000..2bfd3ba
15710--- /dev/null
15711+++ b/arch/x86/include/asm/mman.h
15712@@ -0,0 +1,15 @@
15713+#ifndef _X86_MMAN_H
15714+#define _X86_MMAN_H
15715+
15716+#include <uapi/asm/mman.h>
15717+
15718+#ifdef __KERNEL__
15719+#ifndef __ASSEMBLY__
15720+#ifdef CONFIG_X86_32
15721+#define arch_mmap_check i386_mmap_check
15722+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
15723+#endif
15724+#endif
15725+#endif
15726+
15727+#endif /* X86_MMAN_H */
15728diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
15729index 5f55e69..e20bfb1 100644
15730--- a/arch/x86/include/asm/mmu.h
15731+++ b/arch/x86/include/asm/mmu.h
15732@@ -9,7 +9,7 @@
15733 * we put the segment information here.
15734 */
15735 typedef struct {
15736- void *ldt;
15737+ struct desc_struct *ldt;
15738 int size;
15739
15740 #ifdef CONFIG_X86_64
15741@@ -18,7 +18,19 @@ typedef struct {
15742 #endif
15743
15744 struct mutex lock;
15745- void *vdso;
15746+ unsigned long vdso;
15747+
15748+#ifdef CONFIG_X86_32
15749+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
15750+ unsigned long user_cs_base;
15751+ unsigned long user_cs_limit;
15752+
15753+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
15754+ cpumask_t cpu_user_cs_mask;
15755+#endif
15756+
15757+#endif
15758+#endif
15759 } mm_context_t;
15760
15761 #ifdef CONFIG_SMP
15762diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
15763index cdbf367..ce8f82b 100644
15764--- a/arch/x86/include/asm/mmu_context.h
15765+++ b/arch/x86/include/asm/mmu_context.h
15766@@ -24,6 +24,20 @@ void destroy_context(struct mm_struct *mm);
15767
15768 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
15769 {
15770+
15771+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15772+ if (!(static_cpu_has(X86_FEATURE_PCID))) {
15773+ unsigned int i;
15774+ pgd_t *pgd;
15775+
15776+ pax_open_kernel();
15777+ pgd = get_cpu_pgd(smp_processor_id(), kernel);
15778+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
15779+ set_pgd_batched(pgd+i, native_make_pgd(0));
15780+ pax_close_kernel();
15781+ }
15782+#endif
15783+
15784 #ifdef CONFIG_SMP
15785 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
15786 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
15787@@ -34,16 +48,55 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
15788 struct task_struct *tsk)
15789 {
15790 unsigned cpu = smp_processor_id();
15791+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
15792+ int tlbstate = TLBSTATE_OK;
15793+#endif
15794
15795 if (likely(prev != next)) {
15796 #ifdef CONFIG_SMP
15797+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
15798+ tlbstate = this_cpu_read(cpu_tlbstate.state);
15799+#endif
15800 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
15801 this_cpu_write(cpu_tlbstate.active_mm, next);
15802 #endif
15803 cpumask_set_cpu(cpu, mm_cpumask(next));
15804
15805 /* Re-load page tables */
15806+#ifdef CONFIG_PAX_PER_CPU_PGD
15807+ pax_open_kernel();
15808+
15809+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15810+ if (static_cpu_has(X86_FEATURE_PCID))
15811+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
15812+ else
15813+#endif
15814+
15815+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
15816+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
15817+ pax_close_kernel();
15818+ 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));
15819+
15820+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15821+ if (static_cpu_has(X86_FEATURE_PCID)) {
15822+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
15823+ u64 descriptor[2];
15824+ descriptor[0] = PCID_USER;
15825+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
15826+ } else {
15827+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
15828+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
15829+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
15830+ else
15831+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
15832+ }
15833+ } else
15834+#endif
15835+
15836+ load_cr3(get_cpu_pgd(cpu, kernel));
15837+#else
15838 load_cr3(next->pgd);
15839+#endif
15840
15841 /* stop flush ipis for the previous mm */
15842 cpumask_clear_cpu(cpu, mm_cpumask(prev));
15843@@ -53,9 +106,63 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
15844 */
15845 if (unlikely(prev->context.ldt != next->context.ldt))
15846 load_LDT_nolock(&next->context);
15847- }
15848+
15849+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
15850+ if (!(__supported_pte_mask & _PAGE_NX)) {
15851+ smp_mb__before_clear_bit();
15852+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
15853+ smp_mb__after_clear_bit();
15854+ cpu_set(cpu, next->context.cpu_user_cs_mask);
15855+ }
15856+#endif
15857+
15858+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
15859+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
15860+ prev->context.user_cs_limit != next->context.user_cs_limit))
15861+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
15862 #ifdef CONFIG_SMP
15863+ else if (unlikely(tlbstate != TLBSTATE_OK))
15864+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
15865+#endif
15866+#endif
15867+
15868+ }
15869 else {
15870+
15871+#ifdef CONFIG_PAX_PER_CPU_PGD
15872+ pax_open_kernel();
15873+
15874+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15875+ if (static_cpu_has(X86_FEATURE_PCID))
15876+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
15877+ else
15878+#endif
15879+
15880+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
15881+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
15882+ pax_close_kernel();
15883+ 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));
15884+
15885+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15886+ if (static_cpu_has(X86_FEATURE_PCID)) {
15887+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
15888+ u64 descriptor[2];
15889+ descriptor[0] = PCID_USER;
15890+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
15891+ } else {
15892+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
15893+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
15894+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
15895+ else
15896+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
15897+ }
15898+ } else
15899+#endif
15900+
15901+ load_cr3(get_cpu_pgd(cpu, kernel));
15902+#endif
15903+
15904+#ifdef CONFIG_SMP
15905 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
15906 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
15907
15908@@ -64,11 +171,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
15909 * tlb flush IPI delivery. We must reload CR3
15910 * to make sure to use no freed page tables.
15911 */
15912+
15913+#ifndef CONFIG_PAX_PER_CPU_PGD
15914 load_cr3(next->pgd);
15915+#endif
15916+
15917 load_LDT_nolock(&next->context);
15918+
15919+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
15920+ if (!(__supported_pte_mask & _PAGE_NX))
15921+ cpu_set(cpu, next->context.cpu_user_cs_mask);
15922+#endif
15923+
15924+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
15925+#ifdef CONFIG_PAX_PAGEEXEC
15926+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
15927+#endif
15928+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
15929+#endif
15930+
15931 }
15932+#endif
15933 }
15934-#endif
15935 }
15936
15937 #define activate_mm(prev, next) \
15938diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
15939index e3b7819..b257c64 100644
15940--- a/arch/x86/include/asm/module.h
15941+++ b/arch/x86/include/asm/module.h
15942@@ -5,6 +5,7 @@
15943
15944 #ifdef CONFIG_X86_64
15945 /* X86_64 does not define MODULE_PROC_FAMILY */
15946+#define MODULE_PROC_FAMILY ""
15947 #elif defined CONFIG_M486
15948 #define MODULE_PROC_FAMILY "486 "
15949 #elif defined CONFIG_M586
15950@@ -57,8 +58,20 @@
15951 #error unknown processor family
15952 #endif
15953
15954-#ifdef CONFIG_X86_32
15955-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
15956+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
15957+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
15958+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
15959+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
15960+#else
15961+#define MODULE_PAX_KERNEXEC ""
15962 #endif
15963
15964+#ifdef CONFIG_PAX_MEMORY_UDEREF
15965+#define MODULE_PAX_UDEREF "UDEREF "
15966+#else
15967+#define MODULE_PAX_UDEREF ""
15968+#endif
15969+
15970+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
15971+
15972 #endif /* _ASM_X86_MODULE_H */
15973diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
15974index 86f9301..b365cda 100644
15975--- a/arch/x86/include/asm/nmi.h
15976+++ b/arch/x86/include/asm/nmi.h
15977@@ -40,11 +40,11 @@ struct nmiaction {
15978 nmi_handler_t handler;
15979 unsigned long flags;
15980 const char *name;
15981-};
15982+} __do_const;
15983
15984 #define register_nmi_handler(t, fn, fg, n, init...) \
15985 ({ \
15986- static struct nmiaction init fn##_na = { \
15987+ static const struct nmiaction init fn##_na = { \
15988 .handler = (fn), \
15989 .name = (n), \
15990 .flags = (fg), \
15991@@ -52,7 +52,7 @@ struct nmiaction {
15992 __register_nmi_handler((t), &fn##_na); \
15993 })
15994
15995-int __register_nmi_handler(unsigned int, struct nmiaction *);
15996+int __register_nmi_handler(unsigned int, const struct nmiaction *);
15997
15998 void unregister_nmi_handler(unsigned int, const char *);
15999
16000diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
16001index c878924..21f4889 100644
16002--- a/arch/x86/include/asm/page.h
16003+++ b/arch/x86/include/asm/page.h
16004@@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
16005 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
16006
16007 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
16008+#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
16009
16010 #define __boot_va(x) __va(x)
16011 #define __boot_pa(x) __pa(x)
16012diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
16013index 0f1ddee..e2fc3d1 100644
16014--- a/arch/x86/include/asm/page_64.h
16015+++ b/arch/x86/include/asm/page_64.h
16016@@ -7,9 +7,9 @@
16017
16018 /* duplicated to the one in bootmem.h */
16019 extern unsigned long max_pfn;
16020-extern unsigned long phys_base;
16021+extern const unsigned long phys_base;
16022
16023-static inline unsigned long __phys_addr_nodebug(unsigned long x)
16024+static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
16025 {
16026 unsigned long y = x - __START_KERNEL_map;
16027
16028diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
16029index cfdc9ee..3f7b5d6 100644
16030--- a/arch/x86/include/asm/paravirt.h
16031+++ b/arch/x86/include/asm/paravirt.h
16032@@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
16033 return (pmd_t) { ret };
16034 }
16035
16036-static inline pmdval_t pmd_val(pmd_t pmd)
16037+static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
16038 {
16039 pmdval_t ret;
16040
16041@@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
16042 val);
16043 }
16044
16045+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
16046+{
16047+ pgdval_t val = native_pgd_val(pgd);
16048+
16049+ if (sizeof(pgdval_t) > sizeof(long))
16050+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
16051+ val, (u64)val >> 32);
16052+ else
16053+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
16054+ val);
16055+}
16056+
16057 static inline void pgd_clear(pgd_t *pgdp)
16058 {
16059 set_pgd(pgdp, __pgd(0));
16060@@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
16061 pv_mmu_ops.set_fixmap(idx, phys, flags);
16062 }
16063
16064+#ifdef CONFIG_PAX_KERNEXEC
16065+static inline unsigned long pax_open_kernel(void)
16066+{
16067+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
16068+}
16069+
16070+static inline unsigned long pax_close_kernel(void)
16071+{
16072+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
16073+}
16074+#else
16075+static inline unsigned long pax_open_kernel(void) { return 0; }
16076+static inline unsigned long pax_close_kernel(void) { return 0; }
16077+#endif
16078+
16079 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
16080
16081 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
16082@@ -926,7 +953,7 @@ extern void default_banner(void);
16083
16084 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
16085 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
16086-#define PARA_INDIRECT(addr) *%cs:addr
16087+#define PARA_INDIRECT(addr) *%ss:addr
16088 #endif
16089
16090 #define INTERRUPT_RETURN \
16091@@ -1001,6 +1028,21 @@ extern void default_banner(void);
16092 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
16093 CLBR_NONE, \
16094 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
16095+
16096+#define GET_CR0_INTO_RDI \
16097+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
16098+ mov %rax,%rdi
16099+
16100+#define SET_RDI_INTO_CR0 \
16101+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
16102+
16103+#define GET_CR3_INTO_RDI \
16104+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
16105+ mov %rax,%rdi
16106+
16107+#define SET_RDI_INTO_CR3 \
16108+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
16109+
16110 #endif /* CONFIG_X86_32 */
16111
16112 #endif /* __ASSEMBLY__ */
16113diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
16114index 0db1fca..52310cc 100644
16115--- a/arch/x86/include/asm/paravirt_types.h
16116+++ b/arch/x86/include/asm/paravirt_types.h
16117@@ -84,7 +84,7 @@ struct pv_init_ops {
16118 */
16119 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
16120 unsigned long addr, unsigned len);
16121-};
16122+} __no_const;
16123
16124
16125 struct pv_lazy_ops {
16126@@ -98,7 +98,7 @@ struct pv_time_ops {
16127 unsigned long long (*sched_clock)(void);
16128 unsigned long long (*steal_clock)(int cpu);
16129 unsigned long (*get_tsc_khz)(void);
16130-};
16131+} __no_const;
16132
16133 struct pv_cpu_ops {
16134 /* hooks for various privileged instructions */
16135@@ -192,7 +192,7 @@ struct pv_cpu_ops {
16136
16137 void (*start_context_switch)(struct task_struct *prev);
16138 void (*end_context_switch)(struct task_struct *next);
16139-};
16140+} __no_const;
16141
16142 struct pv_irq_ops {
16143 /*
16144@@ -223,7 +223,7 @@ struct pv_apic_ops {
16145 unsigned long start_eip,
16146 unsigned long start_esp);
16147 #endif
16148-};
16149+} __no_const;
16150
16151 struct pv_mmu_ops {
16152 unsigned long (*read_cr2)(void);
16153@@ -313,6 +313,7 @@ struct pv_mmu_ops {
16154 struct paravirt_callee_save make_pud;
16155
16156 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
16157+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
16158 #endif /* PAGETABLE_LEVELS == 4 */
16159 #endif /* PAGETABLE_LEVELS >= 3 */
16160
16161@@ -324,6 +325,12 @@ struct pv_mmu_ops {
16162 an mfn. We can tell which is which from the index. */
16163 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
16164 phys_addr_t phys, pgprot_t flags);
16165+
16166+#ifdef CONFIG_PAX_KERNEXEC
16167+ unsigned long (*pax_open_kernel)(void);
16168+ unsigned long (*pax_close_kernel)(void);
16169+#endif
16170+
16171 };
16172
16173 struct arch_spinlock;
16174@@ -334,7 +341,7 @@ struct pv_lock_ops {
16175 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
16176 int (*spin_trylock)(struct arch_spinlock *lock);
16177 void (*spin_unlock)(struct arch_spinlock *lock);
16178-};
16179+} __no_const;
16180
16181 /* This contains all the paravirt structures: we get a convenient
16182 * number for each function using the offset which we use to indicate
16183diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
16184index b4389a4..7024269 100644
16185--- a/arch/x86/include/asm/pgalloc.h
16186+++ b/arch/x86/include/asm/pgalloc.h
16187@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
16188 pmd_t *pmd, pte_t *pte)
16189 {
16190 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
16191+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
16192+}
16193+
16194+static inline void pmd_populate_user(struct mm_struct *mm,
16195+ pmd_t *pmd, pte_t *pte)
16196+{
16197+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
16198 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
16199 }
16200
16201@@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
16202
16203 #ifdef CONFIG_X86_PAE
16204 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
16205+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
16206+{
16207+ pud_populate(mm, pudp, pmd);
16208+}
16209 #else /* !CONFIG_X86_PAE */
16210 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
16211 {
16212 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
16213 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
16214 }
16215+
16216+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
16217+{
16218+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
16219+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
16220+}
16221 #endif /* CONFIG_X86_PAE */
16222
16223 #if PAGETABLE_LEVELS > 3
16224@@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
16225 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
16226 }
16227
16228+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
16229+{
16230+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
16231+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
16232+}
16233+
16234 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
16235 {
16236 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
16237diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
16238index 3bf2dd0..23d2a9f 100644
16239--- a/arch/x86/include/asm/pgtable-2level.h
16240+++ b/arch/x86/include/asm/pgtable-2level.h
16241@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
16242
16243 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
16244 {
16245+ pax_open_kernel();
16246 *pmdp = pmd;
16247+ pax_close_kernel();
16248 }
16249
16250 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
16251diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
16252index 81bb91b..9392125 100644
16253--- a/arch/x86/include/asm/pgtable-3level.h
16254+++ b/arch/x86/include/asm/pgtable-3level.h
16255@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
16256
16257 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
16258 {
16259+ pax_open_kernel();
16260 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
16261+ pax_close_kernel();
16262 }
16263
16264 static inline void native_set_pud(pud_t *pudp, pud_t pud)
16265 {
16266+ pax_open_kernel();
16267 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
16268+ pax_close_kernel();
16269 }
16270
16271 /*
16272diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
16273index 1c00631..845f898 100644
16274--- a/arch/x86/include/asm/pgtable.h
16275+++ b/arch/x86/include/asm/pgtable.h
16276@@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
16277
16278 #ifndef __PAGETABLE_PUD_FOLDED
16279 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
16280+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
16281 #define pgd_clear(pgd) native_pgd_clear(pgd)
16282 #endif
16283
16284@@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
16285
16286 #define arch_end_context_switch(prev) do {} while(0)
16287
16288+#define pax_open_kernel() native_pax_open_kernel()
16289+#define pax_close_kernel() native_pax_close_kernel()
16290 #endif /* CONFIG_PARAVIRT */
16291
16292+#define __HAVE_ARCH_PAX_OPEN_KERNEL
16293+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
16294+
16295+#ifdef CONFIG_PAX_KERNEXEC
16296+static inline unsigned long native_pax_open_kernel(void)
16297+{
16298+ unsigned long cr0;
16299+
16300+ preempt_disable();
16301+ barrier();
16302+ cr0 = read_cr0() ^ X86_CR0_WP;
16303+ BUG_ON(cr0 & X86_CR0_WP);
16304+ write_cr0(cr0);
16305+ return cr0 ^ X86_CR0_WP;
16306+}
16307+
16308+static inline unsigned long native_pax_close_kernel(void)
16309+{
16310+ unsigned long cr0;
16311+
16312+ cr0 = read_cr0() ^ X86_CR0_WP;
16313+ BUG_ON(!(cr0 & X86_CR0_WP));
16314+ write_cr0(cr0);
16315+ barrier();
16316+ preempt_enable_no_resched();
16317+ return cr0 ^ X86_CR0_WP;
16318+}
16319+#else
16320+static inline unsigned long native_pax_open_kernel(void) { return 0; }
16321+static inline unsigned long native_pax_close_kernel(void) { return 0; }
16322+#endif
16323+
16324 /*
16325 * The following only work if pte_present() is true.
16326 * Undefined behaviour if not..
16327 */
16328+static inline int pte_user(pte_t pte)
16329+{
16330+ return pte_val(pte) & _PAGE_USER;
16331+}
16332+
16333 static inline int pte_dirty(pte_t pte)
16334 {
16335 return pte_flags(pte) & _PAGE_DIRTY;
16336@@ -147,6 +187,11 @@ static inline unsigned long pud_pfn(pud_t pud)
16337 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
16338 }
16339
16340+static inline unsigned long pgd_pfn(pgd_t pgd)
16341+{
16342+ return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
16343+}
16344+
16345 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
16346
16347 static inline int pmd_large(pmd_t pte)
16348@@ -200,9 +245,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
16349 return pte_clear_flags(pte, _PAGE_RW);
16350 }
16351
16352+static inline pte_t pte_mkread(pte_t pte)
16353+{
16354+ return __pte(pte_val(pte) | _PAGE_USER);
16355+}
16356+
16357 static inline pte_t pte_mkexec(pte_t pte)
16358 {
16359- return pte_clear_flags(pte, _PAGE_NX);
16360+#ifdef CONFIG_X86_PAE
16361+ if (__supported_pte_mask & _PAGE_NX)
16362+ return pte_clear_flags(pte, _PAGE_NX);
16363+ else
16364+#endif
16365+ return pte_set_flags(pte, _PAGE_USER);
16366+}
16367+
16368+static inline pte_t pte_exprotect(pte_t pte)
16369+{
16370+#ifdef CONFIG_X86_PAE
16371+ if (__supported_pte_mask & _PAGE_NX)
16372+ return pte_set_flags(pte, _PAGE_NX);
16373+ else
16374+#endif
16375+ return pte_clear_flags(pte, _PAGE_USER);
16376 }
16377
16378 static inline pte_t pte_mkdirty(pte_t pte)
16379@@ -444,6 +509,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
16380 #endif
16381
16382 #ifndef __ASSEMBLY__
16383+
16384+#ifdef CONFIG_PAX_PER_CPU_PGD
16385+extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
16386+enum cpu_pgd_type {kernel = 0, user = 1};
16387+static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
16388+{
16389+ return cpu_pgd[cpu][type];
16390+}
16391+#endif
16392+
16393 #include <linux/mm_types.h>
16394 #include <linux/log2.h>
16395
16396@@ -576,7 +651,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
16397 * Currently stuck as a macro due to indirect forward reference to
16398 * linux/mmzone.h's __section_mem_map_addr() definition:
16399 */
16400-#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
16401+#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
16402
16403 /* Find an entry in the second-level page table.. */
16404 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
16405@@ -616,7 +691,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
16406 * Currently stuck as a macro due to indirect forward reference to
16407 * linux/mmzone.h's __section_mem_map_addr() definition:
16408 */
16409-#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
16410+#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
16411
16412 /* to find an entry in a page-table-directory. */
16413 static inline unsigned long pud_index(unsigned long address)
16414@@ -631,7 +706,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
16415
16416 static inline int pgd_bad(pgd_t pgd)
16417 {
16418- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
16419+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
16420 }
16421
16422 static inline int pgd_none(pgd_t pgd)
16423@@ -654,7 +729,12 @@ static inline int pgd_none(pgd_t pgd)
16424 * pgd_offset() returns a (pgd_t *)
16425 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
16426 */
16427-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
16428+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
16429+
16430+#ifdef CONFIG_PAX_PER_CPU_PGD
16431+#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
16432+#endif
16433+
16434 /*
16435 * a shortcut which implies the use of the kernel's pgd, instead
16436 * of a process's
16437@@ -665,6 +745,23 @@ static inline int pgd_none(pgd_t pgd)
16438 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
16439 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
16440
16441+#ifdef CONFIG_X86_32
16442+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
16443+#else
16444+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
16445+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
16446+
16447+#ifdef CONFIG_PAX_MEMORY_UDEREF
16448+#ifdef __ASSEMBLY__
16449+#define pax_user_shadow_base pax_user_shadow_base(%rip)
16450+#else
16451+extern unsigned long pax_user_shadow_base;
16452+extern pgdval_t clone_pgd_mask;
16453+#endif
16454+#endif
16455+
16456+#endif
16457+
16458 #ifndef __ASSEMBLY__
16459
16460 extern int direct_gbpages;
16461@@ -831,11 +928,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
16462 * dst and src can be on the same page, but the range must not overlap,
16463 * and must not cross a page boundary.
16464 */
16465-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
16466+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
16467 {
16468- memcpy(dst, src, count * sizeof(pgd_t));
16469+ pax_open_kernel();
16470+ while (count--)
16471+ *dst++ = *src++;
16472+ pax_close_kernel();
16473 }
16474
16475+#ifdef CONFIG_PAX_PER_CPU_PGD
16476+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
16477+#endif
16478+
16479+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16480+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
16481+#else
16482+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
16483+#endif
16484+
16485 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
16486 static inline int page_level_shift(enum pg_level level)
16487 {
16488diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
16489index 9ee3221..b979c6b 100644
16490--- a/arch/x86/include/asm/pgtable_32.h
16491+++ b/arch/x86/include/asm/pgtable_32.h
16492@@ -25,9 +25,6 @@
16493 struct mm_struct;
16494 struct vm_area_struct;
16495
16496-extern pgd_t swapper_pg_dir[1024];
16497-extern pgd_t initial_page_table[1024];
16498-
16499 static inline void pgtable_cache_init(void) { }
16500 static inline void check_pgt_cache(void) { }
16501 void paging_init(void);
16502@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
16503 # include <asm/pgtable-2level.h>
16504 #endif
16505
16506+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
16507+extern pgd_t initial_page_table[PTRS_PER_PGD];
16508+#ifdef CONFIG_X86_PAE
16509+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
16510+#endif
16511+
16512 #if defined(CONFIG_HIGHPTE)
16513 #define pte_offset_map(dir, address) \
16514 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
16515@@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
16516 /* Clear a kernel PTE and flush it from the TLB */
16517 #define kpte_clear_flush(ptep, vaddr) \
16518 do { \
16519+ pax_open_kernel(); \
16520 pte_clear(&init_mm, (vaddr), (ptep)); \
16521+ pax_close_kernel(); \
16522 __flush_tlb_one((vaddr)); \
16523 } while (0)
16524
16525 #endif /* !__ASSEMBLY__ */
16526
16527+#define HAVE_ARCH_UNMAPPED_AREA
16528+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
16529+
16530 /*
16531 * kern_addr_valid() is (1) for FLATMEM and (0) for
16532 * SPARSEMEM and DISCONTIGMEM
16533diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
16534index ed5903b..c7fe163 100644
16535--- a/arch/x86/include/asm/pgtable_32_types.h
16536+++ b/arch/x86/include/asm/pgtable_32_types.h
16537@@ -8,7 +8,7 @@
16538 */
16539 #ifdef CONFIG_X86_PAE
16540 # include <asm/pgtable-3level_types.h>
16541-# define PMD_SIZE (1UL << PMD_SHIFT)
16542+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
16543 # define PMD_MASK (~(PMD_SIZE - 1))
16544 #else
16545 # include <asm/pgtable-2level_types.h>
16546@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
16547 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
16548 #endif
16549
16550+#ifdef CONFIG_PAX_KERNEXEC
16551+#ifndef __ASSEMBLY__
16552+extern unsigned char MODULES_EXEC_VADDR[];
16553+extern unsigned char MODULES_EXEC_END[];
16554+#endif
16555+#include <asm/boot.h>
16556+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
16557+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
16558+#else
16559+#define ktla_ktva(addr) (addr)
16560+#define ktva_ktla(addr) (addr)
16561+#endif
16562+
16563 #define MODULES_VADDR VMALLOC_START
16564 #define MODULES_END VMALLOC_END
16565 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
16566diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
16567index e22c1db..23a625a 100644
16568--- a/arch/x86/include/asm/pgtable_64.h
16569+++ b/arch/x86/include/asm/pgtable_64.h
16570@@ -16,10 +16,14 @@
16571
16572 extern pud_t level3_kernel_pgt[512];
16573 extern pud_t level3_ident_pgt[512];
16574+extern pud_t level3_vmalloc_start_pgt[512];
16575+extern pud_t level3_vmalloc_end_pgt[512];
16576+extern pud_t level3_vmemmap_pgt[512];
16577+extern pud_t level2_vmemmap_pgt[512];
16578 extern pmd_t level2_kernel_pgt[512];
16579 extern pmd_t level2_fixmap_pgt[512];
16580-extern pmd_t level2_ident_pgt[512];
16581-extern pgd_t init_level4_pgt[];
16582+extern pmd_t level2_ident_pgt[512*2];
16583+extern pgd_t init_level4_pgt[512];
16584
16585 #define swapper_pg_dir init_level4_pgt
16586
16587@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
16588
16589 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
16590 {
16591+ pax_open_kernel();
16592 *pmdp = pmd;
16593+ pax_close_kernel();
16594 }
16595
16596 static inline void native_pmd_clear(pmd_t *pmd)
16597@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
16598
16599 static inline void native_set_pud(pud_t *pudp, pud_t pud)
16600 {
16601+ pax_open_kernel();
16602 *pudp = pud;
16603+ pax_close_kernel();
16604 }
16605
16606 static inline void native_pud_clear(pud_t *pud)
16607@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
16608
16609 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
16610 {
16611+ pax_open_kernel();
16612+ *pgdp = pgd;
16613+ pax_close_kernel();
16614+}
16615+
16616+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
16617+{
16618 *pgdp = pgd;
16619 }
16620
16621diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
16622index 2d88344..4679fc3 100644
16623--- a/arch/x86/include/asm/pgtable_64_types.h
16624+++ b/arch/x86/include/asm/pgtable_64_types.h
16625@@ -61,6 +61,11 @@ typedef struct { pteval_t pte; } pte_t;
16626 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
16627 #define MODULES_END _AC(0xffffffffff000000, UL)
16628 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
16629+#define MODULES_EXEC_VADDR MODULES_VADDR
16630+#define MODULES_EXEC_END MODULES_END
16631+
16632+#define ktla_ktva(addr) (addr)
16633+#define ktva_ktla(addr) (addr)
16634
16635 #define EARLY_DYNAMIC_PAGE_TABLES 64
16636
16637diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
16638index f4843e0..a2526f8 100644
16639--- a/arch/x86/include/asm/pgtable_types.h
16640+++ b/arch/x86/include/asm/pgtable_types.h
16641@@ -16,13 +16,12 @@
16642 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
16643 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
16644 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
16645-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
16646+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
16647 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
16648 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
16649 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
16650-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
16651-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
16652-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
16653+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
16654+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
16655 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
16656
16657 /* If _PAGE_BIT_PRESENT is clear, we use these: */
16658@@ -40,7 +39,6 @@
16659 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
16660 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
16661 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
16662-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
16663 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
16664 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
16665 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
16666@@ -84,8 +82,10 @@
16667
16668 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
16669 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
16670-#else
16671+#elif defined(CONFIG_KMEMCHECK)
16672 #define _PAGE_NX (_AT(pteval_t, 0))
16673+#else
16674+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
16675 #endif
16676
16677 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
16678@@ -143,6 +143,9 @@
16679 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
16680 _PAGE_ACCESSED)
16681
16682+#define PAGE_READONLY_NOEXEC PAGE_READONLY
16683+#define PAGE_SHARED_NOEXEC PAGE_SHARED
16684+
16685 #define __PAGE_KERNEL_EXEC \
16686 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
16687 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
16688@@ -153,7 +156,7 @@
16689 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
16690 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
16691 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
16692-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
16693+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
16694 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
16695 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
16696 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
16697@@ -215,8 +218,8 @@
16698 * bits are combined, this will alow user to access the high address mapped
16699 * VDSO in the presence of CONFIG_COMPAT_VDSO
16700 */
16701-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
16702-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
16703+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
16704+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
16705 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
16706 #endif
16707
16708@@ -254,7 +257,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
16709 {
16710 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
16711 }
16712+#endif
16713
16714+#if PAGETABLE_LEVELS == 3
16715+#include <asm-generic/pgtable-nopud.h>
16716+#endif
16717+
16718+#if PAGETABLE_LEVELS == 2
16719+#include <asm-generic/pgtable-nopmd.h>
16720+#endif
16721+
16722+#ifndef __ASSEMBLY__
16723 #if PAGETABLE_LEVELS > 3
16724 typedef struct { pudval_t pud; } pud_t;
16725
16726@@ -268,8 +281,6 @@ static inline pudval_t native_pud_val(pud_t pud)
16727 return pud.pud;
16728 }
16729 #else
16730-#include <asm-generic/pgtable-nopud.h>
16731-
16732 static inline pudval_t native_pud_val(pud_t pud)
16733 {
16734 return native_pgd_val(pud.pgd);
16735@@ -289,8 +300,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
16736 return pmd.pmd;
16737 }
16738 #else
16739-#include <asm-generic/pgtable-nopmd.h>
16740-
16741 static inline pmdval_t native_pmd_val(pmd_t pmd)
16742 {
16743 return native_pgd_val(pmd.pud.pgd);
16744@@ -330,7 +339,6 @@ typedef struct page *pgtable_t;
16745
16746 extern pteval_t __supported_pte_mask;
16747 extern void set_nx(void);
16748-extern int nx_enabled;
16749
16750 #define pgprot_writecombine pgprot_writecombine
16751 extern pgprot_t pgprot_writecombine(pgprot_t prot);
16752diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
16753index 24cf5ae..4d9fa2d 100644
16754--- a/arch/x86/include/asm/processor.h
16755+++ b/arch/x86/include/asm/processor.h
16756@@ -199,9 +199,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
16757 : "memory");
16758 }
16759
16760+/* invpcid (%rdx),%rax */
16761+#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
16762+
16763+#define INVPCID_SINGLE_ADDRESS 0UL
16764+#define INVPCID_SINGLE_CONTEXT 1UL
16765+#define INVPCID_ALL_GLOBAL 2UL
16766+#define INVPCID_ALL_MONGLOBAL 3UL
16767+
16768+#define PCID_KERNEL 0UL
16769+#define PCID_USER 1UL
16770+#define PCID_NOFLUSH (1UL << 63)
16771+
16772 static inline void load_cr3(pgd_t *pgdir)
16773 {
16774- write_cr3(__pa(pgdir));
16775+ write_cr3(__pa(pgdir) | PCID_KERNEL);
16776 }
16777
16778 #ifdef CONFIG_X86_32
16779@@ -283,7 +295,7 @@ struct tss_struct {
16780
16781 } ____cacheline_aligned;
16782
16783-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
16784+extern struct tss_struct init_tss[NR_CPUS];
16785
16786 /*
16787 * Save the original ist values for checking stack pointers during debugging
16788@@ -453,6 +465,7 @@ struct thread_struct {
16789 unsigned short ds;
16790 unsigned short fsindex;
16791 unsigned short gsindex;
16792+ unsigned short ss;
16793 #endif
16794 #ifdef CONFIG_X86_32
16795 unsigned long ip;
16796@@ -553,29 +566,8 @@ static inline void load_sp0(struct tss_struct *tss,
16797 extern unsigned long mmu_cr4_features;
16798 extern u32 *trampoline_cr4_features;
16799
16800-static inline void set_in_cr4(unsigned long mask)
16801-{
16802- unsigned long cr4;
16803-
16804- mmu_cr4_features |= mask;
16805- if (trampoline_cr4_features)
16806- *trampoline_cr4_features = mmu_cr4_features;
16807- cr4 = read_cr4();
16808- cr4 |= mask;
16809- write_cr4(cr4);
16810-}
16811-
16812-static inline void clear_in_cr4(unsigned long mask)
16813-{
16814- unsigned long cr4;
16815-
16816- mmu_cr4_features &= ~mask;
16817- if (trampoline_cr4_features)
16818- *trampoline_cr4_features = mmu_cr4_features;
16819- cr4 = read_cr4();
16820- cr4 &= ~mask;
16821- write_cr4(cr4);
16822-}
16823+extern void set_in_cr4(unsigned long mask);
16824+extern void clear_in_cr4(unsigned long mask);
16825
16826 typedef struct {
16827 unsigned long seg;
16828@@ -824,11 +816,18 @@ static inline void spin_lock_prefetch(const void *x)
16829 */
16830 #define TASK_SIZE PAGE_OFFSET
16831 #define TASK_SIZE_MAX TASK_SIZE
16832+
16833+#ifdef CONFIG_PAX_SEGMEXEC
16834+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
16835+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
16836+#else
16837 #define STACK_TOP TASK_SIZE
16838-#define STACK_TOP_MAX STACK_TOP
16839+#endif
16840+
16841+#define STACK_TOP_MAX TASK_SIZE
16842
16843 #define INIT_THREAD { \
16844- .sp0 = sizeof(init_stack) + (long)&init_stack, \
16845+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
16846 .vm86_info = NULL, \
16847 .sysenter_cs = __KERNEL_CS, \
16848 .io_bitmap_ptr = NULL, \
16849@@ -842,7 +841,7 @@ static inline void spin_lock_prefetch(const void *x)
16850 */
16851 #define INIT_TSS { \
16852 .x86_tss = { \
16853- .sp0 = sizeof(init_stack) + (long)&init_stack, \
16854+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
16855 .ss0 = __KERNEL_DS, \
16856 .ss1 = __KERNEL_CS, \
16857 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
16858@@ -853,11 +852,7 @@ static inline void spin_lock_prefetch(const void *x)
16859 extern unsigned long thread_saved_pc(struct task_struct *tsk);
16860
16861 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
16862-#define KSTK_TOP(info) \
16863-({ \
16864- unsigned long *__ptr = (unsigned long *)(info); \
16865- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
16866-})
16867+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
16868
16869 /*
16870 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
16871@@ -872,7 +867,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
16872 #define task_pt_regs(task) \
16873 ({ \
16874 struct pt_regs *__regs__; \
16875- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
16876+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
16877 __regs__ - 1; \
16878 })
16879
16880@@ -882,13 +877,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
16881 /*
16882 * User space process size. 47bits minus one guard page.
16883 */
16884-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
16885+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
16886
16887 /* This decides where the kernel will search for a free chunk of vm
16888 * space during mmap's.
16889 */
16890 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
16891- 0xc0000000 : 0xFFFFe000)
16892+ 0xc0000000 : 0xFFFFf000)
16893
16894 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
16895 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
16896@@ -899,11 +894,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
16897 #define STACK_TOP_MAX TASK_SIZE_MAX
16898
16899 #define INIT_THREAD { \
16900- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
16901+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
16902 }
16903
16904 #define INIT_TSS { \
16905- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
16906+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
16907 }
16908
16909 /*
16910@@ -931,6 +926,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
16911 */
16912 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
16913
16914+#ifdef CONFIG_PAX_SEGMEXEC
16915+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
16916+#endif
16917+
16918 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
16919
16920 /* Get/set a process' ability to use the timestamp counter instruction */
16921@@ -943,7 +942,8 @@ extern int set_tsc_mode(unsigned int val);
16922 extern u16 amd_get_nb_id(int cpu);
16923
16924 struct aperfmperf {
16925- u64 aperf, mperf;
16926+ u64 aperf __intentional_overflow(0);
16927+ u64 mperf __intentional_overflow(0);
16928 };
16929
16930 static inline void get_aperfmperf(struct aperfmperf *am)
16931@@ -971,7 +971,7 @@ unsigned long calc_aperfmperf_ratio(struct aperfmperf *old,
16932 return ratio;
16933 }
16934
16935-extern unsigned long arch_align_stack(unsigned long sp);
16936+#define arch_align_stack(x) ((x) & ~0xfUL)
16937 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
16938
16939 void default_idle(void);
16940@@ -981,6 +981,6 @@ bool xen_set_default_idle(void);
16941 #define xen_set_default_idle 0
16942 #endif
16943
16944-void stop_this_cpu(void *dummy);
16945+void stop_this_cpu(void *dummy) __noreturn;
16946 void df_debug(struct pt_regs *regs, long error_code);
16947 #endif /* _ASM_X86_PROCESSOR_H */
16948diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
16949index 942a086..6c26446 100644
16950--- a/arch/x86/include/asm/ptrace.h
16951+++ b/arch/x86/include/asm/ptrace.h
16952@@ -85,28 +85,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
16953 }
16954
16955 /*
16956- * user_mode_vm(regs) determines whether a register set came from user mode.
16957+ * user_mode(regs) determines whether a register set came from user mode.
16958 * This is true if V8086 mode was enabled OR if the register set was from
16959 * protected mode with RPL-3 CS value. This tricky test checks that with
16960 * one comparison. Many places in the kernel can bypass this full check
16961- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
16962+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
16963+ * be used.
16964 */
16965-static inline int user_mode(struct pt_regs *regs)
16966+static inline int user_mode_novm(struct pt_regs *regs)
16967 {
16968 #ifdef CONFIG_X86_32
16969 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
16970 #else
16971- return !!(regs->cs & 3);
16972+ return !!(regs->cs & SEGMENT_RPL_MASK);
16973 #endif
16974 }
16975
16976-static inline int user_mode_vm(struct pt_regs *regs)
16977+static inline int user_mode(struct pt_regs *regs)
16978 {
16979 #ifdef CONFIG_X86_32
16980 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
16981 USER_RPL;
16982 #else
16983- return user_mode(regs);
16984+ return user_mode_novm(regs);
16985 #endif
16986 }
16987
16988@@ -122,15 +123,16 @@ static inline int v8086_mode(struct pt_regs *regs)
16989 #ifdef CONFIG_X86_64
16990 static inline bool user_64bit_mode(struct pt_regs *regs)
16991 {
16992+ unsigned long cs = regs->cs & 0xffff;
16993 #ifndef CONFIG_PARAVIRT
16994 /*
16995 * On non-paravirt systems, this is the only long mode CPL 3
16996 * selector. We do not allow long mode selectors in the LDT.
16997 */
16998- return regs->cs == __USER_CS;
16999+ return cs == __USER_CS;
17000 #else
17001 /* Headers are too twisted for this to go in paravirt.h. */
17002- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
17003+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
17004 #endif
17005 }
17006
17007@@ -181,9 +183,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
17008 * Traps from the kernel do not save sp and ss.
17009 * Use the helper function to retrieve sp.
17010 */
17011- if (offset == offsetof(struct pt_regs, sp) &&
17012- regs->cs == __KERNEL_CS)
17013- return kernel_stack_pointer(regs);
17014+ if (offset == offsetof(struct pt_regs, sp)) {
17015+ unsigned long cs = regs->cs & 0xffff;
17016+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
17017+ return kernel_stack_pointer(regs);
17018+ }
17019 #endif
17020 return *(unsigned long *)((unsigned long)regs + offset);
17021 }
17022diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
17023index 9c6b890..5305f53 100644
17024--- a/arch/x86/include/asm/realmode.h
17025+++ b/arch/x86/include/asm/realmode.h
17026@@ -22,16 +22,14 @@ struct real_mode_header {
17027 #endif
17028 /* APM/BIOS reboot */
17029 u32 machine_real_restart_asm;
17030-#ifdef CONFIG_X86_64
17031 u32 machine_real_restart_seg;
17032-#endif
17033 };
17034
17035 /* This must match data at trampoline_32/64.S */
17036 struct trampoline_header {
17037 #ifdef CONFIG_X86_32
17038 u32 start;
17039- u16 gdt_pad;
17040+ u16 boot_cs;
17041 u16 gdt_limit;
17042 u32 gdt_base;
17043 #else
17044diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
17045index a82c4f1..ac45053 100644
17046--- a/arch/x86/include/asm/reboot.h
17047+++ b/arch/x86/include/asm/reboot.h
17048@@ -6,13 +6,13 @@
17049 struct pt_regs;
17050
17051 struct machine_ops {
17052- void (*restart)(char *cmd);
17053- void (*halt)(void);
17054- void (*power_off)(void);
17055+ void (* __noreturn restart)(char *cmd);
17056+ void (* __noreturn halt)(void);
17057+ void (* __noreturn power_off)(void);
17058 void (*shutdown)(void);
17059 void (*crash_shutdown)(struct pt_regs *);
17060- void (*emergency_restart)(void);
17061-};
17062+ void (* __noreturn emergency_restart)(void);
17063+} __no_const;
17064
17065 extern struct machine_ops machine_ops;
17066
17067diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
17068index cad82c9..2e5c5c1 100644
17069--- a/arch/x86/include/asm/rwsem.h
17070+++ b/arch/x86/include/asm/rwsem.h
17071@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
17072 {
17073 asm volatile("# beginning down_read\n\t"
17074 LOCK_PREFIX _ASM_INC "(%1)\n\t"
17075+
17076+#ifdef CONFIG_PAX_REFCOUNT
17077+ "jno 0f\n"
17078+ LOCK_PREFIX _ASM_DEC "(%1)\n"
17079+ "int $4\n0:\n"
17080+ _ASM_EXTABLE(0b, 0b)
17081+#endif
17082+
17083 /* adds 0x00000001 */
17084 " jns 1f\n"
17085 " call call_rwsem_down_read_failed\n"
17086@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
17087 "1:\n\t"
17088 " mov %1,%2\n\t"
17089 " add %3,%2\n\t"
17090+
17091+#ifdef CONFIG_PAX_REFCOUNT
17092+ "jno 0f\n"
17093+ "sub %3,%2\n"
17094+ "int $4\n0:\n"
17095+ _ASM_EXTABLE(0b, 0b)
17096+#endif
17097+
17098 " jle 2f\n\t"
17099 LOCK_PREFIX " cmpxchg %2,%0\n\t"
17100 " jnz 1b\n\t"
17101@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
17102 long tmp;
17103 asm volatile("# beginning down_write\n\t"
17104 LOCK_PREFIX " xadd %1,(%2)\n\t"
17105+
17106+#ifdef CONFIG_PAX_REFCOUNT
17107+ "jno 0f\n"
17108+ "mov %1,(%2)\n"
17109+ "int $4\n0:\n"
17110+ _ASM_EXTABLE(0b, 0b)
17111+#endif
17112+
17113 /* adds 0xffff0001, returns the old value */
17114 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
17115 /* was the active mask 0 before? */
17116@@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
17117 long tmp;
17118 asm volatile("# beginning __up_read\n\t"
17119 LOCK_PREFIX " xadd %1,(%2)\n\t"
17120+
17121+#ifdef CONFIG_PAX_REFCOUNT
17122+ "jno 0f\n"
17123+ "mov %1,(%2)\n"
17124+ "int $4\n0:\n"
17125+ _ASM_EXTABLE(0b, 0b)
17126+#endif
17127+
17128 /* subtracts 1, returns the old value */
17129 " jns 1f\n\t"
17130 " call call_rwsem_wake\n" /* expects old value in %edx */
17131@@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
17132 long tmp;
17133 asm volatile("# beginning __up_write\n\t"
17134 LOCK_PREFIX " xadd %1,(%2)\n\t"
17135+
17136+#ifdef CONFIG_PAX_REFCOUNT
17137+ "jno 0f\n"
17138+ "mov %1,(%2)\n"
17139+ "int $4\n0:\n"
17140+ _ASM_EXTABLE(0b, 0b)
17141+#endif
17142+
17143 /* subtracts 0xffff0001, returns the old value */
17144 " jns 1f\n\t"
17145 " call call_rwsem_wake\n" /* expects old value in %edx */
17146@@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
17147 {
17148 asm volatile("# beginning __downgrade_write\n\t"
17149 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
17150+
17151+#ifdef CONFIG_PAX_REFCOUNT
17152+ "jno 0f\n"
17153+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
17154+ "int $4\n0:\n"
17155+ _ASM_EXTABLE(0b, 0b)
17156+#endif
17157+
17158 /*
17159 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
17160 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
17161@@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
17162 */
17163 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
17164 {
17165- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
17166+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
17167+
17168+#ifdef CONFIG_PAX_REFCOUNT
17169+ "jno 0f\n"
17170+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
17171+ "int $4\n0:\n"
17172+ _ASM_EXTABLE(0b, 0b)
17173+#endif
17174+
17175 : "+m" (sem->count)
17176 : "er" (delta));
17177 }
17178@@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
17179 */
17180 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
17181 {
17182- return delta + xadd(&sem->count, delta);
17183+ return delta + xadd_check_overflow(&sem->count, delta);
17184 }
17185
17186 #endif /* __KERNEL__ */
17187diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
17188index c48a950..bc40804 100644
17189--- a/arch/x86/include/asm/segment.h
17190+++ b/arch/x86/include/asm/segment.h
17191@@ -64,10 +64,15 @@
17192 * 26 - ESPFIX small SS
17193 * 27 - per-cpu [ offset to per-cpu data area ]
17194 * 28 - stack_canary-20 [ for stack protector ]
17195- * 29 - unused
17196- * 30 - unused
17197+ * 29 - PCI BIOS CS
17198+ * 30 - PCI BIOS DS
17199 * 31 - TSS for double fault handler
17200 */
17201+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
17202+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
17203+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
17204+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
17205+
17206 #define GDT_ENTRY_TLS_MIN 6
17207 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
17208
17209@@ -79,6 +84,8 @@
17210
17211 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
17212
17213+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
17214+
17215 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
17216
17217 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
17218@@ -104,6 +111,12 @@
17219 #define __KERNEL_STACK_CANARY 0
17220 #endif
17221
17222+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
17223+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
17224+
17225+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
17226+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
17227+
17228 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
17229
17230 /*
17231@@ -141,7 +154,7 @@
17232 */
17233
17234 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
17235-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
17236+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
17237
17238
17239 #else
17240@@ -165,6 +178,8 @@
17241 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
17242 #define __USER32_DS __USER_DS
17243
17244+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
17245+
17246 #define GDT_ENTRY_TSS 8 /* needs two entries */
17247 #define GDT_ENTRY_LDT 10 /* needs two entries */
17248 #define GDT_ENTRY_TLS_MIN 12
17249@@ -173,6 +188,8 @@
17250 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
17251 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
17252
17253+#define GDT_ENTRY_UDEREF_KERNEL_DS 16
17254+
17255 /* TLS indexes for 64bit - hardcoded in arch_prctl */
17256 #define FS_TLS 0
17257 #define GS_TLS 1
17258@@ -180,12 +197,14 @@
17259 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
17260 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
17261
17262-#define GDT_ENTRIES 16
17263+#define GDT_ENTRIES 17
17264
17265 #endif
17266
17267 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
17268+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
17269 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
17270+#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
17271 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
17272 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
17273 #ifndef CONFIG_PARAVIRT
17274@@ -265,7 +284,7 @@ static inline unsigned long get_limit(unsigned long segment)
17275 {
17276 unsigned long __limit;
17277 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
17278- return __limit + 1;
17279+ return __limit;
17280 }
17281
17282 #endif /* !__ASSEMBLY__ */
17283diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
17284index 8d3120f..352b440 100644
17285--- a/arch/x86/include/asm/smap.h
17286+++ b/arch/x86/include/asm/smap.h
17287@@ -25,11 +25,40 @@
17288
17289 #include <asm/alternative-asm.h>
17290
17291+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17292+#define ASM_PAX_OPEN_USERLAND \
17293+ 661: jmp 663f; \
17294+ .pushsection .altinstr_replacement, "a" ; \
17295+ 662: pushq %rax; nop; \
17296+ .popsection ; \
17297+ .pushsection .altinstructions, "a" ; \
17298+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
17299+ .popsection ; \
17300+ call __pax_open_userland; \
17301+ popq %rax; \
17302+ 663:
17303+
17304+#define ASM_PAX_CLOSE_USERLAND \
17305+ 661: jmp 663f; \
17306+ .pushsection .altinstr_replacement, "a" ; \
17307+ 662: pushq %rax; nop; \
17308+ .popsection; \
17309+ .pushsection .altinstructions, "a" ; \
17310+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
17311+ .popsection; \
17312+ call __pax_close_userland; \
17313+ popq %rax; \
17314+ 663:
17315+#else
17316+#define ASM_PAX_OPEN_USERLAND
17317+#define ASM_PAX_CLOSE_USERLAND
17318+#endif
17319+
17320 #ifdef CONFIG_X86_SMAP
17321
17322 #define ASM_CLAC \
17323 661: ASM_NOP3 ; \
17324- .pushsection .altinstr_replacement, "ax" ; \
17325+ .pushsection .altinstr_replacement, "a" ; \
17326 662: __ASM_CLAC ; \
17327 .popsection ; \
17328 .pushsection .altinstructions, "a" ; \
17329@@ -38,7 +67,7 @@
17330
17331 #define ASM_STAC \
17332 661: ASM_NOP3 ; \
17333- .pushsection .altinstr_replacement, "ax" ; \
17334+ .pushsection .altinstr_replacement, "a" ; \
17335 662: __ASM_STAC ; \
17336 .popsection ; \
17337 .pushsection .altinstructions, "a" ; \
17338@@ -56,6 +85,37 @@
17339
17340 #include <asm/alternative.h>
17341
17342+#define __HAVE_ARCH_PAX_OPEN_USERLAND
17343+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
17344+
17345+extern void __pax_open_userland(void);
17346+static __always_inline unsigned long pax_open_userland(void)
17347+{
17348+
17349+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17350+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
17351+ :
17352+ : [open] "i" (__pax_open_userland)
17353+ : "memory", "rax");
17354+#endif
17355+
17356+ return 0;
17357+}
17358+
17359+extern void __pax_close_userland(void);
17360+static __always_inline unsigned long pax_close_userland(void)
17361+{
17362+
17363+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17364+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
17365+ :
17366+ : [close] "i" (__pax_close_userland)
17367+ : "memory", "rax");
17368+#endif
17369+
17370+ return 0;
17371+}
17372+
17373 #ifdef CONFIG_X86_SMAP
17374
17375 static __always_inline void clac(void)
17376diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
17377index 4137890..03fa172 100644
17378--- a/arch/x86/include/asm/smp.h
17379+++ b/arch/x86/include/asm/smp.h
17380@@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
17381 /* cpus sharing the last level cache: */
17382 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
17383 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
17384-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
17385+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
17386
17387 static inline struct cpumask *cpu_sibling_mask(int cpu)
17388 {
17389@@ -79,7 +79,7 @@ struct smp_ops {
17390
17391 void (*send_call_func_ipi)(const struct cpumask *mask);
17392 void (*send_call_func_single_ipi)(int cpu);
17393-};
17394+} __no_const;
17395
17396 /* Globals due to paravirt */
17397 extern void set_cpu_sibling_map(int cpu);
17398@@ -191,14 +191,8 @@ extern unsigned disabled_cpus;
17399 extern int safe_smp_processor_id(void);
17400
17401 #elif defined(CONFIG_X86_64_SMP)
17402-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
17403-
17404-#define stack_smp_processor_id() \
17405-({ \
17406- struct thread_info *ti; \
17407- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
17408- ti->cpu; \
17409-})
17410+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
17411+#define stack_smp_processor_id() raw_smp_processor_id()
17412 #define safe_smp_processor_id() smp_processor_id()
17413
17414 #endif
17415diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
17416index e3ddd7d..3611fce 100644
17417--- a/arch/x86/include/asm/spinlock.h
17418+++ b/arch/x86/include/asm/spinlock.h
17419@@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
17420 static inline void arch_read_lock(arch_rwlock_t *rw)
17421 {
17422 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
17423+
17424+#ifdef CONFIG_PAX_REFCOUNT
17425+ "jno 0f\n"
17426+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
17427+ "int $4\n0:\n"
17428+ _ASM_EXTABLE(0b, 0b)
17429+#endif
17430+
17431 "jns 1f\n"
17432 "call __read_lock_failed\n\t"
17433 "1:\n"
17434@@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
17435 static inline void arch_write_lock(arch_rwlock_t *rw)
17436 {
17437 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
17438+
17439+#ifdef CONFIG_PAX_REFCOUNT
17440+ "jno 0f\n"
17441+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
17442+ "int $4\n0:\n"
17443+ _ASM_EXTABLE(0b, 0b)
17444+#endif
17445+
17446 "jz 1f\n"
17447 "call __write_lock_failed\n\t"
17448 "1:\n"
17449@@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
17450
17451 static inline void arch_read_unlock(arch_rwlock_t *rw)
17452 {
17453- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
17454+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
17455+
17456+#ifdef CONFIG_PAX_REFCOUNT
17457+ "jno 0f\n"
17458+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
17459+ "int $4\n0:\n"
17460+ _ASM_EXTABLE(0b, 0b)
17461+#endif
17462+
17463 :"+m" (rw->lock) : : "memory");
17464 }
17465
17466 static inline void arch_write_unlock(arch_rwlock_t *rw)
17467 {
17468- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
17469+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
17470+
17471+#ifdef CONFIG_PAX_REFCOUNT
17472+ "jno 0f\n"
17473+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
17474+ "int $4\n0:\n"
17475+ _ASM_EXTABLE(0b, 0b)
17476+#endif
17477+
17478 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
17479 }
17480
17481diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
17482index 6a99859..03cb807 100644
17483--- a/arch/x86/include/asm/stackprotector.h
17484+++ b/arch/x86/include/asm/stackprotector.h
17485@@ -47,7 +47,7 @@
17486 * head_32 for boot CPU and setup_per_cpu_areas() for others.
17487 */
17488 #define GDT_STACK_CANARY_INIT \
17489- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
17490+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
17491
17492 /*
17493 * Initialize the stackprotector canary value.
17494@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
17495
17496 static inline void load_stack_canary_segment(void)
17497 {
17498-#ifdef CONFIG_X86_32
17499+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
17500 asm volatile ("mov %0, %%gs" : : "r" (0));
17501 #endif
17502 }
17503diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
17504index 70bbe39..4ae2bd4 100644
17505--- a/arch/x86/include/asm/stacktrace.h
17506+++ b/arch/x86/include/asm/stacktrace.h
17507@@ -11,28 +11,20 @@
17508
17509 extern int kstack_depth_to_print;
17510
17511-struct thread_info;
17512+struct task_struct;
17513 struct stacktrace_ops;
17514
17515-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
17516- unsigned long *stack,
17517- unsigned long bp,
17518- const struct stacktrace_ops *ops,
17519- void *data,
17520- unsigned long *end,
17521- int *graph);
17522+typedef unsigned long walk_stack_t(struct task_struct *task,
17523+ void *stack_start,
17524+ unsigned long *stack,
17525+ unsigned long bp,
17526+ const struct stacktrace_ops *ops,
17527+ void *data,
17528+ unsigned long *end,
17529+ int *graph);
17530
17531-extern unsigned long
17532-print_context_stack(struct thread_info *tinfo,
17533- unsigned long *stack, unsigned long bp,
17534- const struct stacktrace_ops *ops, void *data,
17535- unsigned long *end, int *graph);
17536-
17537-extern unsigned long
17538-print_context_stack_bp(struct thread_info *tinfo,
17539- unsigned long *stack, unsigned long bp,
17540- const struct stacktrace_ops *ops, void *data,
17541- unsigned long *end, int *graph);
17542+extern walk_stack_t print_context_stack;
17543+extern walk_stack_t print_context_stack_bp;
17544
17545 /* Generic stack tracer with callbacks */
17546
17547@@ -40,7 +32,7 @@ struct stacktrace_ops {
17548 void (*address)(void *data, unsigned long address, int reliable);
17549 /* On negative return stop dumping */
17550 int (*stack)(void *data, char *name);
17551- walk_stack_t walk_stack;
17552+ walk_stack_t *walk_stack;
17553 };
17554
17555 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
17556diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
17557index 4ec45b3..a4f0a8a 100644
17558--- a/arch/x86/include/asm/switch_to.h
17559+++ b/arch/x86/include/asm/switch_to.h
17560@@ -108,7 +108,7 @@ do { \
17561 "call __switch_to\n\t" \
17562 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
17563 __switch_canary \
17564- "movq %P[thread_info](%%rsi),%%r8\n\t" \
17565+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
17566 "movq %%rax,%%rdi\n\t" \
17567 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
17568 "jnz ret_from_fork\n\t" \
17569@@ -119,7 +119,7 @@ do { \
17570 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
17571 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
17572 [_tif_fork] "i" (_TIF_FORK), \
17573- [thread_info] "i" (offsetof(struct task_struct, stack)), \
17574+ [thread_info] "m" (current_tinfo), \
17575 [current_task] "m" (current_task) \
17576 __switch_canary_iparam \
17577 : "memory", "cc" __EXTRA_CLOBBER)
17578diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
17579index 2781119..618b59b 100644
17580--- a/arch/x86/include/asm/thread_info.h
17581+++ b/arch/x86/include/asm/thread_info.h
17582@@ -10,6 +10,7 @@
17583 #include <linux/compiler.h>
17584 #include <asm/page.h>
17585 #include <asm/types.h>
17586+#include <asm/percpu.h>
17587
17588 /*
17589 * low level task data that entry.S needs immediate access to
17590@@ -23,7 +24,6 @@ struct exec_domain;
17591 #include <linux/atomic.h>
17592
17593 struct thread_info {
17594- struct task_struct *task; /* main task structure */
17595 struct exec_domain *exec_domain; /* execution domain */
17596 __u32 flags; /* low level flags */
17597 __u32 status; /* thread synchronous flags */
17598@@ -33,19 +33,13 @@ struct thread_info {
17599 mm_segment_t addr_limit;
17600 struct restart_block restart_block;
17601 void __user *sysenter_return;
17602-#ifdef CONFIG_X86_32
17603- unsigned long previous_esp; /* ESP of the previous stack in
17604- case of nested (IRQ) stacks
17605- */
17606- __u8 supervisor_stack[0];
17607-#endif
17608+ unsigned long lowest_stack;
17609 unsigned int sig_on_uaccess_error:1;
17610 unsigned int uaccess_err:1; /* uaccess failed */
17611 };
17612
17613-#define INIT_THREAD_INFO(tsk) \
17614+#define INIT_THREAD_INFO \
17615 { \
17616- .task = &tsk, \
17617 .exec_domain = &default_exec_domain, \
17618 .flags = 0, \
17619 .cpu = 0, \
17620@@ -56,7 +50,7 @@ struct thread_info {
17621 }, \
17622 }
17623
17624-#define init_thread_info (init_thread_union.thread_info)
17625+#define init_thread_info (init_thread_union.stack)
17626 #define init_stack (init_thread_union.stack)
17627
17628 #else /* !__ASSEMBLY__ */
17629@@ -96,6 +90,7 @@ struct thread_info {
17630 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
17631 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
17632 #define TIF_X32 30 /* 32-bit native x86-64 binary */
17633+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
17634
17635 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
17636 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
17637@@ -119,17 +114,18 @@ struct thread_info {
17638 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
17639 #define _TIF_ADDR32 (1 << TIF_ADDR32)
17640 #define _TIF_X32 (1 << TIF_X32)
17641+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
17642
17643 /* work to do in syscall_trace_enter() */
17644 #define _TIF_WORK_SYSCALL_ENTRY \
17645 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
17646 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
17647- _TIF_NOHZ)
17648+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
17649
17650 /* work to do in syscall_trace_leave() */
17651 #define _TIF_WORK_SYSCALL_EXIT \
17652 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
17653- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
17654+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
17655
17656 /* work to do on interrupt/exception return */
17657 #define _TIF_WORK_MASK \
17658@@ -140,7 +136,7 @@ struct thread_info {
17659 /* work to do on any return to user space */
17660 #define _TIF_ALLWORK_MASK \
17661 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
17662- _TIF_NOHZ)
17663+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
17664
17665 /* Only used for 64 bit */
17666 #define _TIF_DO_NOTIFY_MASK \
17667@@ -156,45 +152,40 @@ struct thread_info {
17668
17669 #define PREEMPT_ACTIVE 0x10000000
17670
17671-#ifdef CONFIG_X86_32
17672-
17673-#define STACK_WARN (THREAD_SIZE/8)
17674-/*
17675- * macros/functions for gaining access to the thread information structure
17676- *
17677- * preempt_count needs to be 1 initially, until the scheduler is functional.
17678- */
17679-#ifndef __ASSEMBLY__
17680-
17681-
17682-/* how to get the current stack pointer from C */
17683-register unsigned long current_stack_pointer asm("esp") __used;
17684-
17685-/* how to get the thread information struct from C */
17686-static inline struct thread_info *current_thread_info(void)
17687-{
17688- return (struct thread_info *)
17689- (current_stack_pointer & ~(THREAD_SIZE - 1));
17690-}
17691-
17692-#else /* !__ASSEMBLY__ */
17693-
17694+#ifdef __ASSEMBLY__
17695 /* how to get the thread information struct from ASM */
17696 #define GET_THREAD_INFO(reg) \
17697- movl $-THREAD_SIZE, reg; \
17698- andl %esp, reg
17699+ mov PER_CPU_VAR(current_tinfo), reg
17700
17701 /* use this one if reg already contains %esp */
17702-#define GET_THREAD_INFO_WITH_ESP(reg) \
17703- andl $-THREAD_SIZE, reg
17704+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
17705+#else
17706+/* how to get the thread information struct from C */
17707+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
17708+
17709+static __always_inline struct thread_info *current_thread_info(void)
17710+{
17711+ return this_cpu_read_stable(current_tinfo);
17712+}
17713+#endif
17714+
17715+#ifdef CONFIG_X86_32
17716+
17717+#define STACK_WARN (THREAD_SIZE/8)
17718+/*
17719+ * macros/functions for gaining access to the thread information structure
17720+ *
17721+ * preempt_count needs to be 1 initially, until the scheduler is functional.
17722+ */
17723+#ifndef __ASSEMBLY__
17724+
17725+/* how to get the current stack pointer from C */
17726+register unsigned long current_stack_pointer asm("esp") __used;
17727
17728 #endif
17729
17730 #else /* X86_32 */
17731
17732-#include <asm/percpu.h>
17733-#define KERNEL_STACK_OFFSET (5*8)
17734-
17735 /*
17736 * macros/functions for gaining access to the thread information structure
17737 * preempt_count needs to be 1 initially, until the scheduler is functional.
17738@@ -202,27 +193,8 @@ static inline struct thread_info *current_thread_info(void)
17739 #ifndef __ASSEMBLY__
17740 DECLARE_PER_CPU(unsigned long, kernel_stack);
17741
17742-static inline struct thread_info *current_thread_info(void)
17743-{
17744- struct thread_info *ti;
17745- ti = (void *)(this_cpu_read_stable(kernel_stack) +
17746- KERNEL_STACK_OFFSET - THREAD_SIZE);
17747- return ti;
17748-}
17749-
17750-#else /* !__ASSEMBLY__ */
17751-
17752-/* how to get the thread information struct from ASM */
17753-#define GET_THREAD_INFO(reg) \
17754- movq PER_CPU_VAR(kernel_stack),reg ; \
17755- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
17756-
17757-/*
17758- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
17759- * a certain register (to be used in assembler memory operands).
17760- */
17761-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
17762-
17763+/* how to get the current stack pointer from C */
17764+register unsigned long current_stack_pointer asm("rsp") __used;
17765 #endif
17766
17767 #endif /* !X86_32 */
17768@@ -281,5 +253,12 @@ static inline bool is_ia32_task(void)
17769 extern void arch_task_cache_init(void);
17770 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
17771 extern void arch_release_task_struct(struct task_struct *tsk);
17772+
17773+#define __HAVE_THREAD_FUNCTIONS
17774+#define task_thread_info(task) (&(task)->tinfo)
17775+#define task_stack_page(task) ((task)->stack)
17776+#define setup_thread_stack(p, org) do {} while (0)
17777+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
17778+
17779 #endif
17780 #endif /* _ASM_X86_THREAD_INFO_H */
17781diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
17782index cf51200..63ff068 100644
17783--- a/arch/x86/include/asm/tlbflush.h
17784+++ b/arch/x86/include/asm/tlbflush.h
17785@@ -17,18 +17,44 @@
17786
17787 static inline void __native_flush_tlb(void)
17788 {
17789+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17790+ u64 descriptor[2];
17791+
17792+ descriptor[0] = PCID_KERNEL;
17793+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_MONGLOBAL) : "memory");
17794+ return;
17795+ }
17796+
17797+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17798+ if (static_cpu_has(X86_FEATURE_PCID)) {
17799+ unsigned int cpu = raw_get_cpu();
17800+
17801+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17802+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17803+ raw_put_cpu_no_resched();
17804+ return;
17805+ }
17806+#endif
17807+
17808 native_write_cr3(native_read_cr3());
17809 }
17810
17811 static inline void __native_flush_tlb_global_irq_disabled(void)
17812 {
17813- unsigned long cr4;
17814+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17815+ u64 descriptor[2];
17816
17817- cr4 = native_read_cr4();
17818- /* clear PGE */
17819- native_write_cr4(cr4 & ~X86_CR4_PGE);
17820- /* write old PGE again and flush TLBs */
17821- native_write_cr4(cr4);
17822+ descriptor[0] = PCID_KERNEL;
17823+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
17824+ } else {
17825+ unsigned long cr4;
17826+
17827+ cr4 = native_read_cr4();
17828+ /* clear PGE */
17829+ native_write_cr4(cr4 & ~X86_CR4_PGE);
17830+ /* write old PGE again and flush TLBs */
17831+ native_write_cr4(cr4);
17832+ }
17833 }
17834
17835 static inline void __native_flush_tlb_global(void)
17836@@ -49,6 +75,42 @@ static inline void __native_flush_tlb_global(void)
17837
17838 static inline void __native_flush_tlb_single(unsigned long addr)
17839 {
17840+
17841+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17842+ u64 descriptor[2];
17843+
17844+ descriptor[0] = PCID_KERNEL;
17845+ descriptor[1] = addr;
17846+
17847+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17848+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
17849+ if (addr < TASK_SIZE_MAX)
17850+ descriptor[1] += pax_user_shadow_base;
17851+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
17852+ }
17853+
17854+ descriptor[0] = PCID_USER;
17855+ descriptor[1] = addr;
17856+#endif
17857+
17858+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
17859+ return;
17860+ }
17861+
17862+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17863+ if (static_cpu_has(X86_FEATURE_PCID)) {
17864+ unsigned int cpu = raw_get_cpu();
17865+
17866+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
17867+ asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
17868+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17869+ raw_put_cpu_no_resched();
17870+
17871+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
17872+ addr += pax_user_shadow_base;
17873+ }
17874+#endif
17875+
17876 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
17877 }
17878
17879diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
17880index 5ee2687..74590b9 100644
17881--- a/arch/x86/include/asm/uaccess.h
17882+++ b/arch/x86/include/asm/uaccess.h
17883@@ -7,6 +7,7 @@
17884 #include <linux/compiler.h>
17885 #include <linux/thread_info.h>
17886 #include <linux/string.h>
17887+#include <linux/sched.h>
17888 #include <asm/asm.h>
17889 #include <asm/page.h>
17890 #include <asm/smap.h>
17891@@ -29,7 +30,12 @@
17892
17893 #define get_ds() (KERNEL_DS)
17894 #define get_fs() (current_thread_info()->addr_limit)
17895+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
17896+void __set_fs(mm_segment_t x);
17897+void set_fs(mm_segment_t x);
17898+#else
17899 #define set_fs(x) (current_thread_info()->addr_limit = (x))
17900+#endif
17901
17902 #define segment_eq(a, b) ((a).seg == (b).seg)
17903
17904@@ -77,8 +83,33 @@
17905 * checks that the pointer is in the user space range - after calling
17906 * this function, memory access functions may still return -EFAULT.
17907 */
17908-#define access_ok(type, addr, size) \
17909- (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
17910+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
17911+#define access_ok(type, addr, size) \
17912+({ \
17913+ long __size = size; \
17914+ unsigned long __addr = (unsigned long)addr; \
17915+ unsigned long __addr_ao = __addr & PAGE_MASK; \
17916+ unsigned long __end_ao = __addr + __size - 1; \
17917+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
17918+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
17919+ while(__addr_ao <= __end_ao) { \
17920+ char __c_ao; \
17921+ __addr_ao += PAGE_SIZE; \
17922+ if (__size > PAGE_SIZE) \
17923+ cond_resched(); \
17924+ if (__get_user(__c_ao, (char __user *)__addr)) \
17925+ break; \
17926+ if (type != VERIFY_WRITE) { \
17927+ __addr = __addr_ao; \
17928+ continue; \
17929+ } \
17930+ if (__put_user(__c_ao, (char __user *)__addr)) \
17931+ break; \
17932+ __addr = __addr_ao; \
17933+ } \
17934+ } \
17935+ __ret_ao; \
17936+})
17937
17938 /*
17939 * The exception table consists of pairs of addresses relative to the
17940@@ -165,10 +196,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
17941 register __inttype(*(ptr)) __val_gu asm("%edx"); \
17942 __chk_user_ptr(ptr); \
17943 might_fault(); \
17944+ pax_open_userland(); \
17945 asm volatile("call __get_user_%P3" \
17946 : "=a" (__ret_gu), "=r" (__val_gu) \
17947 : "0" (ptr), "i" (sizeof(*(ptr)))); \
17948 (x) = (__typeof__(*(ptr))) __val_gu; \
17949+ pax_close_userland(); \
17950 __ret_gu; \
17951 })
17952
17953@@ -176,13 +209,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
17954 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
17955 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
17956
17957-
17958+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
17959+#define __copyuser_seg "gs;"
17960+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
17961+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
17962+#else
17963+#define __copyuser_seg
17964+#define __COPYUSER_SET_ES
17965+#define __COPYUSER_RESTORE_ES
17966+#endif
17967
17968 #ifdef CONFIG_X86_32
17969 #define __put_user_asm_u64(x, addr, err, errret) \
17970 asm volatile(ASM_STAC "\n" \
17971- "1: movl %%eax,0(%2)\n" \
17972- "2: movl %%edx,4(%2)\n" \
17973+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
17974+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
17975 "3: " ASM_CLAC "\n" \
17976 ".section .fixup,\"ax\"\n" \
17977 "4: movl %3,%0\n" \
17978@@ -195,8 +236,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
17979
17980 #define __put_user_asm_ex_u64(x, addr) \
17981 asm volatile(ASM_STAC "\n" \
17982- "1: movl %%eax,0(%1)\n" \
17983- "2: movl %%edx,4(%1)\n" \
17984+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
17985+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
17986 "3: " ASM_CLAC "\n" \
17987 _ASM_EXTABLE_EX(1b, 2b) \
17988 _ASM_EXTABLE_EX(2b, 3b) \
17989@@ -246,7 +287,8 @@ extern void __put_user_8(void);
17990 __typeof__(*(ptr)) __pu_val; \
17991 __chk_user_ptr(ptr); \
17992 might_fault(); \
17993- __pu_val = x; \
17994+ __pu_val = (x); \
17995+ pax_open_userland(); \
17996 switch (sizeof(*(ptr))) { \
17997 case 1: \
17998 __put_user_x(1, __pu_val, ptr, __ret_pu); \
17999@@ -264,6 +306,7 @@ extern void __put_user_8(void);
18000 __put_user_x(X, __pu_val, ptr, __ret_pu); \
18001 break; \
18002 } \
18003+ pax_close_userland(); \
18004 __ret_pu; \
18005 })
18006
18007@@ -344,8 +387,10 @@ do { \
18008 } while (0)
18009
18010 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
18011+do { \
18012+ pax_open_userland(); \
18013 asm volatile(ASM_STAC "\n" \
18014- "1: mov"itype" %2,%"rtype"1\n" \
18015+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
18016 "2: " ASM_CLAC "\n" \
18017 ".section .fixup,\"ax\"\n" \
18018 "3: mov %3,%0\n" \
18019@@ -353,8 +398,10 @@ do { \
18020 " jmp 2b\n" \
18021 ".previous\n" \
18022 _ASM_EXTABLE(1b, 3b) \
18023- : "=r" (err), ltype(x) \
18024- : "m" (__m(addr)), "i" (errret), "0" (err))
18025+ : "=r" (err), ltype (x) \
18026+ : "m" (__m(addr)), "i" (errret), "0" (err)); \
18027+ pax_close_userland(); \
18028+} while (0)
18029
18030 #define __get_user_size_ex(x, ptr, size) \
18031 do { \
18032@@ -378,7 +425,7 @@ do { \
18033 } while (0)
18034
18035 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
18036- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
18037+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
18038 "2:\n" \
18039 _ASM_EXTABLE_EX(1b, 2b) \
18040 : ltype(x) : "m" (__m(addr)))
18041@@ -395,13 +442,24 @@ do { \
18042 int __gu_err; \
18043 unsigned long __gu_val; \
18044 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
18045- (x) = (__force __typeof__(*(ptr)))__gu_val; \
18046+ (x) = (__typeof__(*(ptr)))__gu_val; \
18047 __gu_err; \
18048 })
18049
18050 /* FIXME: this hack is definitely wrong -AK */
18051 struct __large_struct { unsigned long buf[100]; };
18052-#define __m(x) (*(struct __large_struct __user *)(x))
18053+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18054+#define ____m(x) \
18055+({ \
18056+ unsigned long ____x = (unsigned long)(x); \
18057+ if (____x < pax_user_shadow_base) \
18058+ ____x += pax_user_shadow_base; \
18059+ (typeof(x))____x; \
18060+})
18061+#else
18062+#define ____m(x) (x)
18063+#endif
18064+#define __m(x) (*(struct __large_struct __user *)____m(x))
18065
18066 /*
18067 * Tell gcc we read from memory instead of writing: this is because
18068@@ -409,8 +467,10 @@ struct __large_struct { unsigned long buf[100]; };
18069 * aliasing issues.
18070 */
18071 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
18072+do { \
18073+ pax_open_userland(); \
18074 asm volatile(ASM_STAC "\n" \
18075- "1: mov"itype" %"rtype"1,%2\n" \
18076+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
18077 "2: " ASM_CLAC "\n" \
18078 ".section .fixup,\"ax\"\n" \
18079 "3: mov %3,%0\n" \
18080@@ -418,10 +478,12 @@ struct __large_struct { unsigned long buf[100]; };
18081 ".previous\n" \
18082 _ASM_EXTABLE(1b, 3b) \
18083 : "=r"(err) \
18084- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
18085+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
18086+ pax_close_userland(); \
18087+} while (0)
18088
18089 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
18090- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
18091+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
18092 "2:\n" \
18093 _ASM_EXTABLE_EX(1b, 2b) \
18094 : : ltype(x), "m" (__m(addr)))
18095@@ -431,11 +493,13 @@ struct __large_struct { unsigned long buf[100]; };
18096 */
18097 #define uaccess_try do { \
18098 current_thread_info()->uaccess_err = 0; \
18099+ pax_open_userland(); \
18100 stac(); \
18101 barrier();
18102
18103 #define uaccess_catch(err) \
18104 clac(); \
18105+ pax_close_userland(); \
18106 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
18107 } while (0)
18108
18109@@ -460,8 +524,12 @@ struct __large_struct { unsigned long buf[100]; };
18110 * On error, the variable @x is set to zero.
18111 */
18112
18113+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18114+#define __get_user(x, ptr) get_user((x), (ptr))
18115+#else
18116 #define __get_user(x, ptr) \
18117 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
18118+#endif
18119
18120 /**
18121 * __put_user: - Write a simple value into user space, with less checking.
18122@@ -483,8 +551,12 @@ struct __large_struct { unsigned long buf[100]; };
18123 * Returns zero on success, or -EFAULT on error.
18124 */
18125
18126+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18127+#define __put_user(x, ptr) put_user((x), (ptr))
18128+#else
18129 #define __put_user(x, ptr) \
18130 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
18131+#endif
18132
18133 #define __get_user_unaligned __get_user
18134 #define __put_user_unaligned __put_user
18135@@ -502,7 +574,7 @@ struct __large_struct { unsigned long buf[100]; };
18136 #define get_user_ex(x, ptr) do { \
18137 unsigned long __gue_val; \
18138 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
18139- (x) = (__force __typeof__(*(ptr)))__gue_val; \
18140+ (x) = (__typeof__(*(ptr)))__gue_val; \
18141 } while (0)
18142
18143 #define put_user_try uaccess_try
18144@@ -519,8 +591,8 @@ strncpy_from_user(char *dst, const char __user *src, long count);
18145 extern __must_check long strlen_user(const char __user *str);
18146 extern __must_check long strnlen_user(const char __user *str, long n);
18147
18148-unsigned long __must_check clear_user(void __user *mem, unsigned long len);
18149-unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
18150+unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
18151+unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
18152
18153 /*
18154 * movsl can be slow when source and dest are not both 8-byte aligned
18155diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
18156index 7f760a9..04b1c65 100644
18157--- a/arch/x86/include/asm/uaccess_32.h
18158+++ b/arch/x86/include/asm/uaccess_32.h
18159@@ -11,15 +11,15 @@
18160 #include <asm/page.h>
18161
18162 unsigned long __must_check __copy_to_user_ll
18163- (void __user *to, const void *from, unsigned long n);
18164+ (void __user *to, const void *from, unsigned long n) __size_overflow(3);
18165 unsigned long __must_check __copy_from_user_ll
18166- (void *to, const void __user *from, unsigned long n);
18167+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
18168 unsigned long __must_check __copy_from_user_ll_nozero
18169- (void *to, const void __user *from, unsigned long n);
18170+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
18171 unsigned long __must_check __copy_from_user_ll_nocache
18172- (void *to, const void __user *from, unsigned long n);
18173+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
18174 unsigned long __must_check __copy_from_user_ll_nocache_nozero
18175- (void *to, const void __user *from, unsigned long n);
18176+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
18177
18178 /**
18179 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
18180@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
18181 static __always_inline unsigned long __must_check
18182 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
18183 {
18184+ if ((long)n < 0)
18185+ return n;
18186+
18187+ check_object_size(from, n, true);
18188+
18189 if (__builtin_constant_p(n)) {
18190 unsigned long ret;
18191
18192@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
18193 __copy_to_user(void __user *to, const void *from, unsigned long n)
18194 {
18195 might_fault();
18196+
18197 return __copy_to_user_inatomic(to, from, n);
18198 }
18199
18200 static __always_inline unsigned long
18201 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
18202 {
18203+ if ((long)n < 0)
18204+ return n;
18205+
18206 /* Avoid zeroing the tail if the copy fails..
18207 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
18208 * but as the zeroing behaviour is only significant when n is not
18209@@ -137,6 +146,12 @@ static __always_inline unsigned long
18210 __copy_from_user(void *to, const void __user *from, unsigned long n)
18211 {
18212 might_fault();
18213+
18214+ if ((long)n < 0)
18215+ return n;
18216+
18217+ check_object_size(to, n, false);
18218+
18219 if (__builtin_constant_p(n)) {
18220 unsigned long ret;
18221
18222@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
18223 const void __user *from, unsigned long n)
18224 {
18225 might_fault();
18226+
18227+ if ((long)n < 0)
18228+ return n;
18229+
18230 if (__builtin_constant_p(n)) {
18231 unsigned long ret;
18232
18233@@ -181,15 +200,19 @@ static __always_inline unsigned long
18234 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
18235 unsigned long n)
18236 {
18237- return __copy_from_user_ll_nocache_nozero(to, from, n);
18238+ if ((long)n < 0)
18239+ return n;
18240+
18241+ return __copy_from_user_ll_nocache_nozero(to, from, n);
18242 }
18243
18244-unsigned long __must_check copy_to_user(void __user *to,
18245- const void *from, unsigned long n);
18246-unsigned long __must_check _copy_from_user(void *to,
18247- const void __user *from,
18248- unsigned long n);
18249-
18250+extern void copy_to_user_overflow(void)
18251+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
18252+ __compiletime_error("copy_to_user() buffer size is not provably correct")
18253+#else
18254+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
18255+#endif
18256+;
18257
18258 extern void copy_from_user_overflow(void)
18259 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
18260@@ -199,17 +222,60 @@ extern void copy_from_user_overflow(void)
18261 #endif
18262 ;
18263
18264-static inline unsigned long __must_check copy_from_user(void *to,
18265- const void __user *from,
18266- unsigned long n)
18267+/**
18268+ * copy_to_user: - Copy a block of data into user space.
18269+ * @to: Destination address, in user space.
18270+ * @from: Source address, in kernel space.
18271+ * @n: Number of bytes to copy.
18272+ *
18273+ * Context: User context only. This function may sleep.
18274+ *
18275+ * Copy data from kernel space to user space.
18276+ *
18277+ * Returns number of bytes that could not be copied.
18278+ * On success, this will be zero.
18279+ */
18280+static inline unsigned long __must_check
18281+copy_to_user(void __user *to, const void *from, unsigned long n)
18282 {
18283- int sz = __compiletime_object_size(to);
18284+ size_t sz = __compiletime_object_size(from);
18285
18286- if (likely(sz == -1 || sz >= n))
18287- n = _copy_from_user(to, from, n);
18288- else
18289+ if (unlikely(sz != (size_t)-1 && sz < n))
18290+ copy_to_user_overflow();
18291+ else if (access_ok(VERIFY_WRITE, to, n))
18292+ n = __copy_to_user(to, from, n);
18293+ return n;
18294+}
18295+
18296+/**
18297+ * copy_from_user: - Copy a block of data from user space.
18298+ * @to: Destination address, in kernel space.
18299+ * @from: Source address, in user space.
18300+ * @n: Number of bytes to copy.
18301+ *
18302+ * Context: User context only. This function may sleep.
18303+ *
18304+ * Copy data from user space to kernel space.
18305+ *
18306+ * Returns number of bytes that could not be copied.
18307+ * On success, this will be zero.
18308+ *
18309+ * If some data could not be copied, this function will pad the copied
18310+ * data to the requested size using zero bytes.
18311+ */
18312+static inline unsigned long __must_check
18313+copy_from_user(void *to, const void __user *from, unsigned long n)
18314+{
18315+ size_t sz = __compiletime_object_size(to);
18316+
18317+ check_object_size(to, n, false);
18318+
18319+ if (unlikely(sz != (size_t)-1 && sz < n))
18320 copy_from_user_overflow();
18321-
18322+ else if (access_ok(VERIFY_READ, from, n))
18323+ n = __copy_from_user(to, from, n);
18324+ else if ((long)n > 0)
18325+ memset(to, 0, n);
18326 return n;
18327 }
18328
18329diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
18330index 4f7923d..20cb24e 100644
18331--- a/arch/x86/include/asm/uaccess_64.h
18332+++ b/arch/x86/include/asm/uaccess_64.h
18333@@ -10,6 +10,9 @@
18334 #include <asm/alternative.h>
18335 #include <asm/cpufeature.h>
18336 #include <asm/page.h>
18337+#include <asm/pgtable.h>
18338+
18339+#define set_fs(x) (current_thread_info()->addr_limit = (x))
18340
18341 /*
18342 * Copy To/From Userspace
18343@@ -17,13 +20,13 @@
18344
18345 /* Handles exceptions in both to and from, but doesn't do access_ok */
18346 __must_check unsigned long
18347-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
18348+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
18349 __must_check unsigned long
18350-copy_user_generic_string(void *to, const void *from, unsigned len);
18351+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
18352 __must_check unsigned long
18353-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
18354+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
18355
18356-static __always_inline __must_check unsigned long
18357+static __always_inline __must_check __size_overflow(3) unsigned long
18358 copy_user_generic(void *to, const void *from, unsigned len)
18359 {
18360 unsigned ret;
18361@@ -41,142 +44,204 @@ copy_user_generic(void *to, const void *from, unsigned len)
18362 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
18363 "=d" (len)),
18364 "1" (to), "2" (from), "3" (len)
18365- : "memory", "rcx", "r8", "r9", "r10", "r11");
18366+ : "memory", "rcx", "r8", "r9", "r11");
18367 return ret;
18368 }
18369
18370+static __always_inline __must_check unsigned long
18371+__copy_to_user(void __user *to, const void *from, unsigned long len);
18372+static __always_inline __must_check unsigned long
18373+__copy_from_user(void *to, const void __user *from, unsigned long len);
18374 __must_check unsigned long
18375-_copy_to_user(void __user *to, const void *from, unsigned len);
18376-__must_check unsigned long
18377-_copy_from_user(void *to, const void __user *from, unsigned len);
18378-__must_check unsigned long
18379-copy_in_user(void __user *to, const void __user *from, unsigned len);
18380+copy_in_user(void __user *to, const void __user *from, unsigned long len);
18381+
18382+extern void copy_to_user_overflow(void)
18383+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
18384+ __compiletime_error("copy_to_user() buffer size is not provably correct")
18385+#else
18386+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
18387+#endif
18388+;
18389+
18390+extern void copy_from_user_overflow(void)
18391+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
18392+ __compiletime_error("copy_from_user() buffer size is not provably correct")
18393+#else
18394+ __compiletime_warning("copy_from_user() buffer size is not provably correct")
18395+#endif
18396+;
18397
18398 static inline unsigned long __must_check copy_from_user(void *to,
18399 const void __user *from,
18400 unsigned long n)
18401 {
18402- int sz = __compiletime_object_size(to);
18403-
18404 might_fault();
18405- if (likely(sz == -1 || sz >= n))
18406- n = _copy_from_user(to, from, n);
18407-#ifdef CONFIG_DEBUG_VM
18408- else
18409- WARN(1, "Buffer overflow detected!\n");
18410-#endif
18411+
18412+ check_object_size(to, n, false);
18413+
18414+ if (access_ok(VERIFY_READ, from, n))
18415+ n = __copy_from_user(to, from, n);
18416+ else if (n < INT_MAX)
18417+ memset(to, 0, n);
18418 return n;
18419 }
18420
18421 static __always_inline __must_check
18422-int copy_to_user(void __user *dst, const void *src, unsigned size)
18423+int copy_to_user(void __user *dst, const void *src, unsigned long size)
18424 {
18425 might_fault();
18426
18427- return _copy_to_user(dst, src, size);
18428+ if (access_ok(VERIFY_WRITE, dst, size))
18429+ size = __copy_to_user(dst, src, size);
18430+ return size;
18431 }
18432
18433 static __always_inline __must_check
18434-int __copy_from_user(void *dst, const void __user *src, unsigned size)
18435+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
18436 {
18437- int ret = 0;
18438+ size_t sz = __compiletime_object_size(dst);
18439+ unsigned ret = 0;
18440
18441 might_fault();
18442+
18443+ if (size > INT_MAX)
18444+ return size;
18445+
18446+ check_object_size(dst, size, false);
18447+
18448+#ifdef CONFIG_PAX_MEMORY_UDEREF
18449+ if (!__access_ok(VERIFY_READ, src, size))
18450+ return size;
18451+#endif
18452+
18453+ if (unlikely(sz != (size_t)-1 && sz < size)) {
18454+ copy_from_user_overflow();
18455+ return size;
18456+ }
18457+
18458 if (!__builtin_constant_p(size))
18459- return copy_user_generic(dst, (__force void *)src, size);
18460+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
18461 switch (size) {
18462- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
18463+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
18464 ret, "b", "b", "=q", 1);
18465 return ret;
18466- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
18467+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
18468 ret, "w", "w", "=r", 2);
18469 return ret;
18470- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
18471+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
18472 ret, "l", "k", "=r", 4);
18473 return ret;
18474- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
18475+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
18476 ret, "q", "", "=r", 8);
18477 return ret;
18478 case 10:
18479- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
18480+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
18481 ret, "q", "", "=r", 10);
18482 if (unlikely(ret))
18483 return ret;
18484 __get_user_asm(*(u16 *)(8 + (char *)dst),
18485- (u16 __user *)(8 + (char __user *)src),
18486+ (const u16 __user *)(8 + (const char __user *)src),
18487 ret, "w", "w", "=r", 2);
18488 return ret;
18489 case 16:
18490- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
18491+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
18492 ret, "q", "", "=r", 16);
18493 if (unlikely(ret))
18494 return ret;
18495 __get_user_asm(*(u64 *)(8 + (char *)dst),
18496- (u64 __user *)(8 + (char __user *)src),
18497+ (const u64 __user *)(8 + (const char __user *)src),
18498 ret, "q", "", "=r", 8);
18499 return ret;
18500 default:
18501- return copy_user_generic(dst, (__force void *)src, size);
18502+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
18503 }
18504 }
18505
18506 static __always_inline __must_check
18507-int __copy_to_user(void __user *dst, const void *src, unsigned size)
18508+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
18509 {
18510- int ret = 0;
18511+ size_t sz = __compiletime_object_size(src);
18512+ unsigned ret = 0;
18513
18514 might_fault();
18515+
18516+ if (size > INT_MAX)
18517+ return size;
18518+
18519+ check_object_size(src, size, true);
18520+
18521+#ifdef CONFIG_PAX_MEMORY_UDEREF
18522+ if (!__access_ok(VERIFY_WRITE, dst, size))
18523+ return size;
18524+#endif
18525+
18526+ if (unlikely(sz != (size_t)-1 && sz < size)) {
18527+ copy_to_user_overflow();
18528+ return size;
18529+ }
18530+
18531 if (!__builtin_constant_p(size))
18532- return copy_user_generic((__force void *)dst, src, size);
18533+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
18534 switch (size) {
18535- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
18536+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
18537 ret, "b", "b", "iq", 1);
18538 return ret;
18539- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
18540+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
18541 ret, "w", "w", "ir", 2);
18542 return ret;
18543- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
18544+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
18545 ret, "l", "k", "ir", 4);
18546 return ret;
18547- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
18548+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
18549 ret, "q", "", "er", 8);
18550 return ret;
18551 case 10:
18552- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
18553+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
18554 ret, "q", "", "er", 10);
18555 if (unlikely(ret))
18556 return ret;
18557 asm("":::"memory");
18558- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
18559+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
18560 ret, "w", "w", "ir", 2);
18561 return ret;
18562 case 16:
18563- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
18564+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
18565 ret, "q", "", "er", 16);
18566 if (unlikely(ret))
18567 return ret;
18568 asm("":::"memory");
18569- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
18570+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
18571 ret, "q", "", "er", 8);
18572 return ret;
18573 default:
18574- return copy_user_generic((__force void *)dst, src, size);
18575+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
18576 }
18577 }
18578
18579 static __always_inline __must_check
18580-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18581+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
18582 {
18583- int ret = 0;
18584+ unsigned ret = 0;
18585
18586 might_fault();
18587+
18588+ if (size > INT_MAX)
18589+ return size;
18590+
18591+#ifdef CONFIG_PAX_MEMORY_UDEREF
18592+ if (!__access_ok(VERIFY_READ, src, size))
18593+ return size;
18594+ if (!__access_ok(VERIFY_WRITE, dst, size))
18595+ return size;
18596+#endif
18597+
18598 if (!__builtin_constant_p(size))
18599- return copy_user_generic((__force void *)dst,
18600- (__force void *)src, size);
18601+ return copy_user_generic((__force_kernel void *)____m(dst),
18602+ (__force_kernel const void *)____m(src), size);
18603 switch (size) {
18604 case 1: {
18605 u8 tmp;
18606- __get_user_asm(tmp, (u8 __user *)src,
18607+ __get_user_asm(tmp, (const u8 __user *)src,
18608 ret, "b", "b", "=q", 1);
18609 if (likely(!ret))
18610 __put_user_asm(tmp, (u8 __user *)dst,
18611@@ -185,7 +250,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18612 }
18613 case 2: {
18614 u16 tmp;
18615- __get_user_asm(tmp, (u16 __user *)src,
18616+ __get_user_asm(tmp, (const u16 __user *)src,
18617 ret, "w", "w", "=r", 2);
18618 if (likely(!ret))
18619 __put_user_asm(tmp, (u16 __user *)dst,
18620@@ -195,7 +260,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18621
18622 case 4: {
18623 u32 tmp;
18624- __get_user_asm(tmp, (u32 __user *)src,
18625+ __get_user_asm(tmp, (const u32 __user *)src,
18626 ret, "l", "k", "=r", 4);
18627 if (likely(!ret))
18628 __put_user_asm(tmp, (u32 __user *)dst,
18629@@ -204,7 +269,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18630 }
18631 case 8: {
18632 u64 tmp;
18633- __get_user_asm(tmp, (u64 __user *)src,
18634+ __get_user_asm(tmp, (const u64 __user *)src,
18635 ret, "q", "", "=r", 8);
18636 if (likely(!ret))
18637 __put_user_asm(tmp, (u64 __user *)dst,
18638@@ -212,41 +277,74 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
18639 return ret;
18640 }
18641 default:
18642- return copy_user_generic((__force void *)dst,
18643- (__force void *)src, size);
18644+ return copy_user_generic((__force_kernel void *)____m(dst),
18645+ (__force_kernel const void *)____m(src), size);
18646 }
18647 }
18648
18649-static __must_check __always_inline int
18650-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
18651+static __must_check __always_inline unsigned long
18652+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
18653 {
18654- return copy_user_generic(dst, (__force const void *)src, size);
18655+ if (size > INT_MAX)
18656+ return size;
18657+
18658+#ifdef CONFIG_PAX_MEMORY_UDEREF
18659+ if (!__access_ok(VERIFY_READ, src, size))
18660+ return size;
18661+#endif
18662+
18663+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
18664 }
18665
18666-static __must_check __always_inline int
18667-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
18668+static __must_check __always_inline unsigned long
18669+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
18670 {
18671- return copy_user_generic((__force void *)dst, src, size);
18672+ if (size > INT_MAX)
18673+ return size;
18674+
18675+#ifdef CONFIG_PAX_MEMORY_UDEREF
18676+ if (!__access_ok(VERIFY_WRITE, dst, size))
18677+ return size;
18678+#endif
18679+
18680+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
18681 }
18682
18683-extern long __copy_user_nocache(void *dst, const void __user *src,
18684- unsigned size, int zerorest);
18685+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
18686+ unsigned long size, int zerorest) __size_overflow(3);
18687
18688-static inline int
18689-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
18690+static inline unsigned long
18691+__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
18692 {
18693 might_fault();
18694+
18695+ if (size > INT_MAX)
18696+ return size;
18697+
18698+#ifdef CONFIG_PAX_MEMORY_UDEREF
18699+ if (!__access_ok(VERIFY_READ, src, size))
18700+ return size;
18701+#endif
18702+
18703 return __copy_user_nocache(dst, src, size, 1);
18704 }
18705
18706-static inline int
18707+static inline unsigned long
18708 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
18709- unsigned size)
18710+ unsigned long size)
18711 {
18712+ if (size > INT_MAX)
18713+ return size;
18714+
18715+#ifdef CONFIG_PAX_MEMORY_UDEREF
18716+ if (!__access_ok(VERIFY_READ, src, size))
18717+ return size;
18718+#endif
18719+
18720 return __copy_user_nocache(dst, src, size, 0);
18721 }
18722
18723 unsigned long
18724-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
18725+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
18726
18727 #endif /* _ASM_X86_UACCESS_64_H */
18728diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
18729index 5b238981..77fdd78 100644
18730--- a/arch/x86/include/asm/word-at-a-time.h
18731+++ b/arch/x86/include/asm/word-at-a-time.h
18732@@ -11,7 +11,7 @@
18733 * and shift, for example.
18734 */
18735 struct word_at_a_time {
18736- const unsigned long one_bits, high_bits;
18737+ unsigned long one_bits, high_bits;
18738 };
18739
18740 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
18741diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
18742index 828a156..650e625 100644
18743--- a/arch/x86/include/asm/x86_init.h
18744+++ b/arch/x86/include/asm/x86_init.h
18745@@ -129,7 +129,7 @@ struct x86_init_ops {
18746 struct x86_init_timers timers;
18747 struct x86_init_iommu iommu;
18748 struct x86_init_pci pci;
18749-};
18750+} __no_const;
18751
18752 /**
18753 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
18754@@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
18755 void (*setup_percpu_clockev)(void);
18756 void (*early_percpu_clock_init)(void);
18757 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
18758-};
18759+} __no_const;
18760
18761 struct timespec;
18762
18763@@ -168,7 +168,7 @@ struct x86_platform_ops {
18764 void (*save_sched_clock_state)(void);
18765 void (*restore_sched_clock_state)(void);
18766 void (*apic_post_init)(void);
18767-};
18768+} __no_const;
18769
18770 struct pci_dev;
18771 struct msi_msg;
18772@@ -182,7 +182,7 @@ struct x86_msi_ops {
18773 void (*teardown_msi_irqs)(struct pci_dev *dev);
18774 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
18775 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
18776-};
18777+} __no_const;
18778
18779 struct IO_APIC_route_entry;
18780 struct io_apic_irq_attr;
18781@@ -203,7 +203,7 @@ struct x86_io_apic_ops {
18782 unsigned int destination, int vector,
18783 struct io_apic_irq_attr *attr);
18784 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
18785-};
18786+} __no_const;
18787
18788 extern struct x86_init_ops x86_init;
18789 extern struct x86_cpuinit_ops x86_cpuinit;
18790diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
18791index 0415cda..3b22adc 100644
18792--- a/arch/x86/include/asm/xsave.h
18793+++ b/arch/x86/include/asm/xsave.h
18794@@ -70,8 +70,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
18795 if (unlikely(err))
18796 return -EFAULT;
18797
18798+ pax_open_userland();
18799 __asm__ __volatile__(ASM_STAC "\n"
18800- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
18801+ "1:"
18802+ __copyuser_seg
18803+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
18804 "2: " ASM_CLAC "\n"
18805 ".section .fixup,\"ax\"\n"
18806 "3: movl $-1,%[err]\n"
18807@@ -81,18 +84,22 @@ static inline int xsave_user(struct xsave_struct __user *buf)
18808 : [err] "=r" (err)
18809 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
18810 : "memory");
18811+ pax_close_userland();
18812 return err;
18813 }
18814
18815 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
18816 {
18817 int err;
18818- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
18819+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
18820 u32 lmask = mask;
18821 u32 hmask = mask >> 32;
18822
18823+ pax_open_userland();
18824 __asm__ __volatile__(ASM_STAC "\n"
18825- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
18826+ "1:"
18827+ __copyuser_seg
18828+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
18829 "2: " ASM_CLAC "\n"
18830 ".section .fixup,\"ax\"\n"
18831 "3: movl $-1,%[err]\n"
18832@@ -102,6 +109,7 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
18833 : [err] "=r" (err)
18834 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
18835 : "memory"); /* memory required? */
18836+ pax_close_userland();
18837 return err;
18838 }
18839
18840diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
18841index bbae024..e1528f9 100644
18842--- a/arch/x86/include/uapi/asm/e820.h
18843+++ b/arch/x86/include/uapi/asm/e820.h
18844@@ -63,7 +63,7 @@ struct e820map {
18845 #define ISA_START_ADDRESS 0xa0000
18846 #define ISA_END_ADDRESS 0x100000
18847
18848-#define BIOS_BEGIN 0x000a0000
18849+#define BIOS_BEGIN 0x000c0000
18850 #define BIOS_END 0x00100000
18851
18852 #define BIOS_ROM_BASE 0xffe00000
18853diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
18854index 88d99ea..9fc7e17 100644
18855--- a/arch/x86/kernel/Makefile
18856+++ b/arch/x86/kernel/Makefile
18857@@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
18858 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
18859 obj-$(CONFIG_IRQ_WORK) += irq_work.o
18860 obj-y += probe_roms.o
18861-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
18862+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
18863 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
18864 obj-y += syscall_$(BITS).o
18865 obj-$(CONFIG_X86_64) += vsyscall_64.o
18866diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
18867index 2627a81..cd8325e 100644
18868--- a/arch/x86/kernel/acpi/boot.c
18869+++ b/arch/x86/kernel/acpi/boot.c
18870@@ -1368,7 +1368,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
18871 * If your system is blacklisted here, but you find that acpi=force
18872 * works for you, please contact linux-acpi@vger.kernel.org
18873 */
18874-static struct dmi_system_id __initdata acpi_dmi_table[] = {
18875+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
18876 /*
18877 * Boxes that need ACPI disabled
18878 */
18879@@ -1443,7 +1443,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
18880 };
18881
18882 /* second table for DMI checks that should run after early-quirks */
18883-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
18884+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
18885 /*
18886 * HP laptops which use a DSDT reporting as HP/SB400/10000,
18887 * which includes some code which overrides all temperature
18888diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
18889index 3312010..a65ca7b 100644
18890--- a/arch/x86/kernel/acpi/sleep.c
18891+++ b/arch/x86/kernel/acpi/sleep.c
18892@@ -88,8 +88,12 @@ int x86_acpi_suspend_lowlevel(void)
18893 #else /* CONFIG_64BIT */
18894 #ifdef CONFIG_SMP
18895 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
18896+
18897+ pax_open_kernel();
18898 early_gdt_descr.address =
18899 (unsigned long)get_cpu_gdt_table(smp_processor_id());
18900+ pax_close_kernel();
18901+
18902 initial_gs = per_cpu_offset(smp_processor_id());
18903 #endif
18904 initial_code = (unsigned long)wakeup_long64;
18905diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
18906index d1daa66..59fecba 100644
18907--- a/arch/x86/kernel/acpi/wakeup_32.S
18908+++ b/arch/x86/kernel/acpi/wakeup_32.S
18909@@ -29,13 +29,11 @@ wakeup_pmode_return:
18910 # and restore the stack ... but you need gdt for this to work
18911 movl saved_context_esp, %esp
18912
18913- movl %cs:saved_magic, %eax
18914- cmpl $0x12345678, %eax
18915+ cmpl $0x12345678, saved_magic
18916 jne bogus_magic
18917
18918 # jump to place where we left off
18919- movl saved_eip, %eax
18920- jmp *%eax
18921+ jmp *(saved_eip)
18922
18923 bogus_magic:
18924 jmp bogus_magic
18925diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
18926index c15cf9a..0e63558 100644
18927--- a/arch/x86/kernel/alternative.c
18928+++ b/arch/x86/kernel/alternative.c
18929@@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
18930 */
18931 for (a = start; a < end; a++) {
18932 instr = (u8 *)&a->instr_offset + a->instr_offset;
18933+
18934+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18935+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18936+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
18937+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18938+#endif
18939+
18940 replacement = (u8 *)&a->repl_offset + a->repl_offset;
18941 BUG_ON(a->replacementlen > a->instrlen);
18942 BUG_ON(a->instrlen > sizeof(insnbuf));
18943@@ -299,10 +306,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
18944 for (poff = start; poff < end; poff++) {
18945 u8 *ptr = (u8 *)poff + *poff;
18946
18947+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18948+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18949+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
18950+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18951+#endif
18952+
18953 if (!*poff || ptr < text || ptr >= text_end)
18954 continue;
18955 /* turn DS segment override prefix into lock prefix */
18956- if (*ptr == 0x3e)
18957+ if (*ktla_ktva(ptr) == 0x3e)
18958 text_poke(ptr, ((unsigned char []){0xf0}), 1);
18959 }
18960 mutex_unlock(&text_mutex);
18961@@ -317,10 +330,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
18962 for (poff = start; poff < end; poff++) {
18963 u8 *ptr = (u8 *)poff + *poff;
18964
18965+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18966+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18967+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
18968+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
18969+#endif
18970+
18971 if (!*poff || ptr < text || ptr >= text_end)
18972 continue;
18973 /* turn lock prefix into DS segment override prefix */
18974- if (*ptr == 0xf0)
18975+ if (*ktla_ktva(ptr) == 0xf0)
18976 text_poke(ptr, ((unsigned char []){0x3E}), 1);
18977 }
18978 mutex_unlock(&text_mutex);
18979@@ -468,7 +487,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
18980
18981 BUG_ON(p->len > MAX_PATCH_LEN);
18982 /* prep the buffer with the original instructions */
18983- memcpy(insnbuf, p->instr, p->len);
18984+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
18985 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
18986 (unsigned long)p->instr, p->len);
18987
18988@@ -515,7 +534,7 @@ void __init alternative_instructions(void)
18989 if (!uniproc_patched || num_possible_cpus() == 1)
18990 free_init_pages("SMP alternatives",
18991 (unsigned long)__smp_locks,
18992- (unsigned long)__smp_locks_end);
18993+ PAGE_ALIGN((unsigned long)__smp_locks_end));
18994 #endif
18995
18996 apply_paravirt(__parainstructions, __parainstructions_end);
18997@@ -535,13 +554,17 @@ void __init alternative_instructions(void)
18998 * instructions. And on the local CPU you need to be protected again NMI or MCE
18999 * handlers seeing an inconsistent instruction while you patch.
19000 */
19001-void *__init_or_module text_poke_early(void *addr, const void *opcode,
19002+void *__kprobes text_poke_early(void *addr, const void *opcode,
19003 size_t len)
19004 {
19005 unsigned long flags;
19006 local_irq_save(flags);
19007- memcpy(addr, opcode, len);
19008+
19009+ pax_open_kernel();
19010+ memcpy(ktla_ktva(addr), opcode, len);
19011 sync_core();
19012+ pax_close_kernel();
19013+
19014 local_irq_restore(flags);
19015 /* Could also do a CLFLUSH here to speed up CPU recovery; but
19016 that causes hangs on some VIA CPUs. */
19017@@ -563,36 +586,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
19018 */
19019 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
19020 {
19021- unsigned long flags;
19022- char *vaddr;
19023+ unsigned char *vaddr = ktla_ktva(addr);
19024 struct page *pages[2];
19025- int i;
19026+ size_t i;
19027
19028 if (!core_kernel_text((unsigned long)addr)) {
19029- pages[0] = vmalloc_to_page(addr);
19030- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
19031+ pages[0] = vmalloc_to_page(vaddr);
19032+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
19033 } else {
19034- pages[0] = virt_to_page(addr);
19035+ pages[0] = virt_to_page(vaddr);
19036 WARN_ON(!PageReserved(pages[0]));
19037- pages[1] = virt_to_page(addr + PAGE_SIZE);
19038+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
19039 }
19040 BUG_ON(!pages[0]);
19041- local_irq_save(flags);
19042- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
19043- if (pages[1])
19044- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
19045- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
19046- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
19047- clear_fixmap(FIX_TEXT_POKE0);
19048- if (pages[1])
19049- clear_fixmap(FIX_TEXT_POKE1);
19050- local_flush_tlb();
19051- sync_core();
19052- /* Could also do a CLFLUSH here to speed up CPU recovery; but
19053- that causes hangs on some VIA CPUs. */
19054+ text_poke_early(addr, opcode, len);
19055 for (i = 0; i < len; i++)
19056- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
19057- local_irq_restore(flags);
19058+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
19059 return addr;
19060 }
19061
19062diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
19063index eca89c5..d566b78 100644
19064--- a/arch/x86/kernel/apic/apic.c
19065+++ b/arch/x86/kernel/apic/apic.c
19066@@ -190,7 +190,7 @@ int first_system_vector = 0xfe;
19067 /*
19068 * Debug level, exported for io_apic.c
19069 */
19070-unsigned int apic_verbosity;
19071+int apic_verbosity;
19072
19073 int pic_mode;
19074
19075@@ -1985,7 +1985,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
19076 apic_write(APIC_ESR, 0);
19077 v1 = apic_read(APIC_ESR);
19078 ack_APIC_irq();
19079- atomic_inc(&irq_err_count);
19080+ atomic_inc_unchecked(&irq_err_count);
19081
19082 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
19083 smp_processor_id(), v0 , v1);
19084diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
19085index 00c77cf..2dc6a2d 100644
19086--- a/arch/x86/kernel/apic/apic_flat_64.c
19087+++ b/arch/x86/kernel/apic/apic_flat_64.c
19088@@ -157,7 +157,7 @@ static int flat_probe(void)
19089 return 1;
19090 }
19091
19092-static struct apic apic_flat = {
19093+static struct apic apic_flat __read_only = {
19094 .name = "flat",
19095 .probe = flat_probe,
19096 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
19097@@ -271,7 +271,7 @@ static int physflat_probe(void)
19098 return 0;
19099 }
19100
19101-static struct apic apic_physflat = {
19102+static struct apic apic_physflat __read_only = {
19103
19104 .name = "physical flat",
19105 .probe = physflat_probe,
19106diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
19107index e145f28..2752888 100644
19108--- a/arch/x86/kernel/apic/apic_noop.c
19109+++ b/arch/x86/kernel/apic/apic_noop.c
19110@@ -119,7 +119,7 @@ static void noop_apic_write(u32 reg, u32 v)
19111 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
19112 }
19113
19114-struct apic apic_noop = {
19115+struct apic apic_noop __read_only = {
19116 .name = "noop",
19117 .probe = noop_probe,
19118 .acpi_madt_oem_check = NULL,
19119diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
19120index d50e364..543bee3 100644
19121--- a/arch/x86/kernel/apic/bigsmp_32.c
19122+++ b/arch/x86/kernel/apic/bigsmp_32.c
19123@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
19124 return dmi_bigsmp;
19125 }
19126
19127-static struct apic apic_bigsmp = {
19128+static struct apic apic_bigsmp __read_only = {
19129
19130 .name = "bigsmp",
19131 .probe = probe_bigsmp,
19132diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
19133index c552247..587a316 100644
19134--- a/arch/x86/kernel/apic/es7000_32.c
19135+++ b/arch/x86/kernel/apic/es7000_32.c
19136@@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
19137 return ret && es7000_apic_is_cluster();
19138 }
19139
19140-/* We've been warned by a false positive warning.Use __refdata to keep calm. */
19141-static struct apic __refdata apic_es7000_cluster = {
19142+static struct apic apic_es7000_cluster __read_only = {
19143
19144 .name = "es7000",
19145 .probe = probe_es7000,
19146@@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
19147 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
19148 };
19149
19150-static struct apic __refdata apic_es7000 = {
19151+static struct apic apic_es7000 __read_only = {
19152
19153 .name = "es7000",
19154 .probe = probe_es7000,
19155diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
19156index 9ed796c..e930fe4 100644
19157--- a/arch/x86/kernel/apic/io_apic.c
19158+++ b/arch/x86/kernel/apic/io_apic.c
19159@@ -1060,7 +1060,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
19160 }
19161 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
19162
19163-void lock_vector_lock(void)
19164+void lock_vector_lock(void) __acquires(vector_lock)
19165 {
19166 /* Used to the online set of cpus does not change
19167 * during assign_irq_vector.
19168@@ -1068,7 +1068,7 @@ void lock_vector_lock(void)
19169 raw_spin_lock(&vector_lock);
19170 }
19171
19172-void unlock_vector_lock(void)
19173+void unlock_vector_lock(void) __releases(vector_lock)
19174 {
19175 raw_spin_unlock(&vector_lock);
19176 }
19177@@ -2362,7 +2362,7 @@ static void ack_apic_edge(struct irq_data *data)
19178 ack_APIC_irq();
19179 }
19180
19181-atomic_t irq_mis_count;
19182+atomic_unchecked_t irq_mis_count;
19183
19184 #ifdef CONFIG_GENERIC_PENDING_IRQ
19185 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
19186@@ -2503,7 +2503,7 @@ static void ack_apic_level(struct irq_data *data)
19187 * at the cpu.
19188 */
19189 if (!(v & (1 << (i & 0x1f)))) {
19190- atomic_inc(&irq_mis_count);
19191+ atomic_inc_unchecked(&irq_mis_count);
19192
19193 eoi_ioapic_irq(irq, cfg);
19194 }
19195diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
19196index 1e42e8f..daacf44 100644
19197--- a/arch/x86/kernel/apic/numaq_32.c
19198+++ b/arch/x86/kernel/apic/numaq_32.c
19199@@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
19200 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
19201 }
19202
19203-/* Use __refdata to keep false positive warning calm. */
19204-static struct apic __refdata apic_numaq = {
19205+static struct apic apic_numaq __read_only = {
19206
19207 .name = "NUMAQ",
19208 .probe = probe_numaq,
19209diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
19210index eb35ef9..f184a21 100644
19211--- a/arch/x86/kernel/apic/probe_32.c
19212+++ b/arch/x86/kernel/apic/probe_32.c
19213@@ -72,7 +72,7 @@ static int probe_default(void)
19214 return 1;
19215 }
19216
19217-static struct apic apic_default = {
19218+static struct apic apic_default __read_only = {
19219
19220 .name = "default",
19221 .probe = probe_default,
19222diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
19223index 77c95c0..434f8a4 100644
19224--- a/arch/x86/kernel/apic/summit_32.c
19225+++ b/arch/x86/kernel/apic/summit_32.c
19226@@ -486,7 +486,7 @@ void setup_summit(void)
19227 }
19228 #endif
19229
19230-static struct apic apic_summit = {
19231+static struct apic apic_summit __read_only = {
19232
19233 .name = "summit",
19234 .probe = probe_summit,
19235diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
19236index 140e29d..d88bc95 100644
19237--- a/arch/x86/kernel/apic/x2apic_cluster.c
19238+++ b/arch/x86/kernel/apic/x2apic_cluster.c
19239@@ -183,7 +183,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
19240 return notifier_from_errno(err);
19241 }
19242
19243-static struct notifier_block __refdata x2apic_cpu_notifier = {
19244+static struct notifier_block x2apic_cpu_notifier = {
19245 .notifier_call = update_clusterinfo,
19246 };
19247
19248@@ -235,7 +235,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
19249 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
19250 }
19251
19252-static struct apic apic_x2apic_cluster = {
19253+static struct apic apic_x2apic_cluster __read_only = {
19254
19255 .name = "cluster x2apic",
19256 .probe = x2apic_cluster_probe,
19257diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
19258index 562a76d..a003c0f 100644
19259--- a/arch/x86/kernel/apic/x2apic_phys.c
19260+++ b/arch/x86/kernel/apic/x2apic_phys.c
19261@@ -89,7 +89,7 @@ static int x2apic_phys_probe(void)
19262 return apic == &apic_x2apic_phys;
19263 }
19264
19265-static struct apic apic_x2apic_phys = {
19266+static struct apic apic_x2apic_phys __read_only = {
19267
19268 .name = "physical x2apic",
19269 .probe = x2apic_phys_probe,
19270diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
19271index 1191ac1..2335fa4 100644
19272--- a/arch/x86/kernel/apic/x2apic_uv_x.c
19273+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
19274@@ -357,7 +357,7 @@ static int uv_probe(void)
19275 return apic == &apic_x2apic_uv_x;
19276 }
19277
19278-static struct apic __refdata apic_x2apic_uv_x = {
19279+static struct apic apic_x2apic_uv_x __read_only = {
19280
19281 .name = "UV large system",
19282 .probe = uv_probe,
19283diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
19284index 53a4e27..038760a 100644
19285--- a/arch/x86/kernel/apm_32.c
19286+++ b/arch/x86/kernel/apm_32.c
19287@@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
19288 * This is for buggy BIOS's that refer to (real mode) segment 0x40
19289 * even though they are called in protected mode.
19290 */
19291-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
19292+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
19293 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
19294
19295 static const char driver_version[] = "1.16ac"; /* no spaces */
19296@@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
19297 BUG_ON(cpu != 0);
19298 gdt = get_cpu_gdt_table(cpu);
19299 save_desc_40 = gdt[0x40 / 8];
19300+
19301+ pax_open_kernel();
19302 gdt[0x40 / 8] = bad_bios_desc;
19303+ pax_close_kernel();
19304
19305 apm_irq_save(flags);
19306 APM_DO_SAVE_SEGS;
19307@@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
19308 &call->esi);
19309 APM_DO_RESTORE_SEGS;
19310 apm_irq_restore(flags);
19311+
19312+ pax_open_kernel();
19313 gdt[0x40 / 8] = save_desc_40;
19314+ pax_close_kernel();
19315+
19316 put_cpu();
19317
19318 return call->eax & 0xff;
19319@@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
19320 BUG_ON(cpu != 0);
19321 gdt = get_cpu_gdt_table(cpu);
19322 save_desc_40 = gdt[0x40 / 8];
19323+
19324+ pax_open_kernel();
19325 gdt[0x40 / 8] = bad_bios_desc;
19326+ pax_close_kernel();
19327
19328 apm_irq_save(flags);
19329 APM_DO_SAVE_SEGS;
19330@@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
19331 &call->eax);
19332 APM_DO_RESTORE_SEGS;
19333 apm_irq_restore(flags);
19334+
19335+ pax_open_kernel();
19336 gdt[0x40 / 8] = save_desc_40;
19337+ pax_close_kernel();
19338+
19339 put_cpu();
19340 return error;
19341 }
19342@@ -2362,12 +2376,15 @@ static int __init apm_init(void)
19343 * code to that CPU.
19344 */
19345 gdt = get_cpu_gdt_table(0);
19346+
19347+ pax_open_kernel();
19348 set_desc_base(&gdt[APM_CS >> 3],
19349 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
19350 set_desc_base(&gdt[APM_CS_16 >> 3],
19351 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
19352 set_desc_base(&gdt[APM_DS >> 3],
19353 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
19354+ pax_close_kernel();
19355
19356 proc_create("apm", 0, NULL, &apm_file_ops);
19357
19358diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
19359index 2861082..6d4718e 100644
19360--- a/arch/x86/kernel/asm-offsets.c
19361+++ b/arch/x86/kernel/asm-offsets.c
19362@@ -33,6 +33,8 @@ void common(void) {
19363 OFFSET(TI_status, thread_info, status);
19364 OFFSET(TI_addr_limit, thread_info, addr_limit);
19365 OFFSET(TI_preempt_count, thread_info, preempt_count);
19366+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
19367+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
19368
19369 BLANK();
19370 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
19371@@ -53,8 +55,26 @@ void common(void) {
19372 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
19373 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
19374 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
19375+
19376+#ifdef CONFIG_PAX_KERNEXEC
19377+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
19378 #endif
19379
19380+#ifdef CONFIG_PAX_MEMORY_UDEREF
19381+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
19382+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
19383+#ifdef CONFIG_X86_64
19384+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
19385+#endif
19386+#endif
19387+
19388+#endif
19389+
19390+ BLANK();
19391+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
19392+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
19393+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
19394+
19395 #ifdef CONFIG_XEN
19396 BLANK();
19397 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
19398diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
19399index e7c798b..2b2019b 100644
19400--- a/arch/x86/kernel/asm-offsets_64.c
19401+++ b/arch/x86/kernel/asm-offsets_64.c
19402@@ -77,6 +77,7 @@ int main(void)
19403 BLANK();
19404 #undef ENTRY
19405
19406+ DEFINE(TSS_size, sizeof(struct tss_struct));
19407 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
19408 BLANK();
19409
19410diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
19411index 47b56a7..efc2bc6 100644
19412--- a/arch/x86/kernel/cpu/Makefile
19413+++ b/arch/x86/kernel/cpu/Makefile
19414@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
19415 CFLAGS_REMOVE_perf_event.o = -pg
19416 endif
19417
19418-# Make sure load_percpu_segment has no stackprotector
19419-nostackp := $(call cc-option, -fno-stack-protector)
19420-CFLAGS_common.o := $(nostackp)
19421-
19422 obj-y := intel_cacheinfo.o scattered.o topology.o
19423 obj-y += proc.o capflags.o powerflags.o common.o
19424 obj-y += rdrand.o
19425diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
19426index 08a0890..e557865 100644
19427--- a/arch/x86/kernel/cpu/amd.c
19428+++ b/arch/x86/kernel/cpu/amd.c
19429@@ -743,7 +743,7 @@ static void init_amd(struct cpuinfo_x86 *c)
19430 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
19431 {
19432 /* AMD errata T13 (order #21922) */
19433- if ((c->x86 == 6)) {
19434+ if (c->x86 == 6) {
19435 /* Duron Rev A0 */
19436 if (c->x86_model == 3 && c->x86_mask == 0)
19437 size = 64;
19438diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
19439index 25eb274..3a92d93 100644
19440--- a/arch/x86/kernel/cpu/common.c
19441+++ b/arch/x86/kernel/cpu/common.c
19442@@ -88,60 +88,6 @@ static const struct cpu_dev default_cpu = {
19443
19444 static const struct cpu_dev *this_cpu = &default_cpu;
19445
19446-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
19447-#ifdef CONFIG_X86_64
19448- /*
19449- * We need valid kernel segments for data and code in long mode too
19450- * IRET will check the segment types kkeil 2000/10/28
19451- * Also sysret mandates a special GDT layout
19452- *
19453- * TLS descriptors are currently at a different place compared to i386.
19454- * Hopefully nobody expects them at a fixed place (Wine?)
19455- */
19456- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
19457- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
19458- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
19459- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
19460- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
19461- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
19462-#else
19463- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
19464- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
19465- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
19466- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
19467- /*
19468- * Segments used for calling PnP BIOS have byte granularity.
19469- * They code segments and data segments have fixed 64k limits,
19470- * the transfer segment sizes are set at run time.
19471- */
19472- /* 32-bit code */
19473- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
19474- /* 16-bit code */
19475- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
19476- /* 16-bit data */
19477- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
19478- /* 16-bit data */
19479- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
19480- /* 16-bit data */
19481- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
19482- /*
19483- * The APM segments have byte granularity and their bases
19484- * are set at run time. All have 64k limits.
19485- */
19486- /* 32-bit code */
19487- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
19488- /* 16-bit code */
19489- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
19490- /* data */
19491- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
19492-
19493- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
19494- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
19495- GDT_STACK_CANARY_INIT
19496-#endif
19497-} };
19498-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
19499-
19500 static int __init x86_xsave_setup(char *s)
19501 {
19502 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
19503@@ -288,6 +234,57 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
19504 set_in_cr4(X86_CR4_SMAP);
19505 }
19506
19507+#ifdef CONFIG_X86_64
19508+static __init int setup_disable_pcid(char *arg)
19509+{
19510+ setup_clear_cpu_cap(X86_FEATURE_PCID);
19511+
19512+#ifdef CONFIG_PAX_MEMORY_UDEREF
19513+ if (clone_pgd_mask != ~(pgdval_t)0UL)
19514+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
19515+#endif
19516+
19517+ return 1;
19518+}
19519+__setup("nopcid", setup_disable_pcid);
19520+
19521+static void setup_pcid(struct cpuinfo_x86 *c)
19522+{
19523+ if (!cpu_has(c, X86_FEATURE_PCID)) {
19524+
19525+#ifdef CONFIG_PAX_MEMORY_UDEREF
19526+ if (clone_pgd_mask != ~(pgdval_t)0UL) {
19527+ pax_open_kernel();
19528+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
19529+ pax_close_kernel();
19530+ printk("PAX: slow and weak UDEREF enabled\n");
19531+ } else
19532+ printk("PAX: UDEREF disabled\n");
19533+#endif
19534+
19535+ return;
19536+ }
19537+
19538+ printk("PAX: PCID detected\n");
19539+ set_in_cr4(X86_CR4_PCIDE);
19540+
19541+#ifdef CONFIG_PAX_MEMORY_UDEREF
19542+ pax_open_kernel();
19543+ clone_pgd_mask = ~(pgdval_t)0UL;
19544+ pax_close_kernel();
19545+ if (pax_user_shadow_base)
19546+ printk("PAX: weak UDEREF enabled\n");
19547+ else {
19548+ set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
19549+ printk("PAX: strong UDEREF enabled\n");
19550+ }
19551+#endif
19552+
19553+ if (cpu_has(c, X86_FEATURE_INVPCID))
19554+ printk("PAX: INVPCID detected\n");
19555+}
19556+#endif
19557+
19558 /*
19559 * Some CPU features depend on higher CPUID levels, which may not always
19560 * be available due to CPUID level capping or broken virtualization
19561@@ -386,7 +383,7 @@ void switch_to_new_gdt(int cpu)
19562 {
19563 struct desc_ptr gdt_descr;
19564
19565- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
19566+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19567 gdt_descr.size = GDT_SIZE - 1;
19568 load_gdt(&gdt_descr);
19569 /* Reload the per-cpu base */
19570@@ -875,6 +872,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
19571 setup_smep(c);
19572 setup_smap(c);
19573
19574+#ifdef CONFIG_X86_64
19575+ setup_pcid(c);
19576+#endif
19577+
19578 /*
19579 * The vendor-specific functions might have changed features.
19580 * Now we do "generic changes."
19581@@ -883,6 +884,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
19582 /* Filter out anything that depends on CPUID levels we don't have */
19583 filter_cpuid_features(c, true);
19584
19585+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
19586+ setup_clear_cpu_cap(X86_FEATURE_SEP);
19587+#endif
19588+
19589 /* If the model name is still unset, do table lookup. */
19590 if (!c->x86_model_id[0]) {
19591 const char *p;
19592@@ -1070,10 +1075,12 @@ static __init int setup_disablecpuid(char *arg)
19593 }
19594 __setup("clearcpuid=", setup_disablecpuid);
19595
19596+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
19597+EXPORT_PER_CPU_SYMBOL(current_tinfo);
19598+
19599 #ifdef CONFIG_X86_64
19600-struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
19601-struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
19602- (unsigned long) debug_idt_table };
19603+struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
19604+const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
19605
19606 DEFINE_PER_CPU_FIRST(union irq_stack_union,
19607 irq_stack_union) __aligned(PAGE_SIZE);
19608@@ -1087,7 +1094,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
19609 EXPORT_PER_CPU_SYMBOL(current_task);
19610
19611 DEFINE_PER_CPU(unsigned long, kernel_stack) =
19612- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
19613+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
19614 EXPORT_PER_CPU_SYMBOL(kernel_stack);
19615
19616 DEFINE_PER_CPU(char *, irq_stack_ptr) =
19617@@ -1232,7 +1239,7 @@ void cpu_init(void)
19618 load_ucode_ap();
19619
19620 cpu = stack_smp_processor_id();
19621- t = &per_cpu(init_tss, cpu);
19622+ t = init_tss + cpu;
19623 oist = &per_cpu(orig_ist, cpu);
19624
19625 #ifdef CONFIG_NUMA
19626@@ -1267,7 +1274,6 @@ void cpu_init(void)
19627 wrmsrl(MSR_KERNEL_GS_BASE, 0);
19628 barrier();
19629
19630- x86_configure_nx();
19631 enable_x2apic();
19632
19633 /*
19634@@ -1319,7 +1325,7 @@ void cpu_init(void)
19635 {
19636 int cpu = smp_processor_id();
19637 struct task_struct *curr = current;
19638- struct tss_struct *t = &per_cpu(init_tss, cpu);
19639+ struct tss_struct *t = init_tss + cpu;
19640 struct thread_struct *thread = &curr->thread;
19641
19642 show_ucode_info_early();
19643diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
19644index 1414c90..1159406 100644
19645--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
19646+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
19647@@ -1014,6 +1014,22 @@ static struct attribute *default_attrs[] = {
19648 };
19649
19650 #ifdef CONFIG_AMD_NB
19651+static struct attribute *default_attrs_amd_nb[] = {
19652+ &type.attr,
19653+ &level.attr,
19654+ &coherency_line_size.attr,
19655+ &physical_line_partition.attr,
19656+ &ways_of_associativity.attr,
19657+ &number_of_sets.attr,
19658+ &size.attr,
19659+ &shared_cpu_map.attr,
19660+ &shared_cpu_list.attr,
19661+ NULL,
19662+ NULL,
19663+ NULL,
19664+ NULL
19665+};
19666+
19667 static struct attribute **amd_l3_attrs(void)
19668 {
19669 static struct attribute **attrs;
19670@@ -1024,18 +1040,7 @@ static struct attribute **amd_l3_attrs(void)
19671
19672 n = ARRAY_SIZE(default_attrs);
19673
19674- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
19675- n += 2;
19676-
19677- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
19678- n += 1;
19679-
19680- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
19681- if (attrs == NULL)
19682- return attrs = default_attrs;
19683-
19684- for (n = 0; default_attrs[n]; n++)
19685- attrs[n] = default_attrs[n];
19686+ attrs = default_attrs_amd_nb;
19687
19688 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
19689 attrs[n++] = &cache_disable_0.attr;
19690@@ -1086,6 +1091,13 @@ static struct kobj_type ktype_cache = {
19691 .default_attrs = default_attrs,
19692 };
19693
19694+#ifdef CONFIG_AMD_NB
19695+static struct kobj_type ktype_cache_amd_nb = {
19696+ .sysfs_ops = &sysfs_ops,
19697+ .default_attrs = default_attrs_amd_nb,
19698+};
19699+#endif
19700+
19701 static struct kobj_type ktype_percpu_entry = {
19702 .sysfs_ops = &sysfs_ops,
19703 };
19704@@ -1151,20 +1163,26 @@ static int cache_add_dev(struct device *dev)
19705 return retval;
19706 }
19707
19708+#ifdef CONFIG_AMD_NB
19709+ amd_l3_attrs();
19710+#endif
19711+
19712 for (i = 0; i < num_cache_leaves; i++) {
19713+ struct kobj_type *ktype;
19714+
19715 this_object = INDEX_KOBJECT_PTR(cpu, i);
19716 this_object->cpu = cpu;
19717 this_object->index = i;
19718
19719 this_leaf = CPUID4_INFO_IDX(cpu, i);
19720
19721- ktype_cache.default_attrs = default_attrs;
19722+ ktype = &ktype_cache;
19723 #ifdef CONFIG_AMD_NB
19724 if (this_leaf->base.nb)
19725- ktype_cache.default_attrs = amd_l3_attrs();
19726+ ktype = &ktype_cache_amd_nb;
19727 #endif
19728 retval = kobject_init_and_add(&(this_object->kobj),
19729- &ktype_cache,
19730+ ktype,
19731 per_cpu(ici_cache_kobject, cpu),
19732 "index%1lu", i);
19733 if (unlikely(retval)) {
19734diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
19735index 87a65c9..92fcce6 100644
19736--- a/arch/x86/kernel/cpu/mcheck/mce.c
19737+++ b/arch/x86/kernel/cpu/mcheck/mce.c
19738@@ -45,6 +45,7 @@
19739 #include <asm/processor.h>
19740 #include <asm/mce.h>
19741 #include <asm/msr.h>
19742+#include <asm/local.h>
19743
19744 #include "mce-internal.h"
19745
19746@@ -249,7 +250,7 @@ static void print_mce(struct mce *m)
19747 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
19748 m->cs, m->ip);
19749
19750- if (m->cs == __KERNEL_CS)
19751+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
19752 print_symbol("{%s}", m->ip);
19753 pr_cont("\n");
19754 }
19755@@ -282,10 +283,10 @@ static void print_mce(struct mce *m)
19756
19757 #define PANIC_TIMEOUT 5 /* 5 seconds */
19758
19759-static atomic_t mce_paniced;
19760+static atomic_unchecked_t mce_paniced;
19761
19762 static int fake_panic;
19763-static atomic_t mce_fake_paniced;
19764+static atomic_unchecked_t mce_fake_paniced;
19765
19766 /* Panic in progress. Enable interrupts and wait for final IPI */
19767 static void wait_for_panic(void)
19768@@ -309,7 +310,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
19769 /*
19770 * Make sure only one CPU runs in machine check panic
19771 */
19772- if (atomic_inc_return(&mce_paniced) > 1)
19773+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
19774 wait_for_panic();
19775 barrier();
19776
19777@@ -317,7 +318,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
19778 console_verbose();
19779 } else {
19780 /* Don't log too much for fake panic */
19781- if (atomic_inc_return(&mce_fake_paniced) > 1)
19782+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
19783 return;
19784 }
19785 /* First print corrected ones that are still unlogged */
19786@@ -356,7 +357,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
19787 if (!fake_panic) {
19788 if (panic_timeout == 0)
19789 panic_timeout = mca_cfg.panic_timeout;
19790- panic(msg);
19791+ panic("%s", msg);
19792 } else
19793 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
19794 }
19795@@ -686,7 +687,7 @@ static int mce_timed_out(u64 *t)
19796 * might have been modified by someone else.
19797 */
19798 rmb();
19799- if (atomic_read(&mce_paniced))
19800+ if (atomic_read_unchecked(&mce_paniced))
19801 wait_for_panic();
19802 if (!mca_cfg.monarch_timeout)
19803 goto out;
19804@@ -1657,7 +1658,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
19805 }
19806
19807 /* Call the installed machine check handler for this CPU setup. */
19808-void (*machine_check_vector)(struct pt_regs *, long error_code) =
19809+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
19810 unexpected_machine_check;
19811
19812 /*
19813@@ -1680,7 +1681,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
19814 return;
19815 }
19816
19817+ pax_open_kernel();
19818 machine_check_vector = do_machine_check;
19819+ pax_close_kernel();
19820
19821 __mcheck_cpu_init_generic();
19822 __mcheck_cpu_init_vendor(c);
19823@@ -1694,7 +1697,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
19824 */
19825
19826 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
19827-static int mce_chrdev_open_count; /* #times opened */
19828+static local_t mce_chrdev_open_count; /* #times opened */
19829 static int mce_chrdev_open_exclu; /* already open exclusive? */
19830
19831 static int mce_chrdev_open(struct inode *inode, struct file *file)
19832@@ -1702,7 +1705,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
19833 spin_lock(&mce_chrdev_state_lock);
19834
19835 if (mce_chrdev_open_exclu ||
19836- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
19837+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
19838 spin_unlock(&mce_chrdev_state_lock);
19839
19840 return -EBUSY;
19841@@ -1710,7 +1713,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
19842
19843 if (file->f_flags & O_EXCL)
19844 mce_chrdev_open_exclu = 1;
19845- mce_chrdev_open_count++;
19846+ local_inc(&mce_chrdev_open_count);
19847
19848 spin_unlock(&mce_chrdev_state_lock);
19849
19850@@ -1721,7 +1724,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
19851 {
19852 spin_lock(&mce_chrdev_state_lock);
19853
19854- mce_chrdev_open_count--;
19855+ local_dec(&mce_chrdev_open_count);
19856 mce_chrdev_open_exclu = 0;
19857
19858 spin_unlock(&mce_chrdev_state_lock);
19859@@ -2376,7 +2379,7 @@ static __init void mce_init_banks(void)
19860
19861 for (i = 0; i < mca_cfg.banks; i++) {
19862 struct mce_bank *b = &mce_banks[i];
19863- struct device_attribute *a = &b->attr;
19864+ device_attribute_no_const *a = &b->attr;
19865
19866 sysfs_attr_init(&a->attr);
19867 a->attr.name = b->attrname;
19868@@ -2444,7 +2447,7 @@ struct dentry *mce_get_debugfs_dir(void)
19869 static void mce_reset(void)
19870 {
19871 cpu_missing = 0;
19872- atomic_set(&mce_fake_paniced, 0);
19873+ atomic_set_unchecked(&mce_fake_paniced, 0);
19874 atomic_set(&mce_executing, 0);
19875 atomic_set(&mce_callin, 0);
19876 atomic_set(&global_nwo, 0);
19877diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
19878index 1c044b1..37a2a43 100644
19879--- a/arch/x86/kernel/cpu/mcheck/p5.c
19880+++ b/arch/x86/kernel/cpu/mcheck/p5.c
19881@@ -11,6 +11,7 @@
19882 #include <asm/processor.h>
19883 #include <asm/mce.h>
19884 #include <asm/msr.h>
19885+#include <asm/pgtable.h>
19886
19887 /* By default disabled */
19888 int mce_p5_enabled __read_mostly;
19889@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
19890 if (!cpu_has(c, X86_FEATURE_MCE))
19891 return;
19892
19893+ pax_open_kernel();
19894 machine_check_vector = pentium_machine_check;
19895+ pax_close_kernel();
19896 /* Make sure the vector pointer is visible before we enable MCEs: */
19897 wmb();
19898
19899diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
19900index e9a701a..35317d6 100644
19901--- a/arch/x86/kernel/cpu/mcheck/winchip.c
19902+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
19903@@ -10,6 +10,7 @@
19904 #include <asm/processor.h>
19905 #include <asm/mce.h>
19906 #include <asm/msr.h>
19907+#include <asm/pgtable.h>
19908
19909 /* Machine check handler for WinChip C6: */
19910 static void winchip_machine_check(struct pt_regs *regs, long error_code)
19911@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
19912 {
19913 u32 lo, hi;
19914
19915+ pax_open_kernel();
19916 machine_check_vector = winchip_machine_check;
19917+ pax_close_kernel();
19918 /* Make sure the vector pointer is visible before we enable MCEs: */
19919 wmb();
19920
19921diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
19922index f961de9..8a9d332 100644
19923--- a/arch/x86/kernel/cpu/mtrr/main.c
19924+++ b/arch/x86/kernel/cpu/mtrr/main.c
19925@@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
19926 u64 size_or_mask, size_and_mask;
19927 static bool mtrr_aps_delayed_init;
19928
19929-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
19930+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
19931
19932 const struct mtrr_ops *mtrr_if;
19933
19934diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
19935index df5e41f..816c719 100644
19936--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
19937+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
19938@@ -25,7 +25,7 @@ struct mtrr_ops {
19939 int (*validate_add_page)(unsigned long base, unsigned long size,
19940 unsigned int type);
19941 int (*have_wrcomb)(void);
19942-};
19943+} __do_const;
19944
19945 extern int generic_get_free_region(unsigned long base, unsigned long size,
19946 int replace_reg);
19947diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
19948index a7c7305..b9705ab 100644
19949--- a/arch/x86/kernel/cpu/perf_event.c
19950+++ b/arch/x86/kernel/cpu/perf_event.c
19951@@ -1348,7 +1348,7 @@ static void __init pmu_check_apic(void)
19952 pr_info("no hardware sampling interrupt available.\n");
19953 }
19954
19955-static struct attribute_group x86_pmu_format_group = {
19956+static attribute_group_no_const x86_pmu_format_group = {
19957 .name = "format",
19958 .attrs = NULL,
19959 };
19960@@ -1447,7 +1447,7 @@ static struct attribute *events_attr[] = {
19961 NULL,
19962 };
19963
19964-static struct attribute_group x86_pmu_events_group = {
19965+static attribute_group_no_const x86_pmu_events_group = {
19966 .name = "events",
19967 .attrs = events_attr,
19968 };
19969@@ -1957,7 +1957,7 @@ static unsigned long get_segment_base(unsigned int segment)
19970 if (idx > GDT_ENTRIES)
19971 return 0;
19972
19973- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
19974+ desc = get_cpu_gdt_table(smp_processor_id());
19975 }
19976
19977 return get_desc_base(desc + idx);
19978@@ -2047,7 +2047,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
19979 break;
19980
19981 perf_callchain_store(entry, frame.return_address);
19982- fp = frame.next_frame;
19983+ fp = (const void __force_user *)frame.next_frame;
19984 }
19985 }
19986
19987diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
19988index 639d128..e92d7e5 100644
19989--- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
19990+++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
19991@@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
19992 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
19993 {
19994 struct attribute **attrs;
19995- struct attribute_group *attr_group;
19996+ attribute_group_no_const *attr_group;
19997 int i = 0, j;
19998
19999 while (amd_iommu_v2_event_descs[i].attr.attr.name)
20000diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
20001index a45d8d4..8abd32c 100644
20002--- a/arch/x86/kernel/cpu/perf_event_intel.c
20003+++ b/arch/x86/kernel/cpu/perf_event_intel.c
20004@@ -2099,10 +2099,10 @@ __init int intel_pmu_init(void)
20005 * v2 and above have a perf capabilities MSR
20006 */
20007 if (version > 1) {
20008- u64 capabilities;
20009+ u64 capabilities = x86_pmu.intel_cap.capabilities;
20010
20011- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
20012- x86_pmu.intel_cap.capabilities = capabilities;
20013+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
20014+ x86_pmu.intel_cap.capabilities = capabilities;
20015 }
20016
20017 intel_ds_init();
20018diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20019index 1fb6c72..f5fa2a3 100644
20020--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20021+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20022@@ -3095,7 +3095,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
20023 static int __init uncore_type_init(struct intel_uncore_type *type)
20024 {
20025 struct intel_uncore_pmu *pmus;
20026- struct attribute_group *attr_group;
20027+ attribute_group_no_const *attr_group;
20028 struct attribute **attrs;
20029 int i, j;
20030
20031diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20032index 47b3d00c..2cf1751 100644
20033--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20034+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20035@@ -488,7 +488,7 @@ struct intel_uncore_box {
20036 struct uncore_event_desc {
20037 struct kobj_attribute attr;
20038 const char *config;
20039-};
20040+} __do_const;
20041
20042 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
20043 { \
20044diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
20045index 7d9481c..99c7e4b 100644
20046--- a/arch/x86/kernel/cpuid.c
20047+++ b/arch/x86/kernel/cpuid.c
20048@@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
20049 return notifier_from_errno(err);
20050 }
20051
20052-static struct notifier_block __refdata cpuid_class_cpu_notifier =
20053+static struct notifier_block cpuid_class_cpu_notifier =
20054 {
20055 .notifier_call = cpuid_class_cpu_callback,
20056 };
20057diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
20058index 74467fe..18793d5 100644
20059--- a/arch/x86/kernel/crash.c
20060+++ b/arch/x86/kernel/crash.c
20061@@ -58,10 +58,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
20062 {
20063 #ifdef CONFIG_X86_32
20064 struct pt_regs fixed_regs;
20065-#endif
20066
20067-#ifdef CONFIG_X86_32
20068- if (!user_mode_vm(regs)) {
20069+ if (!user_mode(regs)) {
20070 crash_fixup_ss_esp(&fixed_regs, regs);
20071 regs = &fixed_regs;
20072 }
20073diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
20074index afa64ad..dce67dd 100644
20075--- a/arch/x86/kernel/crash_dump_64.c
20076+++ b/arch/x86/kernel/crash_dump_64.c
20077@@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
20078 return -ENOMEM;
20079
20080 if (userbuf) {
20081- if (copy_to_user(buf, vaddr + offset, csize)) {
20082+ if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
20083 iounmap(vaddr);
20084 return -EFAULT;
20085 }
20086diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
20087index 5d3fe8d..02e1429 100644
20088--- a/arch/x86/kernel/doublefault.c
20089+++ b/arch/x86/kernel/doublefault.c
20090@@ -13,7 +13,7 @@
20091
20092 #define DOUBLEFAULT_STACKSIZE (1024)
20093 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
20094-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
20095+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
20096
20097 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
20098
20099@@ -23,7 +23,7 @@ static void doublefault_fn(void)
20100 unsigned long gdt, tss;
20101
20102 native_store_gdt(&gdt_desc);
20103- gdt = gdt_desc.address;
20104+ gdt = (unsigned long)gdt_desc.address;
20105
20106 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
20107
20108@@ -60,10 +60,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
20109 /* 0x2 bit is always set */
20110 .flags = X86_EFLAGS_SF | 0x2,
20111 .sp = STACK_START,
20112- .es = __USER_DS,
20113+ .es = __KERNEL_DS,
20114 .cs = __KERNEL_CS,
20115 .ss = __KERNEL_DS,
20116- .ds = __USER_DS,
20117+ .ds = __KERNEL_DS,
20118 .fs = __KERNEL_PERCPU,
20119
20120 .__cr3 = __pa_nodebug(swapper_pg_dir),
20121diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
20122index deb6421..76bbc12 100644
20123--- a/arch/x86/kernel/dumpstack.c
20124+++ b/arch/x86/kernel/dumpstack.c
20125@@ -2,6 +2,9 @@
20126 * Copyright (C) 1991, 1992 Linus Torvalds
20127 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
20128 */
20129+#ifdef CONFIG_GRKERNSEC_HIDESYM
20130+#define __INCLUDED_BY_HIDESYM 1
20131+#endif
20132 #include <linux/kallsyms.h>
20133 #include <linux/kprobes.h>
20134 #include <linux/uaccess.h>
20135@@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
20136 static void
20137 print_ftrace_graph_addr(unsigned long addr, void *data,
20138 const struct stacktrace_ops *ops,
20139- struct thread_info *tinfo, int *graph)
20140+ struct task_struct *task, int *graph)
20141 {
20142- struct task_struct *task;
20143 unsigned long ret_addr;
20144 int index;
20145
20146 if (addr != (unsigned long)return_to_handler)
20147 return;
20148
20149- task = tinfo->task;
20150 index = task->curr_ret_stack;
20151
20152 if (!task->ret_stack || index < *graph)
20153@@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
20154 static inline void
20155 print_ftrace_graph_addr(unsigned long addr, void *data,
20156 const struct stacktrace_ops *ops,
20157- struct thread_info *tinfo, int *graph)
20158+ struct task_struct *task, int *graph)
20159 { }
20160 #endif
20161
20162@@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
20163 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
20164 */
20165
20166-static inline int valid_stack_ptr(struct thread_info *tinfo,
20167- void *p, unsigned int size, void *end)
20168+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
20169 {
20170- void *t = tinfo;
20171 if (end) {
20172 if (p < end && p >= (end-THREAD_SIZE))
20173 return 1;
20174@@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
20175 }
20176
20177 unsigned long
20178-print_context_stack(struct thread_info *tinfo,
20179+print_context_stack(struct task_struct *task, void *stack_start,
20180 unsigned long *stack, unsigned long bp,
20181 const struct stacktrace_ops *ops, void *data,
20182 unsigned long *end, int *graph)
20183 {
20184 struct stack_frame *frame = (struct stack_frame *)bp;
20185
20186- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
20187+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
20188 unsigned long addr;
20189
20190 addr = *stack;
20191@@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
20192 } else {
20193 ops->address(data, addr, 0);
20194 }
20195- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
20196+ print_ftrace_graph_addr(addr, data, ops, task, graph);
20197 }
20198 stack++;
20199 }
20200@@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
20201 EXPORT_SYMBOL_GPL(print_context_stack);
20202
20203 unsigned long
20204-print_context_stack_bp(struct thread_info *tinfo,
20205+print_context_stack_bp(struct task_struct *task, void *stack_start,
20206 unsigned long *stack, unsigned long bp,
20207 const struct stacktrace_ops *ops, void *data,
20208 unsigned long *end, int *graph)
20209@@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
20210 struct stack_frame *frame = (struct stack_frame *)bp;
20211 unsigned long *ret_addr = &frame->return_address;
20212
20213- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
20214+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
20215 unsigned long addr = *ret_addr;
20216
20217 if (!__kernel_text_address(addr))
20218@@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
20219 ops->address(data, addr, 1);
20220 frame = frame->next_frame;
20221 ret_addr = &frame->return_address;
20222- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
20223+ print_ftrace_graph_addr(addr, data, ops, task, graph);
20224 }
20225
20226 return (unsigned long)frame;
20227@@ -150,7 +149,7 @@ static int print_trace_stack(void *data, char *name)
20228 static void print_trace_address(void *data, unsigned long addr, int reliable)
20229 {
20230 touch_nmi_watchdog();
20231- printk(data);
20232+ printk("%s", (char *)data);
20233 printk_address(addr, reliable);
20234 }
20235
20236@@ -219,6 +218,8 @@ unsigned __kprobes long oops_begin(void)
20237 }
20238 EXPORT_SYMBOL_GPL(oops_begin);
20239
20240+extern void gr_handle_kernel_exploit(void);
20241+
20242 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
20243 {
20244 if (regs && kexec_should_crash(current))
20245@@ -240,7 +241,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
20246 panic("Fatal exception in interrupt");
20247 if (panic_on_oops)
20248 panic("Fatal exception");
20249- do_exit(signr);
20250+
20251+ gr_handle_kernel_exploit();
20252+
20253+ do_group_exit(signr);
20254 }
20255
20256 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
20257@@ -268,7 +272,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
20258 print_modules();
20259 show_regs(regs);
20260 #ifdef CONFIG_X86_32
20261- if (user_mode_vm(regs)) {
20262+ if (user_mode(regs)) {
20263 sp = regs->sp;
20264 ss = regs->ss & 0xffff;
20265 } else {
20266@@ -296,7 +300,7 @@ void die(const char *str, struct pt_regs *regs, long err)
20267 unsigned long flags = oops_begin();
20268 int sig = SIGSEGV;
20269
20270- if (!user_mode_vm(regs))
20271+ if (!user_mode(regs))
20272 report_bug(regs->ip, regs);
20273
20274 if (__die(str, regs, err))
20275diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
20276index f2a1770..540657f 100644
20277--- a/arch/x86/kernel/dumpstack_32.c
20278+++ b/arch/x86/kernel/dumpstack_32.c
20279@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20280 bp = stack_frame(task, regs);
20281
20282 for (;;) {
20283- struct thread_info *context;
20284+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
20285
20286- context = (struct thread_info *)
20287- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
20288- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
20289+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
20290
20291- stack = (unsigned long *)context->previous_esp;
20292- if (!stack)
20293+ if (stack_start == task_stack_page(task))
20294 break;
20295+ stack = *(unsigned long **)stack_start;
20296 if (ops->stack(data, "IRQ") < 0)
20297 break;
20298 touch_nmi_watchdog();
20299@@ -87,27 +85,28 @@ void show_regs(struct pt_regs *regs)
20300 int i;
20301
20302 show_regs_print_info(KERN_EMERG);
20303- __show_regs(regs, !user_mode_vm(regs));
20304+ __show_regs(regs, !user_mode(regs));
20305
20306 /*
20307 * When in-kernel, we also print out the stack and code at the
20308 * time of the fault..
20309 */
20310- if (!user_mode_vm(regs)) {
20311+ if (!user_mode(regs)) {
20312 unsigned int code_prologue = code_bytes * 43 / 64;
20313 unsigned int code_len = code_bytes;
20314 unsigned char c;
20315 u8 *ip;
20316+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
20317
20318 pr_emerg("Stack:\n");
20319 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
20320
20321 pr_emerg("Code:");
20322
20323- ip = (u8 *)regs->ip - code_prologue;
20324+ ip = (u8 *)regs->ip - code_prologue + cs_base;
20325 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
20326 /* try starting at IP */
20327- ip = (u8 *)regs->ip;
20328+ ip = (u8 *)regs->ip + cs_base;
20329 code_len = code_len - code_prologue + 1;
20330 }
20331 for (i = 0; i < code_len; i++, ip++) {
20332@@ -116,7 +115,7 @@ void show_regs(struct pt_regs *regs)
20333 pr_cont(" Bad EIP value.");
20334 break;
20335 }
20336- if (ip == (u8 *)regs->ip)
20337+ if (ip == (u8 *)regs->ip + cs_base)
20338 pr_cont(" <%02x>", c);
20339 else
20340 pr_cont(" %02x", c);
20341@@ -129,6 +128,7 @@ int is_valid_bugaddr(unsigned long ip)
20342 {
20343 unsigned short ud2;
20344
20345+ ip = ktla_ktva(ip);
20346 if (ip < PAGE_OFFSET)
20347 return 0;
20348 if (probe_kernel_address((unsigned short *)ip, ud2))
20349@@ -136,3 +136,15 @@ int is_valid_bugaddr(unsigned long ip)
20350
20351 return ud2 == 0x0b0f;
20352 }
20353+
20354+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20355+void pax_check_alloca(unsigned long size)
20356+{
20357+ unsigned long sp = (unsigned long)&sp, stack_left;
20358+
20359+ /* all kernel stacks are of the same size */
20360+ stack_left = sp & (THREAD_SIZE - 1);
20361+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
20362+}
20363+EXPORT_SYMBOL(pax_check_alloca);
20364+#endif
20365diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
20366index addb207..99635fa 100644
20367--- a/arch/x86/kernel/dumpstack_64.c
20368+++ b/arch/x86/kernel/dumpstack_64.c
20369@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20370 unsigned long *irq_stack_end =
20371 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
20372 unsigned used = 0;
20373- struct thread_info *tinfo;
20374 int graph = 0;
20375 unsigned long dummy;
20376+ void *stack_start;
20377
20378 if (!task)
20379 task = current;
20380@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20381 * current stack address. If the stacks consist of nested
20382 * exceptions
20383 */
20384- tinfo = task_thread_info(task);
20385 for (;;) {
20386 char *id;
20387 unsigned long *estack_end;
20388+
20389 estack_end = in_exception_stack(cpu, (unsigned long)stack,
20390 &used, &id);
20391
20392@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20393 if (ops->stack(data, id) < 0)
20394 break;
20395
20396- bp = ops->walk_stack(tinfo, stack, bp, ops,
20397+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
20398 data, estack_end, &graph);
20399 ops->stack(data, "<EOE>");
20400 /*
20401@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20402 * second-to-last pointer (index -2 to end) in the
20403 * exception stack:
20404 */
20405+ if ((u16)estack_end[-1] != __KERNEL_DS)
20406+ goto out;
20407 stack = (unsigned long *) estack_end[-2];
20408 continue;
20409 }
20410@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20411 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
20412 if (ops->stack(data, "IRQ") < 0)
20413 break;
20414- bp = ops->walk_stack(tinfo, stack, bp,
20415+ bp = ops->walk_stack(task, irq_stack, stack, bp,
20416 ops, data, irq_stack_end, &graph);
20417 /*
20418 * We link to the next stack (which would be
20419@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
20420 /*
20421 * This handles the process stack:
20422 */
20423- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
20424+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
20425+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
20426+out:
20427 put_cpu();
20428 }
20429 EXPORT_SYMBOL(dump_trace);
20430@@ -300,3 +304,50 @@ int is_valid_bugaddr(unsigned long ip)
20431
20432 return ud2 == 0x0b0f;
20433 }
20434+
20435+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20436+void pax_check_alloca(unsigned long size)
20437+{
20438+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
20439+ unsigned cpu, used;
20440+ char *id;
20441+
20442+ /* check the process stack first */
20443+ stack_start = (unsigned long)task_stack_page(current);
20444+ stack_end = stack_start + THREAD_SIZE;
20445+ if (likely(stack_start <= sp && sp < stack_end)) {
20446+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
20447+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
20448+ return;
20449+ }
20450+
20451+ cpu = get_cpu();
20452+
20453+ /* check the irq stacks */
20454+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
20455+ stack_start = stack_end - IRQ_STACK_SIZE;
20456+ if (stack_start <= sp && sp < stack_end) {
20457+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
20458+ put_cpu();
20459+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
20460+ return;
20461+ }
20462+
20463+ /* check the exception stacks */
20464+ used = 0;
20465+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
20466+ stack_start = stack_end - EXCEPTION_STKSZ;
20467+ if (stack_end && stack_start <= sp && sp < stack_end) {
20468+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
20469+ put_cpu();
20470+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
20471+ return;
20472+ }
20473+
20474+ put_cpu();
20475+
20476+ /* unknown stack */
20477+ BUG();
20478+}
20479+EXPORT_SYMBOL(pax_check_alloca);
20480+#endif
20481diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
20482index d32abea..74daf4f 100644
20483--- a/arch/x86/kernel/e820.c
20484+++ b/arch/x86/kernel/e820.c
20485@@ -800,8 +800,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
20486
20487 static void early_panic(char *msg)
20488 {
20489- early_printk(msg);
20490- panic(msg);
20491+ early_printk("%s", msg);
20492+ panic("%s", msg);
20493 }
20494
20495 static int userdef __initdata;
20496diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
20497index d15f575..d692043 100644
20498--- a/arch/x86/kernel/early_printk.c
20499+++ b/arch/x86/kernel/early_printk.c
20500@@ -7,6 +7,7 @@
20501 #include <linux/pci_regs.h>
20502 #include <linux/pci_ids.h>
20503 #include <linux/errno.h>
20504+#include <linux/sched.h>
20505 #include <asm/io.h>
20506 #include <asm/processor.h>
20507 #include <asm/fcntl.h>
20508diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
20509index 2cfbc3a..b756682 100644
20510--- a/arch/x86/kernel/entry_32.S
20511+++ b/arch/x86/kernel/entry_32.S
20512@@ -177,13 +177,153 @@
20513 /*CFI_REL_OFFSET gs, PT_GS*/
20514 .endm
20515 .macro SET_KERNEL_GS reg
20516+
20517+#ifdef CONFIG_CC_STACKPROTECTOR
20518 movl $(__KERNEL_STACK_CANARY), \reg
20519+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
20520+ movl $(__USER_DS), \reg
20521+#else
20522+ xorl \reg, \reg
20523+#endif
20524+
20525 movl \reg, %gs
20526 .endm
20527
20528 #endif /* CONFIG_X86_32_LAZY_GS */
20529
20530-.macro SAVE_ALL
20531+.macro pax_enter_kernel
20532+#ifdef CONFIG_PAX_KERNEXEC
20533+ call pax_enter_kernel
20534+#endif
20535+.endm
20536+
20537+.macro pax_exit_kernel
20538+#ifdef CONFIG_PAX_KERNEXEC
20539+ call pax_exit_kernel
20540+#endif
20541+.endm
20542+
20543+#ifdef CONFIG_PAX_KERNEXEC
20544+ENTRY(pax_enter_kernel)
20545+#ifdef CONFIG_PARAVIRT
20546+ pushl %eax
20547+ pushl %ecx
20548+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
20549+ mov %eax, %esi
20550+#else
20551+ mov %cr0, %esi
20552+#endif
20553+ bts $16, %esi
20554+ jnc 1f
20555+ mov %cs, %esi
20556+ cmp $__KERNEL_CS, %esi
20557+ jz 3f
20558+ ljmp $__KERNEL_CS, $3f
20559+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
20560+2:
20561+#ifdef CONFIG_PARAVIRT
20562+ mov %esi, %eax
20563+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
20564+#else
20565+ mov %esi, %cr0
20566+#endif
20567+3:
20568+#ifdef CONFIG_PARAVIRT
20569+ popl %ecx
20570+ popl %eax
20571+#endif
20572+ ret
20573+ENDPROC(pax_enter_kernel)
20574+
20575+ENTRY(pax_exit_kernel)
20576+#ifdef CONFIG_PARAVIRT
20577+ pushl %eax
20578+ pushl %ecx
20579+#endif
20580+ mov %cs, %esi
20581+ cmp $__KERNEXEC_KERNEL_CS, %esi
20582+ jnz 2f
20583+#ifdef CONFIG_PARAVIRT
20584+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
20585+ mov %eax, %esi
20586+#else
20587+ mov %cr0, %esi
20588+#endif
20589+ btr $16, %esi
20590+ ljmp $__KERNEL_CS, $1f
20591+1:
20592+#ifdef CONFIG_PARAVIRT
20593+ mov %esi, %eax
20594+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
20595+#else
20596+ mov %esi, %cr0
20597+#endif
20598+2:
20599+#ifdef CONFIG_PARAVIRT
20600+ popl %ecx
20601+ popl %eax
20602+#endif
20603+ ret
20604+ENDPROC(pax_exit_kernel)
20605+#endif
20606+
20607+ .macro pax_erase_kstack
20608+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20609+ call pax_erase_kstack
20610+#endif
20611+ .endm
20612+
20613+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
20614+/*
20615+ * ebp: thread_info
20616+ */
20617+ENTRY(pax_erase_kstack)
20618+ pushl %edi
20619+ pushl %ecx
20620+ pushl %eax
20621+
20622+ mov TI_lowest_stack(%ebp), %edi
20623+ mov $-0xBEEF, %eax
20624+ std
20625+
20626+1: mov %edi, %ecx
20627+ and $THREAD_SIZE_asm - 1, %ecx
20628+ shr $2, %ecx
20629+ repne scasl
20630+ jecxz 2f
20631+
20632+ cmp $2*16, %ecx
20633+ jc 2f
20634+
20635+ mov $2*16, %ecx
20636+ repe scasl
20637+ jecxz 2f
20638+ jne 1b
20639+
20640+2: cld
20641+ mov %esp, %ecx
20642+ sub %edi, %ecx
20643+
20644+ cmp $THREAD_SIZE_asm, %ecx
20645+ jb 3f
20646+ ud2
20647+3:
20648+
20649+ shr $2, %ecx
20650+ rep stosl
20651+
20652+ mov TI_task_thread_sp0(%ebp), %edi
20653+ sub $128, %edi
20654+ mov %edi, TI_lowest_stack(%ebp)
20655+
20656+ popl %eax
20657+ popl %ecx
20658+ popl %edi
20659+ ret
20660+ENDPROC(pax_erase_kstack)
20661+#endif
20662+
20663+.macro __SAVE_ALL _DS
20664 cld
20665 PUSH_GS
20666 pushl_cfi %fs
20667@@ -206,7 +346,7 @@
20668 CFI_REL_OFFSET ecx, 0
20669 pushl_cfi %ebx
20670 CFI_REL_OFFSET ebx, 0
20671- movl $(__USER_DS), %edx
20672+ movl $\_DS, %edx
20673 movl %edx, %ds
20674 movl %edx, %es
20675 movl $(__KERNEL_PERCPU), %edx
20676@@ -214,6 +354,15 @@
20677 SET_KERNEL_GS %edx
20678 .endm
20679
20680+.macro SAVE_ALL
20681+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
20682+ __SAVE_ALL __KERNEL_DS
20683+ pax_enter_kernel
20684+#else
20685+ __SAVE_ALL __USER_DS
20686+#endif
20687+.endm
20688+
20689 .macro RESTORE_INT_REGS
20690 popl_cfi %ebx
20691 CFI_RESTORE ebx
20692@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
20693 popfl_cfi
20694 jmp syscall_exit
20695 CFI_ENDPROC
20696-END(ret_from_fork)
20697+ENDPROC(ret_from_fork)
20698
20699 ENTRY(ret_from_kernel_thread)
20700 CFI_STARTPROC
20701@@ -344,7 +493,15 @@ ret_from_intr:
20702 andl $SEGMENT_RPL_MASK, %eax
20703 #endif
20704 cmpl $USER_RPL, %eax
20705+
20706+#ifdef CONFIG_PAX_KERNEXEC
20707+ jae resume_userspace
20708+
20709+ pax_exit_kernel
20710+ jmp resume_kernel
20711+#else
20712 jb resume_kernel # not returning to v8086 or userspace
20713+#endif
20714
20715 ENTRY(resume_userspace)
20716 LOCKDEP_SYS_EXIT
20717@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
20718 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
20719 # int/exception return?
20720 jne work_pending
20721- jmp restore_all
20722-END(ret_from_exception)
20723+ jmp restore_all_pax
20724+ENDPROC(ret_from_exception)
20725
20726 #ifdef CONFIG_PREEMPT
20727 ENTRY(resume_kernel)
20728@@ -372,7 +529,7 @@ need_resched:
20729 jz restore_all
20730 call preempt_schedule_irq
20731 jmp need_resched
20732-END(resume_kernel)
20733+ENDPROC(resume_kernel)
20734 #endif
20735 CFI_ENDPROC
20736 /*
20737@@ -406,30 +563,45 @@ sysenter_past_esp:
20738 /*CFI_REL_OFFSET cs, 0*/
20739 /*
20740 * Push current_thread_info()->sysenter_return to the stack.
20741- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
20742- * pushed above; +8 corresponds to copy_thread's esp0 setting.
20743 */
20744- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
20745+ pushl_cfi $0
20746 CFI_REL_OFFSET eip, 0
20747
20748 pushl_cfi %eax
20749 SAVE_ALL
20750+ GET_THREAD_INFO(%ebp)
20751+ movl TI_sysenter_return(%ebp),%ebp
20752+ movl %ebp,PT_EIP(%esp)
20753 ENABLE_INTERRUPTS(CLBR_NONE)
20754
20755 /*
20756 * Load the potential sixth argument from user stack.
20757 * Careful about security.
20758 */
20759+ movl PT_OLDESP(%esp),%ebp
20760+
20761+#ifdef CONFIG_PAX_MEMORY_UDEREF
20762+ mov PT_OLDSS(%esp),%ds
20763+1: movl %ds:(%ebp),%ebp
20764+ push %ss
20765+ pop %ds
20766+#else
20767 cmpl $__PAGE_OFFSET-3,%ebp
20768 jae syscall_fault
20769 ASM_STAC
20770 1: movl (%ebp),%ebp
20771 ASM_CLAC
20772+#endif
20773+
20774 movl %ebp,PT_EBP(%esp)
20775 _ASM_EXTABLE(1b,syscall_fault)
20776
20777 GET_THREAD_INFO(%ebp)
20778
20779+#ifdef CONFIG_PAX_RANDKSTACK
20780+ pax_erase_kstack
20781+#endif
20782+
20783 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
20784 jnz sysenter_audit
20785 sysenter_do_call:
20786@@ -444,12 +616,24 @@ sysenter_do_call:
20787 testl $_TIF_ALLWORK_MASK, %ecx
20788 jne sysexit_audit
20789 sysenter_exit:
20790+
20791+#ifdef CONFIG_PAX_RANDKSTACK
20792+ pushl_cfi %eax
20793+ movl %esp, %eax
20794+ call pax_randomize_kstack
20795+ popl_cfi %eax
20796+#endif
20797+
20798+ pax_erase_kstack
20799+
20800 /* if something modifies registers it must also disable sysexit */
20801 movl PT_EIP(%esp), %edx
20802 movl PT_OLDESP(%esp), %ecx
20803 xorl %ebp,%ebp
20804 TRACE_IRQS_ON
20805 1: mov PT_FS(%esp), %fs
20806+2: mov PT_DS(%esp), %ds
20807+3: mov PT_ES(%esp), %es
20808 PTGS_TO_GS
20809 ENABLE_INTERRUPTS_SYSEXIT
20810
20811@@ -466,6 +650,9 @@ sysenter_audit:
20812 movl %eax,%edx /* 2nd arg: syscall number */
20813 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
20814 call __audit_syscall_entry
20815+
20816+ pax_erase_kstack
20817+
20818 pushl_cfi %ebx
20819 movl PT_EAX(%esp),%eax /* reload syscall number */
20820 jmp sysenter_do_call
20821@@ -491,10 +678,16 @@ sysexit_audit:
20822
20823 CFI_ENDPROC
20824 .pushsection .fixup,"ax"
20825-2: movl $0,PT_FS(%esp)
20826+4: movl $0,PT_FS(%esp)
20827+ jmp 1b
20828+5: movl $0,PT_DS(%esp)
20829+ jmp 1b
20830+6: movl $0,PT_ES(%esp)
20831 jmp 1b
20832 .popsection
20833- _ASM_EXTABLE(1b,2b)
20834+ _ASM_EXTABLE(1b,4b)
20835+ _ASM_EXTABLE(2b,5b)
20836+ _ASM_EXTABLE(3b,6b)
20837 PTGS_TO_GS_EX
20838 ENDPROC(ia32_sysenter_target)
20839
20840@@ -509,6 +702,11 @@ ENTRY(system_call)
20841 pushl_cfi %eax # save orig_eax
20842 SAVE_ALL
20843 GET_THREAD_INFO(%ebp)
20844+
20845+#ifdef CONFIG_PAX_RANDKSTACK
20846+ pax_erase_kstack
20847+#endif
20848+
20849 # system call tracing in operation / emulation
20850 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
20851 jnz syscall_trace_entry
20852@@ -527,6 +725,15 @@ syscall_exit:
20853 testl $_TIF_ALLWORK_MASK, %ecx # current->work
20854 jne syscall_exit_work
20855
20856+restore_all_pax:
20857+
20858+#ifdef CONFIG_PAX_RANDKSTACK
20859+ movl %esp, %eax
20860+ call pax_randomize_kstack
20861+#endif
20862+
20863+ pax_erase_kstack
20864+
20865 restore_all:
20866 TRACE_IRQS_IRET
20867 restore_all_notrace:
20868@@ -583,14 +790,34 @@ ldt_ss:
20869 * compensating for the offset by changing to the ESPFIX segment with
20870 * a base address that matches for the difference.
20871 */
20872-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
20873+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
20874 mov %esp, %edx /* load kernel esp */
20875 mov PT_OLDESP(%esp), %eax /* load userspace esp */
20876 mov %dx, %ax /* eax: new kernel esp */
20877 sub %eax, %edx /* offset (low word is 0) */
20878+#ifdef CONFIG_SMP
20879+ movl PER_CPU_VAR(cpu_number), %ebx
20880+ shll $PAGE_SHIFT_asm, %ebx
20881+ addl $cpu_gdt_table, %ebx
20882+#else
20883+ movl $cpu_gdt_table, %ebx
20884+#endif
20885 shr $16, %edx
20886- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
20887- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
20888+
20889+#ifdef CONFIG_PAX_KERNEXEC
20890+ mov %cr0, %esi
20891+ btr $16, %esi
20892+ mov %esi, %cr0
20893+#endif
20894+
20895+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
20896+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
20897+
20898+#ifdef CONFIG_PAX_KERNEXEC
20899+ bts $16, %esi
20900+ mov %esi, %cr0
20901+#endif
20902+
20903 pushl_cfi $__ESPFIX_SS
20904 pushl_cfi %eax /* new kernel esp */
20905 /* Disable interrupts, but do not irqtrace this section: we
20906@@ -619,20 +846,18 @@ work_resched:
20907 movl TI_flags(%ebp), %ecx
20908 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
20909 # than syscall tracing?
20910- jz restore_all
20911+ jz restore_all_pax
20912 testb $_TIF_NEED_RESCHED, %cl
20913 jnz work_resched
20914
20915 work_notifysig: # deal with pending signals and
20916 # notify-resume requests
20917+ movl %esp, %eax
20918 #ifdef CONFIG_VM86
20919 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
20920- movl %esp, %eax
20921 jne work_notifysig_v86 # returning to kernel-space or
20922 # vm86-space
20923 1:
20924-#else
20925- movl %esp, %eax
20926 #endif
20927 TRACE_IRQS_ON
20928 ENABLE_INTERRUPTS(CLBR_NONE)
20929@@ -653,7 +878,7 @@ work_notifysig_v86:
20930 movl %eax, %esp
20931 jmp 1b
20932 #endif
20933-END(work_pending)
20934+ENDPROC(work_pending)
20935
20936 # perform syscall exit tracing
20937 ALIGN
20938@@ -661,11 +886,14 @@ syscall_trace_entry:
20939 movl $-ENOSYS,PT_EAX(%esp)
20940 movl %esp, %eax
20941 call syscall_trace_enter
20942+
20943+ pax_erase_kstack
20944+
20945 /* What it returned is what we'll actually use. */
20946 cmpl $(NR_syscalls), %eax
20947 jnae syscall_call
20948 jmp syscall_exit
20949-END(syscall_trace_entry)
20950+ENDPROC(syscall_trace_entry)
20951
20952 # perform syscall exit tracing
20953 ALIGN
20954@@ -678,21 +906,25 @@ syscall_exit_work:
20955 movl %esp, %eax
20956 call syscall_trace_leave
20957 jmp resume_userspace
20958-END(syscall_exit_work)
20959+ENDPROC(syscall_exit_work)
20960 CFI_ENDPROC
20961
20962 RING0_INT_FRAME # can't unwind into user space anyway
20963 syscall_fault:
20964+#ifdef CONFIG_PAX_MEMORY_UDEREF
20965+ push %ss
20966+ pop %ds
20967+#endif
20968 ASM_CLAC
20969 GET_THREAD_INFO(%ebp)
20970 movl $-EFAULT,PT_EAX(%esp)
20971 jmp resume_userspace
20972-END(syscall_fault)
20973+ENDPROC(syscall_fault)
20974
20975 syscall_badsys:
20976 movl $-ENOSYS,PT_EAX(%esp)
20977 jmp resume_userspace
20978-END(syscall_badsys)
20979+ENDPROC(syscall_badsys)
20980 CFI_ENDPROC
20981 /*
20982 * End of kprobes section
20983@@ -708,8 +940,15 @@ END(syscall_badsys)
20984 * normal stack and adjusts ESP with the matching offset.
20985 */
20986 /* fixup the stack */
20987- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
20988- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
20989+#ifdef CONFIG_SMP
20990+ movl PER_CPU_VAR(cpu_number), %ebx
20991+ shll $PAGE_SHIFT_asm, %ebx
20992+ addl $cpu_gdt_table, %ebx
20993+#else
20994+ movl $cpu_gdt_table, %ebx
20995+#endif
20996+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
20997+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
20998 shl $16, %eax
20999 addl %esp, %eax /* the adjusted stack pointer */
21000 pushl_cfi $__KERNEL_DS
21001@@ -762,7 +1001,7 @@ vector=vector+1
21002 .endr
21003 2: jmp common_interrupt
21004 .endr
21005-END(irq_entries_start)
21006+ENDPROC(irq_entries_start)
21007
21008 .previous
21009 END(interrupt)
21010@@ -823,7 +1062,7 @@ ENTRY(coprocessor_error)
21011 pushl_cfi $do_coprocessor_error
21012 jmp error_code
21013 CFI_ENDPROC
21014-END(coprocessor_error)
21015+ENDPROC(coprocessor_error)
21016
21017 ENTRY(simd_coprocessor_error)
21018 RING0_INT_FRAME
21019@@ -836,7 +1075,7 @@ ENTRY(simd_coprocessor_error)
21020 .section .altinstructions,"a"
21021 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
21022 .previous
21023-.section .altinstr_replacement,"ax"
21024+.section .altinstr_replacement,"a"
21025 663: pushl $do_simd_coprocessor_error
21026 664:
21027 .previous
21028@@ -845,7 +1084,7 @@ ENTRY(simd_coprocessor_error)
21029 #endif
21030 jmp error_code
21031 CFI_ENDPROC
21032-END(simd_coprocessor_error)
21033+ENDPROC(simd_coprocessor_error)
21034
21035 ENTRY(device_not_available)
21036 RING0_INT_FRAME
21037@@ -854,18 +1093,18 @@ ENTRY(device_not_available)
21038 pushl_cfi $do_device_not_available
21039 jmp error_code
21040 CFI_ENDPROC
21041-END(device_not_available)
21042+ENDPROC(device_not_available)
21043
21044 #ifdef CONFIG_PARAVIRT
21045 ENTRY(native_iret)
21046 iret
21047 _ASM_EXTABLE(native_iret, iret_exc)
21048-END(native_iret)
21049+ENDPROC(native_iret)
21050
21051 ENTRY(native_irq_enable_sysexit)
21052 sti
21053 sysexit
21054-END(native_irq_enable_sysexit)
21055+ENDPROC(native_irq_enable_sysexit)
21056 #endif
21057
21058 ENTRY(overflow)
21059@@ -875,7 +1114,7 @@ ENTRY(overflow)
21060 pushl_cfi $do_overflow
21061 jmp error_code
21062 CFI_ENDPROC
21063-END(overflow)
21064+ENDPROC(overflow)
21065
21066 ENTRY(bounds)
21067 RING0_INT_FRAME
21068@@ -884,7 +1123,7 @@ ENTRY(bounds)
21069 pushl_cfi $do_bounds
21070 jmp error_code
21071 CFI_ENDPROC
21072-END(bounds)
21073+ENDPROC(bounds)
21074
21075 ENTRY(invalid_op)
21076 RING0_INT_FRAME
21077@@ -893,7 +1132,7 @@ ENTRY(invalid_op)
21078 pushl_cfi $do_invalid_op
21079 jmp error_code
21080 CFI_ENDPROC
21081-END(invalid_op)
21082+ENDPROC(invalid_op)
21083
21084 ENTRY(coprocessor_segment_overrun)
21085 RING0_INT_FRAME
21086@@ -902,7 +1141,7 @@ ENTRY(coprocessor_segment_overrun)
21087 pushl_cfi $do_coprocessor_segment_overrun
21088 jmp error_code
21089 CFI_ENDPROC
21090-END(coprocessor_segment_overrun)
21091+ENDPROC(coprocessor_segment_overrun)
21092
21093 ENTRY(invalid_TSS)
21094 RING0_EC_FRAME
21095@@ -910,7 +1149,7 @@ ENTRY(invalid_TSS)
21096 pushl_cfi $do_invalid_TSS
21097 jmp error_code
21098 CFI_ENDPROC
21099-END(invalid_TSS)
21100+ENDPROC(invalid_TSS)
21101
21102 ENTRY(segment_not_present)
21103 RING0_EC_FRAME
21104@@ -918,7 +1157,7 @@ ENTRY(segment_not_present)
21105 pushl_cfi $do_segment_not_present
21106 jmp error_code
21107 CFI_ENDPROC
21108-END(segment_not_present)
21109+ENDPROC(segment_not_present)
21110
21111 ENTRY(stack_segment)
21112 RING0_EC_FRAME
21113@@ -926,7 +1165,7 @@ ENTRY(stack_segment)
21114 pushl_cfi $do_stack_segment
21115 jmp error_code
21116 CFI_ENDPROC
21117-END(stack_segment)
21118+ENDPROC(stack_segment)
21119
21120 ENTRY(alignment_check)
21121 RING0_EC_FRAME
21122@@ -934,7 +1173,7 @@ ENTRY(alignment_check)
21123 pushl_cfi $do_alignment_check
21124 jmp error_code
21125 CFI_ENDPROC
21126-END(alignment_check)
21127+ENDPROC(alignment_check)
21128
21129 ENTRY(divide_error)
21130 RING0_INT_FRAME
21131@@ -943,7 +1182,7 @@ ENTRY(divide_error)
21132 pushl_cfi $do_divide_error
21133 jmp error_code
21134 CFI_ENDPROC
21135-END(divide_error)
21136+ENDPROC(divide_error)
21137
21138 #ifdef CONFIG_X86_MCE
21139 ENTRY(machine_check)
21140@@ -953,7 +1192,7 @@ ENTRY(machine_check)
21141 pushl_cfi machine_check_vector
21142 jmp error_code
21143 CFI_ENDPROC
21144-END(machine_check)
21145+ENDPROC(machine_check)
21146 #endif
21147
21148 ENTRY(spurious_interrupt_bug)
21149@@ -963,7 +1202,7 @@ ENTRY(spurious_interrupt_bug)
21150 pushl_cfi $do_spurious_interrupt_bug
21151 jmp error_code
21152 CFI_ENDPROC
21153-END(spurious_interrupt_bug)
21154+ENDPROC(spurious_interrupt_bug)
21155 /*
21156 * End of kprobes section
21157 */
21158@@ -1073,7 +1312,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
21159
21160 ENTRY(mcount)
21161 ret
21162-END(mcount)
21163+ENDPROC(mcount)
21164
21165 ENTRY(ftrace_caller)
21166 cmpl $0, function_trace_stop
21167@@ -1106,7 +1345,7 @@ ftrace_graph_call:
21168 .globl ftrace_stub
21169 ftrace_stub:
21170 ret
21171-END(ftrace_caller)
21172+ENDPROC(ftrace_caller)
21173
21174 ENTRY(ftrace_regs_caller)
21175 pushf /* push flags before compare (in cs location) */
21176@@ -1207,7 +1446,7 @@ trace:
21177 popl %ecx
21178 popl %eax
21179 jmp ftrace_stub
21180-END(mcount)
21181+ENDPROC(mcount)
21182 #endif /* CONFIG_DYNAMIC_FTRACE */
21183 #endif /* CONFIG_FUNCTION_TRACER */
21184
21185@@ -1225,7 +1464,7 @@ ENTRY(ftrace_graph_caller)
21186 popl %ecx
21187 popl %eax
21188 ret
21189-END(ftrace_graph_caller)
21190+ENDPROC(ftrace_graph_caller)
21191
21192 .globl return_to_handler
21193 return_to_handler:
21194@@ -1281,15 +1520,18 @@ error_code:
21195 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
21196 REG_TO_PTGS %ecx
21197 SET_KERNEL_GS %ecx
21198- movl $(__USER_DS), %ecx
21199+ movl $(__KERNEL_DS), %ecx
21200 movl %ecx, %ds
21201 movl %ecx, %es
21202+
21203+ pax_enter_kernel
21204+
21205 TRACE_IRQS_OFF
21206 movl %esp,%eax # pt_regs pointer
21207 call *%edi
21208 jmp ret_from_exception
21209 CFI_ENDPROC
21210-END(page_fault)
21211+ENDPROC(page_fault)
21212
21213 /*
21214 * Debug traps and NMI can happen at the one SYSENTER instruction
21215@@ -1332,7 +1574,7 @@ debug_stack_correct:
21216 call do_debug
21217 jmp ret_from_exception
21218 CFI_ENDPROC
21219-END(debug)
21220+ENDPROC(debug)
21221
21222 /*
21223 * NMI is doubly nasty. It can happen _while_ we're handling
21224@@ -1370,6 +1612,9 @@ nmi_stack_correct:
21225 xorl %edx,%edx # zero error code
21226 movl %esp,%eax # pt_regs pointer
21227 call do_nmi
21228+
21229+ pax_exit_kernel
21230+
21231 jmp restore_all_notrace
21232 CFI_ENDPROC
21233
21234@@ -1406,12 +1651,15 @@ nmi_espfix_stack:
21235 FIXUP_ESPFIX_STACK # %eax == %esp
21236 xorl %edx,%edx # zero error code
21237 call do_nmi
21238+
21239+ pax_exit_kernel
21240+
21241 RESTORE_REGS
21242 lss 12+4(%esp), %esp # back to espfix stack
21243 CFI_ADJUST_CFA_OFFSET -24
21244 jmp irq_return
21245 CFI_ENDPROC
21246-END(nmi)
21247+ENDPROC(nmi)
21248
21249 ENTRY(int3)
21250 RING0_INT_FRAME
21251@@ -1424,14 +1672,14 @@ ENTRY(int3)
21252 call do_int3
21253 jmp ret_from_exception
21254 CFI_ENDPROC
21255-END(int3)
21256+ENDPROC(int3)
21257
21258 ENTRY(general_protection)
21259 RING0_EC_FRAME
21260 pushl_cfi $do_general_protection
21261 jmp error_code
21262 CFI_ENDPROC
21263-END(general_protection)
21264+ENDPROC(general_protection)
21265
21266 #ifdef CONFIG_KVM_GUEST
21267 ENTRY(async_page_fault)
21268@@ -1440,7 +1688,7 @@ ENTRY(async_page_fault)
21269 pushl_cfi $do_async_page_fault
21270 jmp error_code
21271 CFI_ENDPROC
21272-END(async_page_fault)
21273+ENDPROC(async_page_fault)
21274 #endif
21275
21276 /*
21277diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
21278index 1b69951..8430a6d 100644
21279--- a/arch/x86/kernel/entry_64.S
21280+++ b/arch/x86/kernel/entry_64.S
21281@@ -59,6 +59,8 @@
21282 #include <asm/context_tracking.h>
21283 #include <asm/smap.h>
21284 #include <linux/err.h>
21285+#include <asm/pgtable.h>
21286+#include <asm/alternative-asm.h>
21287
21288 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
21289 #include <linux/elf-em.h>
21290@@ -80,8 +82,9 @@
21291 #ifdef CONFIG_DYNAMIC_FTRACE
21292
21293 ENTRY(function_hook)
21294+ pax_force_retaddr
21295 retq
21296-END(function_hook)
21297+ENDPROC(function_hook)
21298
21299 /* skip is set if stack has been adjusted */
21300 .macro ftrace_caller_setup skip=0
21301@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
21302 #endif
21303
21304 GLOBAL(ftrace_stub)
21305+ pax_force_retaddr
21306 retq
21307-END(ftrace_caller)
21308+ENDPROC(ftrace_caller)
21309
21310 ENTRY(ftrace_regs_caller)
21311 /* Save the current flags before compare (in SS location)*/
21312@@ -191,7 +195,7 @@ ftrace_restore_flags:
21313 popfq
21314 jmp ftrace_stub
21315
21316-END(ftrace_regs_caller)
21317+ENDPROC(ftrace_regs_caller)
21318
21319
21320 #else /* ! CONFIG_DYNAMIC_FTRACE */
21321@@ -212,6 +216,7 @@ ENTRY(function_hook)
21322 #endif
21323
21324 GLOBAL(ftrace_stub)
21325+ pax_force_retaddr
21326 retq
21327
21328 trace:
21329@@ -225,12 +230,13 @@ trace:
21330 #endif
21331 subq $MCOUNT_INSN_SIZE, %rdi
21332
21333+ pax_force_fptr ftrace_trace_function
21334 call *ftrace_trace_function
21335
21336 MCOUNT_RESTORE_FRAME
21337
21338 jmp ftrace_stub
21339-END(function_hook)
21340+ENDPROC(function_hook)
21341 #endif /* CONFIG_DYNAMIC_FTRACE */
21342 #endif /* CONFIG_FUNCTION_TRACER */
21343
21344@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
21345
21346 MCOUNT_RESTORE_FRAME
21347
21348+ pax_force_retaddr
21349 retq
21350-END(ftrace_graph_caller)
21351+ENDPROC(ftrace_graph_caller)
21352
21353 GLOBAL(return_to_handler)
21354 subq $24, %rsp
21355@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
21356 movq 8(%rsp), %rdx
21357 movq (%rsp), %rax
21358 addq $24, %rsp
21359+ pax_force_fptr %rdi
21360 jmp *%rdi
21361+ENDPROC(return_to_handler)
21362 #endif
21363
21364
21365@@ -284,6 +293,430 @@ ENTRY(native_usergs_sysret64)
21366 ENDPROC(native_usergs_sysret64)
21367 #endif /* CONFIG_PARAVIRT */
21368
21369+ .macro ljmpq sel, off
21370+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
21371+ .byte 0x48; ljmp *1234f(%rip)
21372+ .pushsection .rodata
21373+ .align 16
21374+ 1234: .quad \off; .word \sel
21375+ .popsection
21376+#else
21377+ pushq $\sel
21378+ pushq $\off
21379+ lretq
21380+#endif
21381+ .endm
21382+
21383+ .macro pax_enter_kernel
21384+ pax_set_fptr_mask
21385+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21386+ call pax_enter_kernel
21387+#endif
21388+ .endm
21389+
21390+ .macro pax_exit_kernel
21391+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21392+ call pax_exit_kernel
21393+#endif
21394+
21395+ .endm
21396+
21397+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21398+ENTRY(pax_enter_kernel)
21399+ pushq %rdi
21400+
21401+#ifdef CONFIG_PARAVIRT
21402+ PV_SAVE_REGS(CLBR_RDI)
21403+#endif
21404+
21405+#ifdef CONFIG_PAX_KERNEXEC
21406+ GET_CR0_INTO_RDI
21407+ bts $16,%rdi
21408+ jnc 3f
21409+ mov %cs,%edi
21410+ cmp $__KERNEL_CS,%edi
21411+ jnz 2f
21412+1:
21413+#endif
21414+
21415+#ifdef CONFIG_PAX_MEMORY_UDEREF
21416+ 661: jmp 111f
21417+ .pushsection .altinstr_replacement, "a"
21418+ 662: ASM_NOP2
21419+ .popsection
21420+ .pushsection .altinstructions, "a"
21421+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21422+ .popsection
21423+ GET_CR3_INTO_RDI
21424+ cmp $0,%dil
21425+ jnz 112f
21426+ mov $__KERNEL_DS,%edi
21427+ mov %edi,%ss
21428+ jmp 111f
21429+112: cmp $1,%dil
21430+ jz 113f
21431+ ud2
21432+113: sub $4097,%rdi
21433+ bts $63,%rdi
21434+ SET_RDI_INTO_CR3
21435+ mov $__UDEREF_KERNEL_DS,%edi
21436+ mov %edi,%ss
21437+111:
21438+#endif
21439+
21440+#ifdef CONFIG_PARAVIRT
21441+ PV_RESTORE_REGS(CLBR_RDI)
21442+#endif
21443+
21444+ popq %rdi
21445+ pax_force_retaddr
21446+ retq
21447+
21448+#ifdef CONFIG_PAX_KERNEXEC
21449+2: ljmpq __KERNEL_CS,1b
21450+3: ljmpq __KERNEXEC_KERNEL_CS,4f
21451+4: SET_RDI_INTO_CR0
21452+ jmp 1b
21453+#endif
21454+ENDPROC(pax_enter_kernel)
21455+
21456+ENTRY(pax_exit_kernel)
21457+ pushq %rdi
21458+
21459+#ifdef CONFIG_PARAVIRT
21460+ PV_SAVE_REGS(CLBR_RDI)
21461+#endif
21462+
21463+#ifdef CONFIG_PAX_KERNEXEC
21464+ mov %cs,%rdi
21465+ cmp $__KERNEXEC_KERNEL_CS,%edi
21466+ jz 2f
21467+ GET_CR0_INTO_RDI
21468+ bts $16,%rdi
21469+ jnc 4f
21470+1:
21471+#endif
21472+
21473+#ifdef CONFIG_PAX_MEMORY_UDEREF
21474+ 661: jmp 111f
21475+ .pushsection .altinstr_replacement, "a"
21476+ 662: ASM_NOP2
21477+ .popsection
21478+ .pushsection .altinstructions, "a"
21479+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21480+ .popsection
21481+ mov %ss,%edi
21482+ cmp $__UDEREF_KERNEL_DS,%edi
21483+ jnz 111f
21484+ GET_CR3_INTO_RDI
21485+ cmp $0,%dil
21486+ jz 112f
21487+ ud2
21488+112: add $4097,%rdi
21489+ bts $63,%rdi
21490+ SET_RDI_INTO_CR3
21491+ mov $__KERNEL_DS,%edi
21492+ mov %edi,%ss
21493+111:
21494+#endif
21495+
21496+#ifdef CONFIG_PARAVIRT
21497+ PV_RESTORE_REGS(CLBR_RDI);
21498+#endif
21499+
21500+ popq %rdi
21501+ pax_force_retaddr
21502+ retq
21503+
21504+#ifdef CONFIG_PAX_KERNEXEC
21505+2: GET_CR0_INTO_RDI
21506+ btr $16,%rdi
21507+ jnc 4f
21508+ ljmpq __KERNEL_CS,3f
21509+3: SET_RDI_INTO_CR0
21510+ jmp 1b
21511+4: ud2
21512+ jmp 4b
21513+#endif
21514+ENDPROC(pax_exit_kernel)
21515+#endif
21516+
21517+ .macro pax_enter_kernel_user
21518+ pax_set_fptr_mask
21519+#ifdef CONFIG_PAX_MEMORY_UDEREF
21520+ call pax_enter_kernel_user
21521+#endif
21522+ .endm
21523+
21524+ .macro pax_exit_kernel_user
21525+#ifdef CONFIG_PAX_MEMORY_UDEREF
21526+ call pax_exit_kernel_user
21527+#endif
21528+#ifdef CONFIG_PAX_RANDKSTACK
21529+ pushq %rax
21530+ pushq %r11
21531+ call pax_randomize_kstack
21532+ popq %r11
21533+ popq %rax
21534+#endif
21535+ .endm
21536+
21537+#ifdef CONFIG_PAX_MEMORY_UDEREF
21538+ENTRY(pax_enter_kernel_user)
21539+ pushq %rdi
21540+ pushq %rbx
21541+
21542+#ifdef CONFIG_PARAVIRT
21543+ PV_SAVE_REGS(CLBR_RDI)
21544+#endif
21545+
21546+ 661: jmp 111f
21547+ .pushsection .altinstr_replacement, "a"
21548+ 662: ASM_NOP2
21549+ .popsection
21550+ .pushsection .altinstructions, "a"
21551+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21552+ .popsection
21553+ GET_CR3_INTO_RDI
21554+ cmp $1,%dil
21555+ jnz 4f
21556+ sub $4097,%rdi
21557+ bts $63,%rdi
21558+ SET_RDI_INTO_CR3
21559+ jmp 3f
21560+111:
21561+
21562+ GET_CR3_INTO_RDI
21563+ mov %rdi,%rbx
21564+ add $__START_KERNEL_map,%rbx
21565+ sub phys_base(%rip),%rbx
21566+
21567+#ifdef CONFIG_PARAVIRT
21568+ cmpl $0, pv_info+PARAVIRT_enabled
21569+ jz 1f
21570+ pushq %rdi
21571+ i = 0
21572+ .rept USER_PGD_PTRS
21573+ mov i*8(%rbx),%rsi
21574+ mov $0,%sil
21575+ lea i*8(%rbx),%rdi
21576+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
21577+ i = i + 1
21578+ .endr
21579+ popq %rdi
21580+ jmp 2f
21581+1:
21582+#endif
21583+
21584+ i = 0
21585+ .rept USER_PGD_PTRS
21586+ movb $0,i*8(%rbx)
21587+ i = i + 1
21588+ .endr
21589+
21590+2: SET_RDI_INTO_CR3
21591+
21592+#ifdef CONFIG_PAX_KERNEXEC
21593+ GET_CR0_INTO_RDI
21594+ bts $16,%rdi
21595+ SET_RDI_INTO_CR0
21596+#endif
21597+
21598+3:
21599+
21600+#ifdef CONFIG_PARAVIRT
21601+ PV_RESTORE_REGS(CLBR_RDI)
21602+#endif
21603+
21604+ popq %rbx
21605+ popq %rdi
21606+ pax_force_retaddr
21607+ retq
21608+4: ud2
21609+ENDPROC(pax_enter_kernel_user)
21610+
21611+ENTRY(pax_exit_kernel_user)
21612+ pushq %rdi
21613+ pushq %rbx
21614+
21615+#ifdef CONFIG_PARAVIRT
21616+ PV_SAVE_REGS(CLBR_RDI)
21617+#endif
21618+
21619+ GET_CR3_INTO_RDI
21620+ 661: jmp 1f
21621+ .pushsection .altinstr_replacement, "a"
21622+ 662: ASM_NOP2
21623+ .popsection
21624+ .pushsection .altinstructions, "a"
21625+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21626+ .popsection
21627+ cmp $0,%dil
21628+ jnz 3f
21629+ add $4097,%rdi
21630+ bts $63,%rdi
21631+ SET_RDI_INTO_CR3
21632+ jmp 2f
21633+1:
21634+
21635+ mov %rdi,%rbx
21636+
21637+#ifdef CONFIG_PAX_KERNEXEC
21638+ GET_CR0_INTO_RDI
21639+ btr $16,%rdi
21640+ jnc 3f
21641+ SET_RDI_INTO_CR0
21642+#endif
21643+
21644+ add $__START_KERNEL_map,%rbx
21645+ sub phys_base(%rip),%rbx
21646+
21647+#ifdef CONFIG_PARAVIRT
21648+ cmpl $0, pv_info+PARAVIRT_enabled
21649+ jz 1f
21650+ i = 0
21651+ .rept USER_PGD_PTRS
21652+ mov i*8(%rbx),%rsi
21653+ mov $0x67,%sil
21654+ lea i*8(%rbx),%rdi
21655+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
21656+ i = i + 1
21657+ .endr
21658+ jmp 2f
21659+1:
21660+#endif
21661+
21662+ i = 0
21663+ .rept USER_PGD_PTRS
21664+ movb $0x67,i*8(%rbx)
21665+ i = i + 1
21666+ .endr
21667+2:
21668+
21669+#ifdef CONFIG_PARAVIRT
21670+ PV_RESTORE_REGS(CLBR_RDI)
21671+#endif
21672+
21673+ popq %rbx
21674+ popq %rdi
21675+ pax_force_retaddr
21676+ retq
21677+3: ud2
21678+ENDPROC(pax_exit_kernel_user)
21679+#endif
21680+
21681+ .macro pax_enter_kernel_nmi
21682+ pax_set_fptr_mask
21683+
21684+#ifdef CONFIG_PAX_KERNEXEC
21685+ GET_CR0_INTO_RDI
21686+ bts $16,%rdi
21687+ jc 110f
21688+ SET_RDI_INTO_CR0
21689+ or $2,%ebx
21690+110:
21691+#endif
21692+
21693+#ifdef CONFIG_PAX_MEMORY_UDEREF
21694+ 661: jmp 111f
21695+ .pushsection .altinstr_replacement, "a"
21696+ 662: ASM_NOP2
21697+ .popsection
21698+ .pushsection .altinstructions, "a"
21699+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
21700+ .popsection
21701+ GET_CR3_INTO_RDI
21702+ cmp $0,%dil
21703+ jz 111f
21704+ sub $4097,%rdi
21705+ or $4,%ebx
21706+ bts $63,%rdi
21707+ SET_RDI_INTO_CR3
21708+ mov $__UDEREF_KERNEL_DS,%edi
21709+ mov %edi,%ss
21710+111:
21711+#endif
21712+ .endm
21713+
21714+ .macro pax_exit_kernel_nmi
21715+#ifdef CONFIG_PAX_KERNEXEC
21716+ btr $1,%ebx
21717+ jnc 110f
21718+ GET_CR0_INTO_RDI
21719+ btr $16,%rdi
21720+ SET_RDI_INTO_CR0
21721+110:
21722+#endif
21723+
21724+#ifdef CONFIG_PAX_MEMORY_UDEREF
21725+ btr $2,%ebx
21726+ jnc 111f
21727+ GET_CR3_INTO_RDI
21728+ add $4097,%rdi
21729+ bts $63,%rdi
21730+ SET_RDI_INTO_CR3
21731+ mov $__KERNEL_DS,%edi
21732+ mov %edi,%ss
21733+111:
21734+#endif
21735+ .endm
21736+
21737+ .macro pax_erase_kstack
21738+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21739+ call pax_erase_kstack
21740+#endif
21741+ .endm
21742+
21743+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21744+ENTRY(pax_erase_kstack)
21745+ pushq %rdi
21746+ pushq %rcx
21747+ pushq %rax
21748+ pushq %r11
21749+
21750+ GET_THREAD_INFO(%r11)
21751+ mov TI_lowest_stack(%r11), %rdi
21752+ mov $-0xBEEF, %rax
21753+ std
21754+
21755+1: mov %edi, %ecx
21756+ and $THREAD_SIZE_asm - 1, %ecx
21757+ shr $3, %ecx
21758+ repne scasq
21759+ jecxz 2f
21760+
21761+ cmp $2*8, %ecx
21762+ jc 2f
21763+
21764+ mov $2*8, %ecx
21765+ repe scasq
21766+ jecxz 2f
21767+ jne 1b
21768+
21769+2: cld
21770+ mov %esp, %ecx
21771+ sub %edi, %ecx
21772+
21773+ cmp $THREAD_SIZE_asm, %rcx
21774+ jb 3f
21775+ ud2
21776+3:
21777+
21778+ shr $3, %ecx
21779+ rep stosq
21780+
21781+ mov TI_task_thread_sp0(%r11), %rdi
21782+ sub $256, %rdi
21783+ mov %rdi, TI_lowest_stack(%r11)
21784+
21785+ popq %r11
21786+ popq %rax
21787+ popq %rcx
21788+ popq %rdi
21789+ pax_force_retaddr
21790+ ret
21791+ENDPROC(pax_erase_kstack)
21792+#endif
21793
21794 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
21795 #ifdef CONFIG_TRACE_IRQFLAGS
21796@@ -375,8 +808,8 @@ ENDPROC(native_usergs_sysret64)
21797 .endm
21798
21799 .macro UNFAKE_STACK_FRAME
21800- addq $8*6, %rsp
21801- CFI_ADJUST_CFA_OFFSET -(6*8)
21802+ addq $8*6 + ARG_SKIP, %rsp
21803+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
21804 .endm
21805
21806 /*
21807@@ -463,7 +896,7 @@ ENDPROC(native_usergs_sysret64)
21808 movq %rsp, %rsi
21809
21810 leaq -RBP(%rsp),%rdi /* arg1 for handler */
21811- testl $3, CS-RBP(%rsi)
21812+ testb $3, CS-RBP(%rsi)
21813 je 1f
21814 SWAPGS
21815 /*
21816@@ -498,9 +931,10 @@ ENTRY(save_rest)
21817 movq_cfi r15, R15+16
21818 movq %r11, 8(%rsp) /* return address */
21819 FIXUP_TOP_OF_STACK %r11, 16
21820+ pax_force_retaddr
21821 ret
21822 CFI_ENDPROC
21823-END(save_rest)
21824+ENDPROC(save_rest)
21825
21826 /* save complete stack frame */
21827 .pushsection .kprobes.text, "ax"
21828@@ -529,9 +963,10 @@ ENTRY(save_paranoid)
21829 js 1f /* negative -> in kernel */
21830 SWAPGS
21831 xorl %ebx,%ebx
21832-1: ret
21833+1: pax_force_retaddr_bts
21834+ ret
21835 CFI_ENDPROC
21836-END(save_paranoid)
21837+ENDPROC(save_paranoid)
21838 .popsection
21839
21840 /*
21841@@ -553,7 +988,7 @@ ENTRY(ret_from_fork)
21842
21843 RESTORE_REST
21844
21845- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
21846+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
21847 jz 1f
21848
21849 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
21850@@ -571,7 +1006,7 @@ ENTRY(ret_from_fork)
21851 RESTORE_REST
21852 jmp int_ret_from_sys_call
21853 CFI_ENDPROC
21854-END(ret_from_fork)
21855+ENDPROC(ret_from_fork)
21856
21857 /*
21858 * System call entry. Up to 6 arguments in registers are supported.
21859@@ -608,7 +1043,7 @@ END(ret_from_fork)
21860 ENTRY(system_call)
21861 CFI_STARTPROC simple
21862 CFI_SIGNAL_FRAME
21863- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
21864+ CFI_DEF_CFA rsp,0
21865 CFI_REGISTER rip,rcx
21866 /*CFI_REGISTER rflags,r11*/
21867 SWAPGS_UNSAFE_STACK
21868@@ -621,16 +1056,23 @@ GLOBAL(system_call_after_swapgs)
21869
21870 movq %rsp,PER_CPU_VAR(old_rsp)
21871 movq PER_CPU_VAR(kernel_stack),%rsp
21872+ SAVE_ARGS 8*6,0
21873+ pax_enter_kernel_user
21874+
21875+#ifdef CONFIG_PAX_RANDKSTACK
21876+ pax_erase_kstack
21877+#endif
21878+
21879 /*
21880 * No need to follow this irqs off/on section - it's straight
21881 * and short:
21882 */
21883 ENABLE_INTERRUPTS(CLBR_NONE)
21884- SAVE_ARGS 8,0
21885 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
21886 movq %rcx,RIP-ARGOFFSET(%rsp)
21887 CFI_REL_OFFSET rip,RIP-ARGOFFSET
21888- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
21889+ GET_THREAD_INFO(%rcx)
21890+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
21891 jnz tracesys
21892 system_call_fastpath:
21893 #if __SYSCALL_MASK == ~0
21894@@ -640,7 +1082,7 @@ system_call_fastpath:
21895 cmpl $__NR_syscall_max,%eax
21896 #endif
21897 ja badsys
21898- movq %r10,%rcx
21899+ movq R10-ARGOFFSET(%rsp),%rcx
21900 call *sys_call_table(,%rax,8) # XXX: rip relative
21901 movq %rax,RAX-ARGOFFSET(%rsp)
21902 /*
21903@@ -654,10 +1096,13 @@ sysret_check:
21904 LOCKDEP_SYS_EXIT
21905 DISABLE_INTERRUPTS(CLBR_NONE)
21906 TRACE_IRQS_OFF
21907- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
21908+ GET_THREAD_INFO(%rcx)
21909+ movl TI_flags(%rcx),%edx
21910 andl %edi,%edx
21911 jnz sysret_careful
21912 CFI_REMEMBER_STATE
21913+ pax_exit_kernel_user
21914+ pax_erase_kstack
21915 /*
21916 * sysretq will re-enable interrupts:
21917 */
21918@@ -709,14 +1154,18 @@ badsys:
21919 * jump back to the normal fast path.
21920 */
21921 auditsys:
21922- movq %r10,%r9 /* 6th arg: 4th syscall arg */
21923+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
21924 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
21925 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
21926 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
21927 movq %rax,%rsi /* 2nd arg: syscall number */
21928 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
21929 call __audit_syscall_entry
21930+
21931+ pax_erase_kstack
21932+
21933 LOAD_ARGS 0 /* reload call-clobbered registers */
21934+ pax_set_fptr_mask
21935 jmp system_call_fastpath
21936
21937 /*
21938@@ -737,7 +1186,7 @@ sysret_audit:
21939 /* Do syscall tracing */
21940 tracesys:
21941 #ifdef CONFIG_AUDITSYSCALL
21942- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
21943+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
21944 jz auditsys
21945 #endif
21946 SAVE_REST
21947@@ -745,12 +1194,16 @@ tracesys:
21948 FIXUP_TOP_OF_STACK %rdi
21949 movq %rsp,%rdi
21950 call syscall_trace_enter
21951+
21952+ pax_erase_kstack
21953+
21954 /*
21955 * Reload arg registers from stack in case ptrace changed them.
21956 * We don't reload %rax because syscall_trace_enter() returned
21957 * the value it wants us to use in the table lookup.
21958 */
21959 LOAD_ARGS ARGOFFSET, 1
21960+ pax_set_fptr_mask
21961 RESTORE_REST
21962 #if __SYSCALL_MASK == ~0
21963 cmpq $__NR_syscall_max,%rax
21964@@ -759,7 +1212,7 @@ tracesys:
21965 cmpl $__NR_syscall_max,%eax
21966 #endif
21967 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
21968- movq %r10,%rcx /* fixup for C */
21969+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
21970 call *sys_call_table(,%rax,8)
21971 movq %rax,RAX-ARGOFFSET(%rsp)
21972 /* Use IRET because user could have changed frame */
21973@@ -780,7 +1233,9 @@ GLOBAL(int_with_check)
21974 andl %edi,%edx
21975 jnz int_careful
21976 andl $~TS_COMPAT,TI_status(%rcx)
21977- jmp retint_swapgs
21978+ pax_exit_kernel_user
21979+ pax_erase_kstack
21980+ jmp retint_swapgs_pax
21981
21982 /* Either reschedule or signal or syscall exit tracking needed. */
21983 /* First do a reschedule test. */
21984@@ -826,7 +1281,7 @@ int_restore_rest:
21985 TRACE_IRQS_OFF
21986 jmp int_with_check
21987 CFI_ENDPROC
21988-END(system_call)
21989+ENDPROC(system_call)
21990
21991 .macro FORK_LIKE func
21992 ENTRY(stub_\func)
21993@@ -839,9 +1294,10 @@ ENTRY(stub_\func)
21994 DEFAULT_FRAME 0 8 /* offset 8: return address */
21995 call sys_\func
21996 RESTORE_TOP_OF_STACK %r11, 8
21997+ pax_force_retaddr
21998 ret $REST_SKIP /* pop extended registers */
21999 CFI_ENDPROC
22000-END(stub_\func)
22001+ENDPROC(stub_\func)
22002 .endm
22003
22004 .macro FIXED_FRAME label,func
22005@@ -851,9 +1307,10 @@ ENTRY(\label)
22006 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
22007 call \func
22008 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
22009+ pax_force_retaddr
22010 ret
22011 CFI_ENDPROC
22012-END(\label)
22013+ENDPROC(\label)
22014 .endm
22015
22016 FORK_LIKE clone
22017@@ -870,9 +1327,10 @@ ENTRY(ptregscall_common)
22018 movq_cfi_restore R12+8, r12
22019 movq_cfi_restore RBP+8, rbp
22020 movq_cfi_restore RBX+8, rbx
22021+ pax_force_retaddr
22022 ret $REST_SKIP /* pop extended registers */
22023 CFI_ENDPROC
22024-END(ptregscall_common)
22025+ENDPROC(ptregscall_common)
22026
22027 ENTRY(stub_execve)
22028 CFI_STARTPROC
22029@@ -885,7 +1343,7 @@ ENTRY(stub_execve)
22030 RESTORE_REST
22031 jmp int_ret_from_sys_call
22032 CFI_ENDPROC
22033-END(stub_execve)
22034+ENDPROC(stub_execve)
22035
22036 /*
22037 * sigreturn is special because it needs to restore all registers on return.
22038@@ -902,7 +1360,7 @@ ENTRY(stub_rt_sigreturn)
22039 RESTORE_REST
22040 jmp int_ret_from_sys_call
22041 CFI_ENDPROC
22042-END(stub_rt_sigreturn)
22043+ENDPROC(stub_rt_sigreturn)
22044
22045 #ifdef CONFIG_X86_X32_ABI
22046 ENTRY(stub_x32_rt_sigreturn)
22047@@ -916,7 +1374,7 @@ ENTRY(stub_x32_rt_sigreturn)
22048 RESTORE_REST
22049 jmp int_ret_from_sys_call
22050 CFI_ENDPROC
22051-END(stub_x32_rt_sigreturn)
22052+ENDPROC(stub_x32_rt_sigreturn)
22053
22054 ENTRY(stub_x32_execve)
22055 CFI_STARTPROC
22056@@ -930,7 +1388,7 @@ ENTRY(stub_x32_execve)
22057 RESTORE_REST
22058 jmp int_ret_from_sys_call
22059 CFI_ENDPROC
22060-END(stub_x32_execve)
22061+ENDPROC(stub_x32_execve)
22062
22063 #endif
22064
22065@@ -967,7 +1425,7 @@ vector=vector+1
22066 2: jmp common_interrupt
22067 .endr
22068 CFI_ENDPROC
22069-END(irq_entries_start)
22070+ENDPROC(irq_entries_start)
22071
22072 .previous
22073 END(interrupt)
22074@@ -987,6 +1445,16 @@ END(interrupt)
22075 subq $ORIG_RAX-RBP, %rsp
22076 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
22077 SAVE_ARGS_IRQ
22078+#ifdef CONFIG_PAX_MEMORY_UDEREF
22079+ testb $3, CS(%rdi)
22080+ jnz 1f
22081+ pax_enter_kernel
22082+ jmp 2f
22083+1: pax_enter_kernel_user
22084+2:
22085+#else
22086+ pax_enter_kernel
22087+#endif
22088 call \func
22089 .endm
22090
22091@@ -1019,7 +1487,7 @@ ret_from_intr:
22092
22093 exit_intr:
22094 GET_THREAD_INFO(%rcx)
22095- testl $3,CS-ARGOFFSET(%rsp)
22096+ testb $3,CS-ARGOFFSET(%rsp)
22097 je retint_kernel
22098
22099 /* Interrupt came from user space */
22100@@ -1041,12 +1509,16 @@ retint_swapgs: /* return to user-space */
22101 * The iretq could re-enable interrupts:
22102 */
22103 DISABLE_INTERRUPTS(CLBR_ANY)
22104+ pax_exit_kernel_user
22105+retint_swapgs_pax:
22106 TRACE_IRQS_IRETQ
22107 SWAPGS
22108 jmp restore_args
22109
22110 retint_restore_args: /* return to kernel space */
22111 DISABLE_INTERRUPTS(CLBR_ANY)
22112+ pax_exit_kernel
22113+ pax_force_retaddr (RIP-ARGOFFSET)
22114 /*
22115 * The iretq could re-enable interrupts:
22116 */
22117@@ -1129,7 +1601,7 @@ ENTRY(retint_kernel)
22118 #endif
22119
22120 CFI_ENDPROC
22121-END(common_interrupt)
22122+ENDPROC(common_interrupt)
22123 /*
22124 * End of kprobes section
22125 */
22126@@ -1147,7 +1619,7 @@ ENTRY(\sym)
22127 interrupt \do_sym
22128 jmp ret_from_intr
22129 CFI_ENDPROC
22130-END(\sym)
22131+ENDPROC(\sym)
22132 .endm
22133
22134 #ifdef CONFIG_TRACING
22135@@ -1230,12 +1702,22 @@ ENTRY(\sym)
22136 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22137 call error_entry
22138 DEFAULT_FRAME 0
22139+#ifdef CONFIG_PAX_MEMORY_UDEREF
22140+ testb $3, CS(%rsp)
22141+ jnz 1f
22142+ pax_enter_kernel
22143+ jmp 2f
22144+1: pax_enter_kernel_user
22145+2:
22146+#else
22147+ pax_enter_kernel
22148+#endif
22149 movq %rsp,%rdi /* pt_regs pointer */
22150 xorl %esi,%esi /* no error code */
22151 call \do_sym
22152 jmp error_exit /* %ebx: no swapgs flag */
22153 CFI_ENDPROC
22154-END(\sym)
22155+ENDPROC(\sym)
22156 .endm
22157
22158 .macro paranoidzeroentry sym do_sym
22159@@ -1248,15 +1730,25 @@ ENTRY(\sym)
22160 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22161 call save_paranoid
22162 TRACE_IRQS_OFF
22163+#ifdef CONFIG_PAX_MEMORY_UDEREF
22164+ testb $3, CS(%rsp)
22165+ jnz 1f
22166+ pax_enter_kernel
22167+ jmp 2f
22168+1: pax_enter_kernel_user
22169+2:
22170+#else
22171+ pax_enter_kernel
22172+#endif
22173 movq %rsp,%rdi /* pt_regs pointer */
22174 xorl %esi,%esi /* no error code */
22175 call \do_sym
22176 jmp paranoid_exit /* %ebx: no swapgs flag */
22177 CFI_ENDPROC
22178-END(\sym)
22179+ENDPROC(\sym)
22180 .endm
22181
22182-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
22183+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
22184 .macro paranoidzeroentry_ist sym do_sym ist
22185 ENTRY(\sym)
22186 INTR_FRAME
22187@@ -1267,14 +1759,30 @@ ENTRY(\sym)
22188 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22189 call save_paranoid
22190 TRACE_IRQS_OFF_DEBUG
22191+#ifdef CONFIG_PAX_MEMORY_UDEREF
22192+ testb $3, CS(%rsp)
22193+ jnz 1f
22194+ pax_enter_kernel
22195+ jmp 2f
22196+1: pax_enter_kernel_user
22197+2:
22198+#else
22199+ pax_enter_kernel
22200+#endif
22201 movq %rsp,%rdi /* pt_regs pointer */
22202 xorl %esi,%esi /* no error code */
22203+#ifdef CONFIG_SMP
22204+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
22205+ lea init_tss(%r12), %r12
22206+#else
22207+ lea init_tss(%rip), %r12
22208+#endif
22209 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
22210 call \do_sym
22211 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
22212 jmp paranoid_exit /* %ebx: no swapgs flag */
22213 CFI_ENDPROC
22214-END(\sym)
22215+ENDPROC(\sym)
22216 .endm
22217
22218 .macro errorentry sym do_sym
22219@@ -1286,13 +1794,23 @@ ENTRY(\sym)
22220 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
22221 call error_entry
22222 DEFAULT_FRAME 0
22223+#ifdef CONFIG_PAX_MEMORY_UDEREF
22224+ testb $3, CS(%rsp)
22225+ jnz 1f
22226+ pax_enter_kernel
22227+ jmp 2f
22228+1: pax_enter_kernel_user
22229+2:
22230+#else
22231+ pax_enter_kernel
22232+#endif
22233 movq %rsp,%rdi /* pt_regs pointer */
22234 movq ORIG_RAX(%rsp),%rsi /* get error code */
22235 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
22236 call \do_sym
22237 jmp error_exit /* %ebx: no swapgs flag */
22238 CFI_ENDPROC
22239-END(\sym)
22240+ENDPROC(\sym)
22241 .endm
22242
22243 /* error code is on the stack already */
22244@@ -1306,13 +1824,23 @@ ENTRY(\sym)
22245 call save_paranoid
22246 DEFAULT_FRAME 0
22247 TRACE_IRQS_OFF
22248+#ifdef CONFIG_PAX_MEMORY_UDEREF
22249+ testb $3, CS(%rsp)
22250+ jnz 1f
22251+ pax_enter_kernel
22252+ jmp 2f
22253+1: pax_enter_kernel_user
22254+2:
22255+#else
22256+ pax_enter_kernel
22257+#endif
22258 movq %rsp,%rdi /* pt_regs pointer */
22259 movq ORIG_RAX(%rsp),%rsi /* get error code */
22260 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
22261 call \do_sym
22262 jmp paranoid_exit /* %ebx: no swapgs flag */
22263 CFI_ENDPROC
22264-END(\sym)
22265+ENDPROC(\sym)
22266 .endm
22267
22268 zeroentry divide_error do_divide_error
22269@@ -1342,9 +1870,10 @@ gs_change:
22270 2: mfence /* workaround */
22271 SWAPGS
22272 popfq_cfi
22273+ pax_force_retaddr
22274 ret
22275 CFI_ENDPROC
22276-END(native_load_gs_index)
22277+ENDPROC(native_load_gs_index)
22278
22279 _ASM_EXTABLE(gs_change,bad_gs)
22280 .section .fixup,"ax"
22281@@ -1372,9 +1901,10 @@ ENTRY(call_softirq)
22282 CFI_DEF_CFA_REGISTER rsp
22283 CFI_ADJUST_CFA_OFFSET -8
22284 decl PER_CPU_VAR(irq_count)
22285+ pax_force_retaddr
22286 ret
22287 CFI_ENDPROC
22288-END(call_softirq)
22289+ENDPROC(call_softirq)
22290
22291 #ifdef CONFIG_XEN
22292 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
22293@@ -1412,7 +1942,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
22294 decl PER_CPU_VAR(irq_count)
22295 jmp error_exit
22296 CFI_ENDPROC
22297-END(xen_do_hypervisor_callback)
22298+ENDPROC(xen_do_hypervisor_callback)
22299
22300 /*
22301 * Hypervisor uses this for application faults while it executes.
22302@@ -1471,7 +2001,7 @@ ENTRY(xen_failsafe_callback)
22303 SAVE_ALL
22304 jmp error_exit
22305 CFI_ENDPROC
22306-END(xen_failsafe_callback)
22307+ENDPROC(xen_failsafe_callback)
22308
22309 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
22310 xen_hvm_callback_vector xen_evtchn_do_upcall
22311@@ -1523,18 +2053,33 @@ ENTRY(paranoid_exit)
22312 DEFAULT_FRAME
22313 DISABLE_INTERRUPTS(CLBR_NONE)
22314 TRACE_IRQS_OFF_DEBUG
22315- testl %ebx,%ebx /* swapgs needed? */
22316+ testl $1,%ebx /* swapgs needed? */
22317 jnz paranoid_restore
22318- testl $3,CS(%rsp)
22319+ testb $3,CS(%rsp)
22320 jnz paranoid_userspace
22321+#ifdef CONFIG_PAX_MEMORY_UDEREF
22322+ pax_exit_kernel
22323+ TRACE_IRQS_IRETQ 0
22324+ SWAPGS_UNSAFE_STACK
22325+ RESTORE_ALL 8
22326+ pax_force_retaddr_bts
22327+ jmp irq_return
22328+#endif
22329 paranoid_swapgs:
22330+#ifdef CONFIG_PAX_MEMORY_UDEREF
22331+ pax_exit_kernel_user
22332+#else
22333+ pax_exit_kernel
22334+#endif
22335 TRACE_IRQS_IRETQ 0
22336 SWAPGS_UNSAFE_STACK
22337 RESTORE_ALL 8
22338 jmp irq_return
22339 paranoid_restore:
22340+ pax_exit_kernel
22341 TRACE_IRQS_IRETQ_DEBUG 0
22342 RESTORE_ALL 8
22343+ pax_force_retaddr_bts
22344 jmp irq_return
22345 paranoid_userspace:
22346 GET_THREAD_INFO(%rcx)
22347@@ -1563,7 +2108,7 @@ paranoid_schedule:
22348 TRACE_IRQS_OFF
22349 jmp paranoid_userspace
22350 CFI_ENDPROC
22351-END(paranoid_exit)
22352+ENDPROC(paranoid_exit)
22353
22354 /*
22355 * Exception entry point. This expects an error code/orig_rax on the stack.
22356@@ -1590,12 +2135,13 @@ ENTRY(error_entry)
22357 movq_cfi r14, R14+8
22358 movq_cfi r15, R15+8
22359 xorl %ebx,%ebx
22360- testl $3,CS+8(%rsp)
22361+ testb $3,CS+8(%rsp)
22362 je error_kernelspace
22363 error_swapgs:
22364 SWAPGS
22365 error_sti:
22366 TRACE_IRQS_OFF
22367+ pax_force_retaddr_bts
22368 ret
22369
22370 /*
22371@@ -1622,7 +2168,7 @@ bstep_iret:
22372 movq %rcx,RIP+8(%rsp)
22373 jmp error_swapgs
22374 CFI_ENDPROC
22375-END(error_entry)
22376+ENDPROC(error_entry)
22377
22378
22379 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
22380@@ -1633,7 +2179,7 @@ ENTRY(error_exit)
22381 DISABLE_INTERRUPTS(CLBR_NONE)
22382 TRACE_IRQS_OFF
22383 GET_THREAD_INFO(%rcx)
22384- testl %eax,%eax
22385+ testl $1,%eax
22386 jne retint_kernel
22387 LOCKDEP_SYS_EXIT_IRQ
22388 movl TI_flags(%rcx),%edx
22389@@ -1642,7 +2188,7 @@ ENTRY(error_exit)
22390 jnz retint_careful
22391 jmp retint_swapgs
22392 CFI_ENDPROC
22393-END(error_exit)
22394+ENDPROC(error_exit)
22395
22396 /*
22397 * Test if a given stack is an NMI stack or not.
22398@@ -1700,9 +2246,11 @@ ENTRY(nmi)
22399 * If %cs was not the kernel segment, then the NMI triggered in user
22400 * space, which means it is definitely not nested.
22401 */
22402+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
22403+ je 1f
22404 cmpl $__KERNEL_CS, 16(%rsp)
22405 jne first_nmi
22406-
22407+1:
22408 /*
22409 * Check the special variable on the stack to see if NMIs are
22410 * executing.
22411@@ -1736,8 +2284,7 @@ nested_nmi:
22412
22413 1:
22414 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
22415- leaq -1*8(%rsp), %rdx
22416- movq %rdx, %rsp
22417+ subq $8, %rsp
22418 CFI_ADJUST_CFA_OFFSET 1*8
22419 leaq -10*8(%rsp), %rdx
22420 pushq_cfi $__KERNEL_DS
22421@@ -1755,6 +2302,7 @@ nested_nmi_out:
22422 CFI_RESTORE rdx
22423
22424 /* No need to check faults here */
22425+# pax_force_retaddr_bts
22426 INTERRUPT_RETURN
22427
22428 CFI_RESTORE_STATE
22429@@ -1871,6 +2419,8 @@ end_repeat_nmi:
22430 */
22431 movq %cr2, %r12
22432
22433+ pax_enter_kernel_nmi
22434+
22435 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
22436 movq %rsp,%rdi
22437 movq $-1,%rsi
22438@@ -1883,26 +2433,31 @@ end_repeat_nmi:
22439 movq %r12, %cr2
22440 1:
22441
22442- testl %ebx,%ebx /* swapgs needed? */
22443+ testl $1,%ebx /* swapgs needed? */
22444 jnz nmi_restore
22445 nmi_swapgs:
22446 SWAPGS_UNSAFE_STACK
22447 nmi_restore:
22448+ pax_exit_kernel_nmi
22449 /* Pop the extra iret frame at once */
22450 RESTORE_ALL 6*8
22451+ testb $3, 8(%rsp)
22452+ jnz 1f
22453+ pax_force_retaddr_bts
22454+1:
22455
22456 /* Clear the NMI executing stack variable */
22457 movq $0, 5*8(%rsp)
22458 jmp irq_return
22459 CFI_ENDPROC
22460-END(nmi)
22461+ENDPROC(nmi)
22462
22463 ENTRY(ignore_sysret)
22464 CFI_STARTPROC
22465 mov $-ENOSYS,%eax
22466 sysret
22467 CFI_ENDPROC
22468-END(ignore_sysret)
22469+ENDPROC(ignore_sysret)
22470
22471 /*
22472 * End of kprobes section
22473diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
22474index 42a392a..fbbd930 100644
22475--- a/arch/x86/kernel/ftrace.c
22476+++ b/arch/x86/kernel/ftrace.c
22477@@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
22478 {
22479 unsigned char replaced[MCOUNT_INSN_SIZE];
22480
22481+ ip = ktla_ktva(ip);
22482+
22483 /*
22484 * Note: Due to modules and __init, code can
22485 * disappear and change, we need to protect against faulting
22486@@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
22487 unsigned char old[MCOUNT_INSN_SIZE], *new;
22488 int ret;
22489
22490- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
22491+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
22492 new = ftrace_call_replace(ip, (unsigned long)func);
22493
22494 /* See comment above by declaration of modifying_ftrace_code */
22495@@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
22496 /* Also update the regs callback function */
22497 if (!ret) {
22498 ip = (unsigned long)(&ftrace_regs_call);
22499- memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
22500+ memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
22501 new = ftrace_call_replace(ip, (unsigned long)func);
22502 ret = ftrace_modify_code(ip, old, new);
22503 }
22504@@ -279,7 +281,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
22505 * kernel identity mapping to modify code.
22506 */
22507 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
22508- ip = (unsigned long)__va(__pa_symbol(ip));
22509+ ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
22510
22511 return probe_kernel_write((void *)ip, val, size);
22512 }
22513@@ -289,7 +291,7 @@ static int add_break(unsigned long ip, const char *old)
22514 unsigned char replaced[MCOUNT_INSN_SIZE];
22515 unsigned char brk = BREAKPOINT_INSTRUCTION;
22516
22517- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
22518+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
22519 return -EFAULT;
22520
22521 /* Make sure it is what we expect it to be */
22522@@ -637,7 +639,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
22523 return ret;
22524
22525 fail_update:
22526- probe_kernel_write((void *)ip, &old_code[0], 1);
22527+ probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
22528 goto out;
22529 }
22530
22531@@ -670,6 +672,8 @@ static int ftrace_mod_jmp(unsigned long ip,
22532 {
22533 unsigned char code[MCOUNT_INSN_SIZE];
22534
22535+ ip = ktla_ktva(ip);
22536+
22537 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
22538 return -EFAULT;
22539
22540diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
22541index 55b6761..a6456fc 100644
22542--- a/arch/x86/kernel/head64.c
22543+++ b/arch/x86/kernel/head64.c
22544@@ -67,12 +67,12 @@ again:
22545 pgd = *pgd_p;
22546
22547 /*
22548- * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
22549- * critical -- __PAGE_OFFSET would point us back into the dynamic
22550+ * The use of __early_va rather than __va here is critical:
22551+ * __va would point us back into the dynamic
22552 * range and we might end up looping forever...
22553 */
22554 if (pgd)
22555- pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
22556+ pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
22557 else {
22558 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
22559 reset_early_page_tables();
22560@@ -82,13 +82,13 @@ again:
22561 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
22562 for (i = 0; i < PTRS_PER_PUD; i++)
22563 pud_p[i] = 0;
22564- *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
22565+ *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
22566 }
22567 pud_p += pud_index(address);
22568 pud = *pud_p;
22569
22570 if (pud)
22571- pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
22572+ pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
22573 else {
22574 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
22575 reset_early_page_tables();
22576@@ -98,7 +98,7 @@ again:
22577 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
22578 for (i = 0; i < PTRS_PER_PMD; i++)
22579 pmd_p[i] = 0;
22580- *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
22581+ *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
22582 }
22583 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
22584 pmd_p[pmd_index(address)] = pmd;
22585@@ -175,7 +175,6 @@ void __init x86_64_start_kernel(char * real_mode_data)
22586 if (console_loglevel == 10)
22587 early_printk("Kernel alive\n");
22588
22589- clear_page(init_level4_pgt);
22590 /* set init_level4_pgt kernel high mapping*/
22591 init_level4_pgt[511] = early_level4_pgt[511];
22592
22593diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
22594index 5dd87a8..d68b3f4 100644
22595--- a/arch/x86/kernel/head_32.S
22596+++ b/arch/x86/kernel/head_32.S
22597@@ -26,6 +26,12 @@
22598 /* Physical address */
22599 #define pa(X) ((X) - __PAGE_OFFSET)
22600
22601+#ifdef CONFIG_PAX_KERNEXEC
22602+#define ta(X) (X)
22603+#else
22604+#define ta(X) ((X) - __PAGE_OFFSET)
22605+#endif
22606+
22607 /*
22608 * References to members of the new_cpu_data structure.
22609 */
22610@@ -55,11 +61,7 @@
22611 * and small than max_low_pfn, otherwise will waste some page table entries
22612 */
22613
22614-#if PTRS_PER_PMD > 1
22615-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
22616-#else
22617-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
22618-#endif
22619+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
22620
22621 /* Number of possible pages in the lowmem region */
22622 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
22623@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
22624 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
22625
22626 /*
22627+ * Real beginning of normal "text" segment
22628+ */
22629+ENTRY(stext)
22630+ENTRY(_stext)
22631+
22632+/*
22633 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
22634 * %esi points to the real-mode code as a 32-bit pointer.
22635 * CS and DS must be 4 GB flat segments, but we don't depend on
22636@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
22637 * can.
22638 */
22639 __HEAD
22640+
22641+#ifdef CONFIG_PAX_KERNEXEC
22642+ jmp startup_32
22643+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
22644+.fill PAGE_SIZE-5,1,0xcc
22645+#endif
22646+
22647 ENTRY(startup_32)
22648 movl pa(stack_start),%ecx
22649
22650@@ -106,6 +121,59 @@ ENTRY(startup_32)
22651 2:
22652 leal -__PAGE_OFFSET(%ecx),%esp
22653
22654+#ifdef CONFIG_SMP
22655+ movl $pa(cpu_gdt_table),%edi
22656+ movl $__per_cpu_load,%eax
22657+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
22658+ rorl $16,%eax
22659+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
22660+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
22661+ movl $__per_cpu_end - 1,%eax
22662+ subl $__per_cpu_start,%eax
22663+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
22664+#endif
22665+
22666+#ifdef CONFIG_PAX_MEMORY_UDEREF
22667+ movl $NR_CPUS,%ecx
22668+ movl $pa(cpu_gdt_table),%edi
22669+1:
22670+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
22671+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
22672+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
22673+ addl $PAGE_SIZE_asm,%edi
22674+ loop 1b
22675+#endif
22676+
22677+#ifdef CONFIG_PAX_KERNEXEC
22678+ movl $pa(boot_gdt),%edi
22679+ movl $__LOAD_PHYSICAL_ADDR,%eax
22680+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
22681+ rorl $16,%eax
22682+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
22683+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
22684+ rorl $16,%eax
22685+
22686+ ljmp $(__BOOT_CS),$1f
22687+1:
22688+
22689+ movl $NR_CPUS,%ecx
22690+ movl $pa(cpu_gdt_table),%edi
22691+ addl $__PAGE_OFFSET,%eax
22692+1:
22693+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
22694+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
22695+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
22696+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
22697+ rorl $16,%eax
22698+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
22699+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
22700+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
22701+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
22702+ rorl $16,%eax
22703+ addl $PAGE_SIZE_asm,%edi
22704+ loop 1b
22705+#endif
22706+
22707 /*
22708 * Clear BSS first so that there are no surprises...
22709 */
22710@@ -201,8 +269,11 @@ ENTRY(startup_32)
22711 movl %eax, pa(max_pfn_mapped)
22712
22713 /* Do early initialization of the fixmap area */
22714- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
22715- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
22716+#ifdef CONFIG_COMPAT_VDSO
22717+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
22718+#else
22719+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
22720+#endif
22721 #else /* Not PAE */
22722
22723 page_pde_offset = (__PAGE_OFFSET >> 20);
22724@@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
22725 movl %eax, pa(max_pfn_mapped)
22726
22727 /* Do early initialization of the fixmap area */
22728- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
22729- movl %eax,pa(initial_page_table+0xffc)
22730+#ifdef CONFIG_COMPAT_VDSO
22731+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
22732+#else
22733+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
22734+#endif
22735 #endif
22736
22737 #ifdef CONFIG_PARAVIRT
22738@@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
22739 cmpl $num_subarch_entries, %eax
22740 jae bad_subarch
22741
22742- movl pa(subarch_entries)(,%eax,4), %eax
22743- subl $__PAGE_OFFSET, %eax
22744- jmp *%eax
22745+ jmp *pa(subarch_entries)(,%eax,4)
22746
22747 bad_subarch:
22748 WEAK(lguest_entry)
22749@@ -261,10 +333,10 @@ WEAK(xen_entry)
22750 __INITDATA
22751
22752 subarch_entries:
22753- .long default_entry /* normal x86/PC */
22754- .long lguest_entry /* lguest hypervisor */
22755- .long xen_entry /* Xen hypervisor */
22756- .long default_entry /* Moorestown MID */
22757+ .long ta(default_entry) /* normal x86/PC */
22758+ .long ta(lguest_entry) /* lguest hypervisor */
22759+ .long ta(xen_entry) /* Xen hypervisor */
22760+ .long ta(default_entry) /* Moorestown MID */
22761 num_subarch_entries = (. - subarch_entries) / 4
22762 .previous
22763 #else
22764@@ -354,6 +426,7 @@ default_entry:
22765 movl pa(mmu_cr4_features),%eax
22766 movl %eax,%cr4
22767
22768+#ifdef CONFIG_X86_PAE
22769 testb $X86_CR4_PAE, %al # check if PAE is enabled
22770 jz enable_paging
22771
22772@@ -382,6 +455,9 @@ default_entry:
22773 /* Make changes effective */
22774 wrmsr
22775
22776+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
22777+#endif
22778+
22779 enable_paging:
22780
22781 /*
22782@@ -449,14 +525,20 @@ is486:
22783 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
22784 movl %eax,%ss # after changing gdt.
22785
22786- movl $(__USER_DS),%eax # DS/ES contains default USER segment
22787+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
22788 movl %eax,%ds
22789 movl %eax,%es
22790
22791 movl $(__KERNEL_PERCPU), %eax
22792 movl %eax,%fs # set this cpu's percpu
22793
22794+#ifdef CONFIG_CC_STACKPROTECTOR
22795 movl $(__KERNEL_STACK_CANARY),%eax
22796+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
22797+ movl $(__USER_DS),%eax
22798+#else
22799+ xorl %eax,%eax
22800+#endif
22801 movl %eax,%gs
22802
22803 xorl %eax,%eax # Clear LDT
22804@@ -512,8 +594,11 @@ setup_once:
22805 * relocation. Manually set base address in stack canary
22806 * segment descriptor.
22807 */
22808- movl $gdt_page,%eax
22809+ movl $cpu_gdt_table,%eax
22810 movl $stack_canary,%ecx
22811+#ifdef CONFIG_SMP
22812+ addl $__per_cpu_load,%ecx
22813+#endif
22814 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
22815 shrl $16, %ecx
22816 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
22817@@ -544,7 +629,7 @@ ENDPROC(early_idt_handlers)
22818 /* This is global to keep gas from relaxing the jumps */
22819 ENTRY(early_idt_handler)
22820 cld
22821- cmpl $2,%ss:early_recursion_flag
22822+ cmpl $1,%ss:early_recursion_flag
22823 je hlt_loop
22824 incl %ss:early_recursion_flag
22825
22826@@ -582,8 +667,8 @@ ENTRY(early_idt_handler)
22827 pushl (20+6*4)(%esp) /* trapno */
22828 pushl $fault_msg
22829 call printk
22830-#endif
22831 call dump_stack
22832+#endif
22833 hlt_loop:
22834 hlt
22835 jmp hlt_loop
22836@@ -602,8 +687,11 @@ ENDPROC(early_idt_handler)
22837 /* This is the default interrupt "handler" :-) */
22838 ALIGN
22839 ignore_int:
22840- cld
22841 #ifdef CONFIG_PRINTK
22842+ cmpl $2,%ss:early_recursion_flag
22843+ je hlt_loop
22844+ incl %ss:early_recursion_flag
22845+ cld
22846 pushl %eax
22847 pushl %ecx
22848 pushl %edx
22849@@ -612,9 +700,6 @@ ignore_int:
22850 movl $(__KERNEL_DS),%eax
22851 movl %eax,%ds
22852 movl %eax,%es
22853- cmpl $2,early_recursion_flag
22854- je hlt_loop
22855- incl early_recursion_flag
22856 pushl 16(%esp)
22857 pushl 24(%esp)
22858 pushl 32(%esp)
22859@@ -648,29 +733,34 @@ ENTRY(setup_once_ref)
22860 /*
22861 * BSS section
22862 */
22863-__PAGE_ALIGNED_BSS
22864- .align PAGE_SIZE
22865 #ifdef CONFIG_X86_PAE
22866+.section .initial_pg_pmd,"a",@progbits
22867 initial_pg_pmd:
22868 .fill 1024*KPMDS,4,0
22869 #else
22870+.section .initial_page_table,"a",@progbits
22871 ENTRY(initial_page_table)
22872 .fill 1024,4,0
22873 #endif
22874+.section .initial_pg_fixmap,"a",@progbits
22875 initial_pg_fixmap:
22876 .fill 1024,4,0
22877+.section .empty_zero_page,"a",@progbits
22878 ENTRY(empty_zero_page)
22879 .fill 4096,1,0
22880+.section .swapper_pg_dir,"a",@progbits
22881 ENTRY(swapper_pg_dir)
22882+#ifdef CONFIG_X86_PAE
22883+ .fill 4,8,0
22884+#else
22885 .fill 1024,4,0
22886+#endif
22887
22888 /*
22889 * This starts the data section.
22890 */
22891 #ifdef CONFIG_X86_PAE
22892-__PAGE_ALIGNED_DATA
22893- /* Page-aligned for the benefit of paravirt? */
22894- .align PAGE_SIZE
22895+.section .initial_page_table,"a",@progbits
22896 ENTRY(initial_page_table)
22897 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
22898 # if KPMDS == 3
22899@@ -689,12 +779,20 @@ ENTRY(initial_page_table)
22900 # error "Kernel PMDs should be 1, 2 or 3"
22901 # endif
22902 .align PAGE_SIZE /* needs to be page-sized too */
22903+
22904+#ifdef CONFIG_PAX_PER_CPU_PGD
22905+ENTRY(cpu_pgd)
22906+ .rept 2*NR_CPUS
22907+ .fill 4,8,0
22908+ .endr
22909+#endif
22910+
22911 #endif
22912
22913 .data
22914 .balign 4
22915 ENTRY(stack_start)
22916- .long init_thread_union+THREAD_SIZE
22917+ .long init_thread_union+THREAD_SIZE-8
22918
22919 __INITRODATA
22920 int_msg:
22921@@ -722,7 +820,7 @@ fault_msg:
22922 * segment size, and 32-bit linear address value:
22923 */
22924
22925- .data
22926+.section .rodata,"a",@progbits
22927 .globl boot_gdt_descr
22928 .globl idt_descr
22929
22930@@ -731,7 +829,7 @@ fault_msg:
22931 .word 0 # 32 bit align gdt_desc.address
22932 boot_gdt_descr:
22933 .word __BOOT_DS+7
22934- .long boot_gdt - __PAGE_OFFSET
22935+ .long pa(boot_gdt)
22936
22937 .word 0 # 32-bit align idt_desc.address
22938 idt_descr:
22939@@ -742,7 +840,7 @@ idt_descr:
22940 .word 0 # 32 bit align gdt_desc.address
22941 ENTRY(early_gdt_descr)
22942 .word GDT_ENTRIES*8-1
22943- .long gdt_page /* Overwritten for secondary CPUs */
22944+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
22945
22946 /*
22947 * The boot_gdt must mirror the equivalent in setup.S and is
22948@@ -751,5 +849,65 @@ ENTRY(early_gdt_descr)
22949 .align L1_CACHE_BYTES
22950 ENTRY(boot_gdt)
22951 .fill GDT_ENTRY_BOOT_CS,8,0
22952- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
22953- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
22954+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
22955+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
22956+
22957+ .align PAGE_SIZE_asm
22958+ENTRY(cpu_gdt_table)
22959+ .rept NR_CPUS
22960+ .quad 0x0000000000000000 /* NULL descriptor */
22961+ .quad 0x0000000000000000 /* 0x0b reserved */
22962+ .quad 0x0000000000000000 /* 0x13 reserved */
22963+ .quad 0x0000000000000000 /* 0x1b reserved */
22964+
22965+#ifdef CONFIG_PAX_KERNEXEC
22966+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
22967+#else
22968+ .quad 0x0000000000000000 /* 0x20 unused */
22969+#endif
22970+
22971+ .quad 0x0000000000000000 /* 0x28 unused */
22972+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
22973+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
22974+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
22975+ .quad 0x0000000000000000 /* 0x4b reserved */
22976+ .quad 0x0000000000000000 /* 0x53 reserved */
22977+ .quad 0x0000000000000000 /* 0x5b reserved */
22978+
22979+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
22980+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
22981+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
22982+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
22983+
22984+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
22985+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
22986+
22987+ /*
22988+ * Segments used for calling PnP BIOS have byte granularity.
22989+ * The code segments and data segments have fixed 64k limits,
22990+ * the transfer segment sizes are set at run time.
22991+ */
22992+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
22993+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
22994+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
22995+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
22996+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
22997+
22998+ /*
22999+ * The APM segments have byte granularity and their bases
23000+ * are set at run time. All have 64k limits.
23001+ */
23002+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
23003+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
23004+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
23005+
23006+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
23007+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
23008+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
23009+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
23010+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
23011+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
23012+
23013+ /* Be sure this is zeroed to avoid false validations in Xen */
23014+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
23015+ .endr
23016diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
23017index e1aabdb..73dcad8 100644
23018--- a/arch/x86/kernel/head_64.S
23019+++ b/arch/x86/kernel/head_64.S
23020@@ -20,6 +20,8 @@
23021 #include <asm/processor-flags.h>
23022 #include <asm/percpu.h>
23023 #include <asm/nops.h>
23024+#include <asm/cpufeature.h>
23025+#include <asm/alternative-asm.h>
23026
23027 #ifdef CONFIG_PARAVIRT
23028 #include <asm/asm-offsets.h>
23029@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
23030 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
23031 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
23032 L3_START_KERNEL = pud_index(__START_KERNEL_map)
23033+L4_VMALLOC_START = pgd_index(VMALLOC_START)
23034+L3_VMALLOC_START = pud_index(VMALLOC_START)
23035+L4_VMALLOC_END = pgd_index(VMALLOC_END)
23036+L3_VMALLOC_END = pud_index(VMALLOC_END)
23037+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
23038+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
23039
23040 .text
23041 __HEAD
23042@@ -89,11 +97,23 @@ startup_64:
23043 * Fixup the physical addresses in the page table
23044 */
23045 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
23046+ addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
23047+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
23048+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
23049+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
23050+ addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
23051
23052- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
23053- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
23054+ addq %rbp, level3_ident_pgt + (0*8)(%rip)
23055+#ifndef CONFIG_XEN
23056+ addq %rbp, level3_ident_pgt + (1*8)(%rip)
23057+#endif
23058
23059- addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
23060+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
23061+
23062+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
23063+ addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
23064+
23065+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
23066
23067 /*
23068 * Set up the identity mapping for the switchover. These
23069@@ -177,8 +197,8 @@ ENTRY(secondary_startup_64)
23070 movq $(init_level4_pgt - __START_KERNEL_map), %rax
23071 1:
23072
23073- /* Enable PAE mode and PGE */
23074- movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
23075+ /* Enable PAE mode and PSE/PGE */
23076+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
23077 movq %rcx, %cr4
23078
23079 /* Setup early boot stage 4 level pagetables. */
23080@@ -199,10 +219,18 @@ ENTRY(secondary_startup_64)
23081 movl $MSR_EFER, %ecx
23082 rdmsr
23083 btsl $_EFER_SCE, %eax /* Enable System Call */
23084- btl $20,%edi /* No Execute supported? */
23085+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
23086 jnc 1f
23087 btsl $_EFER_NX, %eax
23088 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
23089+ leaq init_level4_pgt(%rip), %rdi
23090+#ifndef CONFIG_EFI
23091+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
23092+#endif
23093+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
23094+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
23095+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
23096+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
23097 1: wrmsr /* Make changes effective */
23098
23099 /* Setup cr0 */
23100@@ -282,6 +310,7 @@ ENTRY(secondary_startup_64)
23101 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
23102 * address given in m16:64.
23103 */
23104+ pax_set_fptr_mask
23105 movq initial_code(%rip),%rax
23106 pushq $0 # fake return address to stop unwinder
23107 pushq $__KERNEL_CS # set correct cs
23108@@ -388,7 +417,7 @@ ENTRY(early_idt_handler)
23109 call dump_stack
23110 #ifdef CONFIG_KALLSYMS
23111 leaq early_idt_ripmsg(%rip),%rdi
23112- movq 40(%rsp),%rsi # %rip again
23113+ movq 88(%rsp),%rsi # %rip again
23114 call __print_symbol
23115 #endif
23116 #endif /* EARLY_PRINTK */
23117@@ -416,6 +445,7 @@ ENDPROC(early_idt_handler)
23118 early_recursion_flag:
23119 .long 0
23120
23121+ .section .rodata,"a",@progbits
23122 #ifdef CONFIG_EARLY_PRINTK
23123 early_idt_msg:
23124 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
23125@@ -443,29 +473,52 @@ NEXT_PAGE(early_level4_pgt)
23126 NEXT_PAGE(early_dynamic_pgts)
23127 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
23128
23129- .data
23130+ .section .rodata,"a",@progbits
23131
23132-#ifndef CONFIG_XEN
23133 NEXT_PAGE(init_level4_pgt)
23134- .fill 512,8,0
23135-#else
23136-NEXT_PAGE(init_level4_pgt)
23137- .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
23138 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
23139 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
23140+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
23141+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
23142+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
23143+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
23144+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
23145+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
23146 .org init_level4_pgt + L4_START_KERNEL*8, 0
23147 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
23148 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
23149
23150+#ifdef CONFIG_PAX_PER_CPU_PGD
23151+NEXT_PAGE(cpu_pgd)
23152+ .rept 2*NR_CPUS
23153+ .fill 512,8,0
23154+ .endr
23155+#endif
23156+
23157 NEXT_PAGE(level3_ident_pgt)
23158 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
23159+#ifdef CONFIG_XEN
23160 .fill 511, 8, 0
23161+#else
23162+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
23163+ .fill 510,8,0
23164+#endif
23165+
23166+NEXT_PAGE(level3_vmalloc_start_pgt)
23167+ .fill 512,8,0
23168+
23169+NEXT_PAGE(level3_vmalloc_end_pgt)
23170+ .fill 512,8,0
23171+
23172+NEXT_PAGE(level3_vmemmap_pgt)
23173+ .fill L3_VMEMMAP_START,8,0
23174+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
23175+
23176 NEXT_PAGE(level2_ident_pgt)
23177- /* Since I easily can, map the first 1G.
23178+ /* Since I easily can, map the first 2G.
23179 * Don't set NX because code runs from these pages.
23180 */
23181- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
23182-#endif
23183+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
23184
23185 NEXT_PAGE(level3_kernel_pgt)
23186 .fill L3_START_KERNEL,8,0
23187@@ -473,6 +526,9 @@ NEXT_PAGE(level3_kernel_pgt)
23188 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
23189 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
23190
23191+NEXT_PAGE(level2_vmemmap_pgt)
23192+ .fill 512,8,0
23193+
23194 NEXT_PAGE(level2_kernel_pgt)
23195 /*
23196 * 512 MB kernel mapping. We spend a full page on this pagetable
23197@@ -488,30 +544,62 @@ NEXT_PAGE(level2_kernel_pgt)
23198 KERNEL_IMAGE_SIZE/PMD_SIZE)
23199
23200 NEXT_PAGE(level2_fixmap_pgt)
23201- .fill 506,8,0
23202- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
23203- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
23204- .fill 5,8,0
23205+ .fill 507,8,0
23206+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
23207+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
23208+ .fill 4,8,0
23209
23210-NEXT_PAGE(level1_fixmap_pgt)
23211+NEXT_PAGE(level1_vsyscall_pgt)
23212 .fill 512,8,0
23213
23214 #undef PMDS
23215
23216- .data
23217+ .align PAGE_SIZE
23218+ENTRY(cpu_gdt_table)
23219+ .rept NR_CPUS
23220+ .quad 0x0000000000000000 /* NULL descriptor */
23221+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
23222+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
23223+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
23224+ .quad 0x00cffb000000ffff /* __USER32_CS */
23225+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
23226+ .quad 0x00affb000000ffff /* __USER_CS */
23227+
23228+#ifdef CONFIG_PAX_KERNEXEC
23229+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
23230+#else
23231+ .quad 0x0 /* unused */
23232+#endif
23233+
23234+ .quad 0,0 /* TSS */
23235+ .quad 0,0 /* LDT */
23236+ .quad 0,0,0 /* three TLS descriptors */
23237+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
23238+ /* asm/segment.h:GDT_ENTRIES must match this */
23239+
23240+#ifdef CONFIG_PAX_MEMORY_UDEREF
23241+ .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
23242+#else
23243+ .quad 0x0 /* unused */
23244+#endif
23245+
23246+ /* zero the remaining page */
23247+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
23248+ .endr
23249+
23250 .align 16
23251 .globl early_gdt_descr
23252 early_gdt_descr:
23253 .word GDT_ENTRIES*8-1
23254 early_gdt_descr_base:
23255- .quad INIT_PER_CPU_VAR(gdt_page)
23256+ .quad cpu_gdt_table
23257
23258 ENTRY(phys_base)
23259 /* This must match the first entry in level2_kernel_pgt */
23260 .quad 0x0000000000000000
23261
23262 #include "../../x86/xen/xen-head.S"
23263-
23264- __PAGE_ALIGNED_BSS
23265+
23266+ .section .rodata,"a",@progbits
23267 NEXT_PAGE(empty_zero_page)
23268 .skip PAGE_SIZE
23269diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
23270index 0fa6912..b37438b 100644
23271--- a/arch/x86/kernel/i386_ksyms_32.c
23272+++ b/arch/x86/kernel/i386_ksyms_32.c
23273@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
23274 EXPORT_SYMBOL(cmpxchg8b_emu);
23275 #endif
23276
23277+EXPORT_SYMBOL_GPL(cpu_gdt_table);
23278+
23279 /* Networking helper routines. */
23280 EXPORT_SYMBOL(csum_partial_copy_generic);
23281+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
23282+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
23283
23284 EXPORT_SYMBOL(__get_user_1);
23285 EXPORT_SYMBOL(__get_user_2);
23286@@ -37,3 +41,11 @@ EXPORT_SYMBOL(strstr);
23287
23288 EXPORT_SYMBOL(csum_partial);
23289 EXPORT_SYMBOL(empty_zero_page);
23290+
23291+#ifdef CONFIG_PAX_KERNEXEC
23292+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
23293+#endif
23294+
23295+#ifdef CONFIG_PAX_PER_CPU_PGD
23296+EXPORT_SYMBOL(cpu_pgd);
23297+#endif
23298diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
23299index 5d576ab..1403a03 100644
23300--- a/arch/x86/kernel/i387.c
23301+++ b/arch/x86/kernel/i387.c
23302@@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
23303 static inline bool interrupted_user_mode(void)
23304 {
23305 struct pt_regs *regs = get_irq_regs();
23306- return regs && user_mode_vm(regs);
23307+ return regs && user_mode(regs);
23308 }
23309
23310 /*
23311diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
23312index 9a5c460..84868423 100644
23313--- a/arch/x86/kernel/i8259.c
23314+++ b/arch/x86/kernel/i8259.c
23315@@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
23316 static void make_8259A_irq(unsigned int irq)
23317 {
23318 disable_irq_nosync(irq);
23319- io_apic_irqs &= ~(1<<irq);
23320+ io_apic_irqs &= ~(1UL<<irq);
23321 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
23322 i8259A_chip.name);
23323 enable_irq(irq);
23324@@ -209,7 +209,7 @@ spurious_8259A_irq:
23325 "spurious 8259A interrupt: IRQ%d.\n", irq);
23326 spurious_irq_mask |= irqmask;
23327 }
23328- atomic_inc(&irq_err_count);
23329+ atomic_inc_unchecked(&irq_err_count);
23330 /*
23331 * Theoretically we do not have to handle this IRQ,
23332 * but in Linux this does not cause problems and is
23333@@ -333,14 +333,16 @@ static void init_8259A(int auto_eoi)
23334 /* (slave's support for AEOI in flat mode is to be investigated) */
23335 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
23336
23337+ pax_open_kernel();
23338 if (auto_eoi)
23339 /*
23340 * In AEOI mode we just have to mask the interrupt
23341 * when acking.
23342 */
23343- i8259A_chip.irq_mask_ack = disable_8259A_irq;
23344+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
23345 else
23346- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
23347+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
23348+ pax_close_kernel();
23349
23350 udelay(100); /* wait for 8259A to initialize */
23351
23352diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
23353index a979b5b..1d6db75 100644
23354--- a/arch/x86/kernel/io_delay.c
23355+++ b/arch/x86/kernel/io_delay.c
23356@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
23357 * Quirk table for systems that misbehave (lock up, etc.) if port
23358 * 0x80 is used:
23359 */
23360-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
23361+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
23362 {
23363 .callback = dmi_io_delay_0xed_port,
23364 .ident = "Compaq Presario V6000",
23365diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
23366index 4ddaf66..6292f4e 100644
23367--- a/arch/x86/kernel/ioport.c
23368+++ b/arch/x86/kernel/ioport.c
23369@@ -6,6 +6,7 @@
23370 #include <linux/sched.h>
23371 #include <linux/kernel.h>
23372 #include <linux/capability.h>
23373+#include <linux/security.h>
23374 #include <linux/errno.h>
23375 #include <linux/types.h>
23376 #include <linux/ioport.h>
23377@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
23378
23379 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
23380 return -EINVAL;
23381+#ifdef CONFIG_GRKERNSEC_IO
23382+ if (turn_on && grsec_disable_privio) {
23383+ gr_handle_ioperm();
23384+ return -EPERM;
23385+ }
23386+#endif
23387 if (turn_on && !capable(CAP_SYS_RAWIO))
23388 return -EPERM;
23389
23390@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
23391 * because the ->io_bitmap_max value must match the bitmap
23392 * contents:
23393 */
23394- tss = &per_cpu(init_tss, get_cpu());
23395+ tss = init_tss + get_cpu();
23396
23397 if (turn_on)
23398 bitmap_clear(t->io_bitmap_ptr, from, num);
23399@@ -103,6 +110,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
23400 return -EINVAL;
23401 /* Trying to gain more privileges? */
23402 if (level > old) {
23403+#ifdef CONFIG_GRKERNSEC_IO
23404+ if (grsec_disable_privio) {
23405+ gr_handle_iopl();
23406+ return -EPERM;
23407+ }
23408+#endif
23409 if (!capable(CAP_SYS_RAWIO))
23410 return -EPERM;
23411 }
23412diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
23413index 3a8185c..3c042ee 100644
23414--- a/arch/x86/kernel/irq.c
23415+++ b/arch/x86/kernel/irq.c
23416@@ -21,7 +21,7 @@
23417 #define CREATE_TRACE_POINTS
23418 #include <asm/trace/irq_vectors.h>
23419
23420-atomic_t irq_err_count;
23421+atomic_unchecked_t irq_err_count;
23422
23423 /* Function pointer for generic interrupt vector handling */
23424 void (*x86_platform_ipi_callback)(void) = NULL;
23425@@ -125,9 +125,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
23426 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
23427 seq_printf(p, " Machine check polls\n");
23428 #endif
23429- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
23430+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
23431 #if defined(CONFIG_X86_IO_APIC)
23432- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
23433+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
23434 #endif
23435 return 0;
23436 }
23437@@ -167,7 +167,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
23438
23439 u64 arch_irq_stat(void)
23440 {
23441- u64 sum = atomic_read(&irq_err_count);
23442+ u64 sum = atomic_read_unchecked(&irq_err_count);
23443 return sum;
23444 }
23445
23446diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
23447index 4186755..784efa0 100644
23448--- a/arch/x86/kernel/irq_32.c
23449+++ b/arch/x86/kernel/irq_32.c
23450@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
23451 __asm__ __volatile__("andl %%esp,%0" :
23452 "=r" (sp) : "0" (THREAD_SIZE - 1));
23453
23454- return sp < (sizeof(struct thread_info) + STACK_WARN);
23455+ return sp < STACK_WARN;
23456 }
23457
23458 static void print_stack_overflow(void)
23459@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
23460 * per-CPU IRQ handling contexts (thread information and stack)
23461 */
23462 union irq_ctx {
23463- struct thread_info tinfo;
23464- u32 stack[THREAD_SIZE/sizeof(u32)];
23465+ unsigned long previous_esp;
23466+ u32 stack[THREAD_SIZE/sizeof(u32)];
23467 } __attribute__((aligned(THREAD_SIZE)));
23468
23469 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
23470@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
23471 static inline int
23472 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
23473 {
23474- union irq_ctx *curctx, *irqctx;
23475+ union irq_ctx *irqctx;
23476 u32 *isp, arg1, arg2;
23477
23478- curctx = (union irq_ctx *) current_thread_info();
23479 irqctx = __this_cpu_read(hardirq_ctx);
23480
23481 /*
23482@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
23483 * handler) we can't do that and just have to keep using the
23484 * current stack (which is the irq stack already after all)
23485 */
23486- if (unlikely(curctx == irqctx))
23487+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
23488 return 0;
23489
23490 /* build the stack frame on the IRQ stack */
23491- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
23492- irqctx->tinfo.task = curctx->tinfo.task;
23493- irqctx->tinfo.previous_esp = current_stack_pointer;
23494+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
23495+ irqctx->previous_esp = current_stack_pointer;
23496
23497- /* Copy the preempt_count so that the [soft]irq checks work. */
23498- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
23499+#ifdef CONFIG_PAX_MEMORY_UDEREF
23500+ __set_fs(MAKE_MM_SEG(0));
23501+#endif
23502
23503 if (unlikely(overflow))
23504 call_on_stack(print_stack_overflow, isp);
23505@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
23506 : "0" (irq), "1" (desc), "2" (isp),
23507 "D" (desc->handle_irq)
23508 : "memory", "cc", "ecx");
23509+
23510+#ifdef CONFIG_PAX_MEMORY_UDEREF
23511+ __set_fs(current_thread_info()->addr_limit);
23512+#endif
23513+
23514 return 1;
23515 }
23516
23517@@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
23518 */
23519 void irq_ctx_init(int cpu)
23520 {
23521- union irq_ctx *irqctx;
23522-
23523 if (per_cpu(hardirq_ctx, cpu))
23524 return;
23525
23526- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
23527- THREADINFO_GFP,
23528- THREAD_SIZE_ORDER));
23529- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
23530- irqctx->tinfo.cpu = cpu;
23531- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
23532- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
23533+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
23534+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
23535
23536- per_cpu(hardirq_ctx, cpu) = irqctx;
23537-
23538- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
23539- THREADINFO_GFP,
23540- THREAD_SIZE_ORDER));
23541- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
23542- irqctx->tinfo.cpu = cpu;
23543- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
23544-
23545- per_cpu(softirq_ctx, cpu) = irqctx;
23546+ printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
23547+ cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
23548
23549 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
23550 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
23551@@ -152,7 +141,6 @@ void irq_ctx_init(int cpu)
23552 asmlinkage void do_softirq(void)
23553 {
23554 unsigned long flags;
23555- struct thread_info *curctx;
23556 union irq_ctx *irqctx;
23557 u32 *isp;
23558
23559@@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
23560 local_irq_save(flags);
23561
23562 if (local_softirq_pending()) {
23563- curctx = current_thread_info();
23564 irqctx = __this_cpu_read(softirq_ctx);
23565- irqctx->tinfo.task = curctx->task;
23566- irqctx->tinfo.previous_esp = current_stack_pointer;
23567+ irqctx->previous_esp = current_stack_pointer;
23568
23569 /* build the stack frame on the softirq stack */
23570- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
23571+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
23572+
23573+#ifdef CONFIG_PAX_MEMORY_UDEREF
23574+ __set_fs(MAKE_MM_SEG(0));
23575+#endif
23576
23577 call_on_stack(__do_softirq, isp);
23578+
23579+#ifdef CONFIG_PAX_MEMORY_UDEREF
23580+ __set_fs(current_thread_info()->addr_limit);
23581+#endif
23582+
23583 /*
23584 * Shouldn't happen, we returned above if in_interrupt():
23585 */
23586@@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
23587 if (unlikely(!desc))
23588 return false;
23589
23590- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
23591+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
23592 if (unlikely(overflow))
23593 print_stack_overflow();
23594 desc->handle_irq(irq, desc);
23595diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
23596index d04d3ec..ea4b374 100644
23597--- a/arch/x86/kernel/irq_64.c
23598+++ b/arch/x86/kernel/irq_64.c
23599@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
23600 u64 estack_top, estack_bottom;
23601 u64 curbase = (u64)task_stack_page(current);
23602
23603- if (user_mode_vm(regs))
23604+ if (user_mode(regs))
23605 return;
23606
23607 if (regs->sp >= curbase + sizeof(struct thread_info) +
23608diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
23609index dc1404b..bbc43e7 100644
23610--- a/arch/x86/kernel/kdebugfs.c
23611+++ b/arch/x86/kernel/kdebugfs.c
23612@@ -27,7 +27,7 @@ struct setup_data_node {
23613 u32 len;
23614 };
23615
23616-static ssize_t setup_data_read(struct file *file, char __user *user_buf,
23617+static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
23618 size_t count, loff_t *ppos)
23619 {
23620 struct setup_data_node *node = file->private_data;
23621diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
23622index 836f832..a8bda67 100644
23623--- a/arch/x86/kernel/kgdb.c
23624+++ b/arch/x86/kernel/kgdb.c
23625@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
23626 #ifdef CONFIG_X86_32
23627 switch (regno) {
23628 case GDB_SS:
23629- if (!user_mode_vm(regs))
23630+ if (!user_mode(regs))
23631 *(unsigned long *)mem = __KERNEL_DS;
23632 break;
23633 case GDB_SP:
23634- if (!user_mode_vm(regs))
23635+ if (!user_mode(regs))
23636 *(unsigned long *)mem = kernel_stack_pointer(regs);
23637 break;
23638 case GDB_GS:
23639@@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
23640 bp->attr.bp_addr = breakinfo[breakno].addr;
23641 bp->attr.bp_len = breakinfo[breakno].len;
23642 bp->attr.bp_type = breakinfo[breakno].type;
23643- info->address = breakinfo[breakno].addr;
23644+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
23645+ info->address = ktla_ktva(breakinfo[breakno].addr);
23646+ else
23647+ info->address = breakinfo[breakno].addr;
23648 info->len = breakinfo[breakno].len;
23649 info->type = breakinfo[breakno].type;
23650 val = arch_install_hw_breakpoint(bp);
23651@@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
23652 case 'k':
23653 /* clear the trace bit */
23654 linux_regs->flags &= ~X86_EFLAGS_TF;
23655- atomic_set(&kgdb_cpu_doing_single_step, -1);
23656+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
23657
23658 /* set the trace bit if we're stepping */
23659 if (remcomInBuffer[0] == 's') {
23660 linux_regs->flags |= X86_EFLAGS_TF;
23661- atomic_set(&kgdb_cpu_doing_single_step,
23662+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
23663 raw_smp_processor_id());
23664 }
23665
23666@@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
23667
23668 switch (cmd) {
23669 case DIE_DEBUG:
23670- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
23671+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
23672 if (user_mode(regs))
23673 return single_step_cont(regs, args);
23674 break;
23675@@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
23676 #endif /* CONFIG_DEBUG_RODATA */
23677
23678 bpt->type = BP_BREAKPOINT;
23679- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
23680+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
23681 BREAK_INSTR_SIZE);
23682 if (err)
23683 return err;
23684- err = probe_kernel_write((char *)bpt->bpt_addr,
23685+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
23686 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
23687 #ifdef CONFIG_DEBUG_RODATA
23688 if (!err)
23689@@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
23690 return -EBUSY;
23691 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
23692 BREAK_INSTR_SIZE);
23693- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
23694+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
23695 if (err)
23696 return err;
23697 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
23698@@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
23699 if (mutex_is_locked(&text_mutex))
23700 goto knl_write;
23701 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
23702- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
23703+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
23704 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
23705 goto knl_write;
23706 return err;
23707 knl_write:
23708 #endif /* CONFIG_DEBUG_RODATA */
23709- return probe_kernel_write((char *)bpt->bpt_addr,
23710+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
23711 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
23712 }
23713
23714diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
23715index 211bce4..6e2580a 100644
23716--- a/arch/x86/kernel/kprobes/core.c
23717+++ b/arch/x86/kernel/kprobes/core.c
23718@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
23719 s32 raddr;
23720 } __packed *insn;
23721
23722- insn = (struct __arch_relative_insn *)from;
23723+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
23724+
23725+ pax_open_kernel();
23726 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
23727 insn->op = op;
23728+ pax_close_kernel();
23729 }
23730
23731 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
23732@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
23733 kprobe_opcode_t opcode;
23734 kprobe_opcode_t *orig_opcodes = opcodes;
23735
23736- if (search_exception_tables((unsigned long)opcodes))
23737+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
23738 return 0; /* Page fault may occur on this address. */
23739
23740 retry:
23741@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
23742 * for the first byte, we can recover the original instruction
23743 * from it and kp->opcode.
23744 */
23745- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
23746+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
23747 buf[0] = kp->opcode;
23748- return (unsigned long)buf;
23749+ return ktva_ktla((unsigned long)buf);
23750 }
23751
23752 /*
23753@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
23754 /* Another subsystem puts a breakpoint, failed to recover */
23755 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
23756 return 0;
23757+ pax_open_kernel();
23758 memcpy(dest, insn.kaddr, insn.length);
23759+ pax_close_kernel();
23760
23761 #ifdef CONFIG_X86_64
23762 if (insn_rip_relative(&insn)) {
23763@@ -359,7 +364,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
23764 return 0;
23765 }
23766 disp = (u8 *) dest + insn_offset_displacement(&insn);
23767+ pax_open_kernel();
23768 *(s32 *) disp = (s32) newdisp;
23769+ pax_close_kernel();
23770 }
23771 #endif
23772 return insn.length;
23773@@ -498,7 +505,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
23774 * nor set current_kprobe, because it doesn't use single
23775 * stepping.
23776 */
23777- regs->ip = (unsigned long)p->ainsn.insn;
23778+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
23779 preempt_enable_no_resched();
23780 return;
23781 }
23782@@ -515,9 +522,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
23783 regs->flags &= ~X86_EFLAGS_IF;
23784 /* single step inline if the instruction is an int3 */
23785 if (p->opcode == BREAKPOINT_INSTRUCTION)
23786- regs->ip = (unsigned long)p->addr;
23787+ regs->ip = ktla_ktva((unsigned long)p->addr);
23788 else
23789- regs->ip = (unsigned long)p->ainsn.insn;
23790+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
23791 }
23792
23793 /*
23794@@ -596,7 +603,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
23795 setup_singlestep(p, regs, kcb, 0);
23796 return 1;
23797 }
23798- } else if (*addr != BREAKPOINT_INSTRUCTION) {
23799+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
23800 /*
23801 * The breakpoint instruction was removed right
23802 * after we hit it. Another cpu has removed
23803@@ -642,6 +649,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
23804 " movq %rax, 152(%rsp)\n"
23805 RESTORE_REGS_STRING
23806 " popfq\n"
23807+#ifdef KERNEXEC_PLUGIN
23808+ " btsq $63,(%rsp)\n"
23809+#endif
23810 #else
23811 " pushf\n"
23812 SAVE_REGS_STRING
23813@@ -779,7 +789,7 @@ static void __kprobes
23814 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
23815 {
23816 unsigned long *tos = stack_addr(regs);
23817- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
23818+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
23819 unsigned long orig_ip = (unsigned long)p->addr;
23820 kprobe_opcode_t *insn = p->ainsn.insn;
23821
23822@@ -961,7 +971,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
23823 struct die_args *args = data;
23824 int ret = NOTIFY_DONE;
23825
23826- if (args->regs && user_mode_vm(args->regs))
23827+ if (args->regs && user_mode(args->regs))
23828 return ret;
23829
23830 switch (val) {
23831diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
23832index 76dc6f0..66bdfc3 100644
23833--- a/arch/x86/kernel/kprobes/opt.c
23834+++ b/arch/x86/kernel/kprobes/opt.c
23835@@ -79,6 +79,7 @@ found:
23836 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
23837 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
23838 {
23839+ pax_open_kernel();
23840 #ifdef CONFIG_X86_64
23841 *addr++ = 0x48;
23842 *addr++ = 0xbf;
23843@@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
23844 *addr++ = 0xb8;
23845 #endif
23846 *(unsigned long *)addr = val;
23847+ pax_close_kernel();
23848 }
23849
23850 static void __used __kprobes kprobes_optinsn_template_holder(void)
23851@@ -338,7 +340,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
23852 * Verify if the address gap is in 2GB range, because this uses
23853 * a relative jump.
23854 */
23855- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
23856+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
23857 if (abs(rel) > 0x7fffffff)
23858 return -ERANGE;
23859
23860@@ -353,16 +355,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
23861 op->optinsn.size = ret;
23862
23863 /* Copy arch-dep-instance from template */
23864- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
23865+ pax_open_kernel();
23866+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
23867+ pax_close_kernel();
23868
23869 /* Set probe information */
23870 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
23871
23872 /* Set probe function call */
23873- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
23874+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
23875
23876 /* Set returning jmp instruction at the tail of out-of-line buffer */
23877- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
23878+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
23879 (u8 *)op->kp.addr + op->optinsn.size);
23880
23881 flush_icache_range((unsigned long) buf,
23882@@ -385,7 +389,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
23883 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
23884
23885 /* Backup instructions which will be replaced by jump address */
23886- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
23887+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
23888 RELATIVE_ADDR_SIZE);
23889
23890 insn_buf[0] = RELATIVEJUMP_OPCODE;
23891@@ -483,7 +487,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
23892 /* This kprobe is really able to run optimized path. */
23893 op = container_of(p, struct optimized_kprobe, kp);
23894 /* Detour through copied instructions */
23895- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
23896+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
23897 if (!reenter)
23898 reset_current_kprobe();
23899 preempt_enable_no_resched();
23900diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
23901index ebc9873..1b9724b 100644
23902--- a/arch/x86/kernel/ldt.c
23903+++ b/arch/x86/kernel/ldt.c
23904@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
23905 if (reload) {
23906 #ifdef CONFIG_SMP
23907 preempt_disable();
23908- load_LDT(pc);
23909+ load_LDT_nolock(pc);
23910 if (!cpumask_equal(mm_cpumask(current->mm),
23911 cpumask_of(smp_processor_id())))
23912 smp_call_function(flush_ldt, current->mm, 1);
23913 preempt_enable();
23914 #else
23915- load_LDT(pc);
23916+ load_LDT_nolock(pc);
23917 #endif
23918 }
23919 if (oldsize) {
23920@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
23921 return err;
23922
23923 for (i = 0; i < old->size; i++)
23924- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
23925+ write_ldt_entry(new->ldt, i, old->ldt + i);
23926 return 0;
23927 }
23928
23929@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
23930 retval = copy_ldt(&mm->context, &old_mm->context);
23931 mutex_unlock(&old_mm->context.lock);
23932 }
23933+
23934+ if (tsk == current) {
23935+ mm->context.vdso = 0;
23936+
23937+#ifdef CONFIG_X86_32
23938+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23939+ mm->context.user_cs_base = 0UL;
23940+ mm->context.user_cs_limit = ~0UL;
23941+
23942+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
23943+ cpus_clear(mm->context.cpu_user_cs_mask);
23944+#endif
23945+
23946+#endif
23947+#endif
23948+
23949+ }
23950+
23951 return retval;
23952 }
23953
23954@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
23955 }
23956 }
23957
23958+#ifdef CONFIG_PAX_SEGMEXEC
23959+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
23960+ error = -EINVAL;
23961+ goto out_unlock;
23962+ }
23963+#endif
23964+
23965 fill_ldt(&ldt, &ldt_info);
23966 if (oldmode)
23967 ldt.avl = 0;
23968diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
23969index 5b19e4d..6476a76 100644
23970--- a/arch/x86/kernel/machine_kexec_32.c
23971+++ b/arch/x86/kernel/machine_kexec_32.c
23972@@ -26,7 +26,7 @@
23973 #include <asm/cacheflush.h>
23974 #include <asm/debugreg.h>
23975
23976-static void set_idt(void *newidt, __u16 limit)
23977+static void set_idt(struct desc_struct *newidt, __u16 limit)
23978 {
23979 struct desc_ptr curidt;
23980
23981@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
23982 }
23983
23984
23985-static void set_gdt(void *newgdt, __u16 limit)
23986+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
23987 {
23988 struct desc_ptr curgdt;
23989
23990@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
23991 }
23992
23993 control_page = page_address(image->control_code_page);
23994- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
23995+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
23996
23997 relocate_kernel_ptr = control_page;
23998 page_list[PA_CONTROL_PAGE] = __pa(control_page);
23999diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
24000index 15c9876..0a43909 100644
24001--- a/arch/x86/kernel/microcode_core.c
24002+++ b/arch/x86/kernel/microcode_core.c
24003@@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
24004 return NOTIFY_OK;
24005 }
24006
24007-static struct notifier_block __refdata mc_cpu_notifier = {
24008+static struct notifier_block mc_cpu_notifier = {
24009 .notifier_call = mc_cpu_callback,
24010 };
24011
24012diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
24013index 5fb2ceb..3ae90bb 100644
24014--- a/arch/x86/kernel/microcode_intel.c
24015+++ b/arch/x86/kernel/microcode_intel.c
24016@@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
24017
24018 static int get_ucode_user(void *to, const void *from, size_t n)
24019 {
24020- return copy_from_user(to, from, n);
24021+ return copy_from_user(to, (const void __force_user *)from, n);
24022 }
24023
24024 static enum ucode_state
24025 request_microcode_user(int cpu, const void __user *buf, size_t size)
24026 {
24027- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
24028+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
24029 }
24030
24031 static void microcode_fini_cpu(int cpu)
24032diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
24033index 216a4d7..228255a 100644
24034--- a/arch/x86/kernel/module.c
24035+++ b/arch/x86/kernel/module.c
24036@@ -43,15 +43,60 @@ do { \
24037 } while (0)
24038 #endif
24039
24040-void *module_alloc(unsigned long size)
24041+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
24042 {
24043- if (PAGE_ALIGN(size) > MODULES_LEN)
24044+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
24045 return NULL;
24046 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
24047- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
24048+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
24049 -1, __builtin_return_address(0));
24050 }
24051
24052+void *module_alloc(unsigned long size)
24053+{
24054+
24055+#ifdef CONFIG_PAX_KERNEXEC
24056+ return __module_alloc(size, PAGE_KERNEL);
24057+#else
24058+ return __module_alloc(size, PAGE_KERNEL_EXEC);
24059+#endif
24060+
24061+}
24062+
24063+#ifdef CONFIG_PAX_KERNEXEC
24064+#ifdef CONFIG_X86_32
24065+void *module_alloc_exec(unsigned long size)
24066+{
24067+ struct vm_struct *area;
24068+
24069+ if (size == 0)
24070+ return NULL;
24071+
24072+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
24073+ return area ? area->addr : NULL;
24074+}
24075+EXPORT_SYMBOL(module_alloc_exec);
24076+
24077+void module_free_exec(struct module *mod, void *module_region)
24078+{
24079+ vunmap(module_region);
24080+}
24081+EXPORT_SYMBOL(module_free_exec);
24082+#else
24083+void module_free_exec(struct module *mod, void *module_region)
24084+{
24085+ module_free(mod, module_region);
24086+}
24087+EXPORT_SYMBOL(module_free_exec);
24088+
24089+void *module_alloc_exec(unsigned long size)
24090+{
24091+ return __module_alloc(size, PAGE_KERNEL_RX);
24092+}
24093+EXPORT_SYMBOL(module_alloc_exec);
24094+#endif
24095+#endif
24096+
24097 #ifdef CONFIG_X86_32
24098 int apply_relocate(Elf32_Shdr *sechdrs,
24099 const char *strtab,
24100@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
24101 unsigned int i;
24102 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
24103 Elf32_Sym *sym;
24104- uint32_t *location;
24105+ uint32_t *plocation, location;
24106
24107 DEBUGP("Applying relocate section %u to %u\n",
24108 relsec, sechdrs[relsec].sh_info);
24109 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
24110 /* This is where to make the change */
24111- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
24112- + rel[i].r_offset;
24113+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
24114+ location = (uint32_t)plocation;
24115+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
24116+ plocation = ktla_ktva((void *)plocation);
24117 /* This is the symbol it is referring to. Note that all
24118 undefined symbols have been resolved. */
24119 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
24120@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
24121 switch (ELF32_R_TYPE(rel[i].r_info)) {
24122 case R_386_32:
24123 /* We add the value into the location given */
24124- *location += sym->st_value;
24125+ pax_open_kernel();
24126+ *plocation += sym->st_value;
24127+ pax_close_kernel();
24128 break;
24129 case R_386_PC32:
24130 /* Add the value, subtract its position */
24131- *location += sym->st_value - (uint32_t)location;
24132+ pax_open_kernel();
24133+ *plocation += sym->st_value - location;
24134+ pax_close_kernel();
24135 break;
24136 default:
24137 pr_err("%s: Unknown relocation: %u\n",
24138@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
24139 case R_X86_64_NONE:
24140 break;
24141 case R_X86_64_64:
24142+ pax_open_kernel();
24143 *(u64 *)loc = val;
24144+ pax_close_kernel();
24145 break;
24146 case R_X86_64_32:
24147+ pax_open_kernel();
24148 *(u32 *)loc = val;
24149+ pax_close_kernel();
24150 if (val != *(u32 *)loc)
24151 goto overflow;
24152 break;
24153 case R_X86_64_32S:
24154+ pax_open_kernel();
24155 *(s32 *)loc = val;
24156+ pax_close_kernel();
24157 if ((s64)val != *(s32 *)loc)
24158 goto overflow;
24159 break;
24160 case R_X86_64_PC32:
24161 val -= (u64)loc;
24162+ pax_open_kernel();
24163 *(u32 *)loc = val;
24164+ pax_close_kernel();
24165+
24166 #if 0
24167 if ((s64)val != *(s32 *)loc)
24168 goto overflow;
24169diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
24170index 88458fa..349f7a4 100644
24171--- a/arch/x86/kernel/msr.c
24172+++ b/arch/x86/kernel/msr.c
24173@@ -233,7 +233,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
24174 return notifier_from_errno(err);
24175 }
24176
24177-static struct notifier_block __refdata msr_class_cpu_notifier = {
24178+static struct notifier_block msr_class_cpu_notifier = {
24179 .notifier_call = msr_class_cpu_callback,
24180 };
24181
24182diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
24183index ba77ebc..65da999 100644
24184--- a/arch/x86/kernel/nmi.c
24185+++ b/arch/x86/kernel/nmi.c
24186@@ -138,7 +138,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
24187 return handled;
24188 }
24189
24190-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
24191+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
24192 {
24193 struct nmi_desc *desc = nmi_to_desc(type);
24194 unsigned long flags;
24195@@ -162,9 +162,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
24196 * event confuses some handlers (kdump uses this flag)
24197 */
24198 if (action->flags & NMI_FLAG_FIRST)
24199- list_add_rcu(&action->list, &desc->head);
24200+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
24201 else
24202- list_add_tail_rcu(&action->list, &desc->head);
24203+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
24204
24205 spin_unlock_irqrestore(&desc->lock, flags);
24206 return 0;
24207@@ -187,7 +187,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
24208 if (!strcmp(n->name, name)) {
24209 WARN(in_nmi(),
24210 "Trying to free NMI (%s) from NMI context!\n", n->name);
24211- list_del_rcu(&n->list);
24212+ pax_list_del_rcu((struct list_head *)&n->list);
24213 break;
24214 }
24215 }
24216@@ -512,6 +512,17 @@ static inline void nmi_nesting_postprocess(void)
24217 dotraplinkage notrace __kprobes void
24218 do_nmi(struct pt_regs *regs, long error_code)
24219 {
24220+
24221+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
24222+ if (!user_mode(regs)) {
24223+ unsigned long cs = regs->cs & 0xFFFF;
24224+ unsigned long ip = ktva_ktla(regs->ip);
24225+
24226+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
24227+ regs->ip = ip;
24228+ }
24229+#endif
24230+
24231 nmi_nesting_preprocess(regs);
24232
24233 nmi_enter();
24234diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
24235index 6d9582e..f746287 100644
24236--- a/arch/x86/kernel/nmi_selftest.c
24237+++ b/arch/x86/kernel/nmi_selftest.c
24238@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
24239 {
24240 /* trap all the unknown NMIs we may generate */
24241 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
24242- __initdata);
24243+ __initconst);
24244 }
24245
24246 static void __init cleanup_nmi_testsuite(void)
24247@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
24248 unsigned long timeout;
24249
24250 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
24251- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
24252+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
24253 nmi_fail = FAILURE;
24254 return;
24255 }
24256diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
24257index 676b8c7..870ba04 100644
24258--- a/arch/x86/kernel/paravirt-spinlocks.c
24259+++ b/arch/x86/kernel/paravirt-spinlocks.c
24260@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
24261 arch_spin_lock(lock);
24262 }
24263
24264-struct pv_lock_ops pv_lock_ops = {
24265+struct pv_lock_ops pv_lock_ops __read_only = {
24266 #ifdef CONFIG_SMP
24267 .spin_is_locked = __ticket_spin_is_locked,
24268 .spin_is_contended = __ticket_spin_is_contended,
24269diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
24270index cd6de64..27c6af0 100644
24271--- a/arch/x86/kernel/paravirt.c
24272+++ b/arch/x86/kernel/paravirt.c
24273@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
24274 {
24275 return x;
24276 }
24277+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
24278+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
24279+#endif
24280
24281 void __init default_banner(void)
24282 {
24283@@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
24284 if (opfunc == NULL)
24285 /* If there's no function, patch it with a ud2a (BUG) */
24286 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
24287- else if (opfunc == _paravirt_nop)
24288+ else if (opfunc == (void *)_paravirt_nop)
24289 /* If the operation is a nop, then nop the callsite */
24290 ret = paravirt_patch_nop();
24291
24292 /* identity functions just return their single argument */
24293- else if (opfunc == _paravirt_ident_32)
24294+ else if (opfunc == (void *)_paravirt_ident_32)
24295 ret = paravirt_patch_ident_32(insnbuf, len);
24296- else if (opfunc == _paravirt_ident_64)
24297+ else if (opfunc == (void *)_paravirt_ident_64)
24298 ret = paravirt_patch_ident_64(insnbuf, len);
24299+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
24300+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
24301+ ret = paravirt_patch_ident_64(insnbuf, len);
24302+#endif
24303
24304 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
24305 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
24306@@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
24307 if (insn_len > len || start == NULL)
24308 insn_len = len;
24309 else
24310- memcpy(insnbuf, start, insn_len);
24311+ memcpy(insnbuf, ktla_ktva(start), insn_len);
24312
24313 return insn_len;
24314 }
24315@@ -304,7 +311,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
24316 return this_cpu_read(paravirt_lazy_mode);
24317 }
24318
24319-struct pv_info pv_info = {
24320+struct pv_info pv_info __read_only = {
24321 .name = "bare hardware",
24322 .paravirt_enabled = 0,
24323 .kernel_rpl = 0,
24324@@ -315,16 +322,16 @@ struct pv_info pv_info = {
24325 #endif
24326 };
24327
24328-struct pv_init_ops pv_init_ops = {
24329+struct pv_init_ops pv_init_ops __read_only = {
24330 .patch = native_patch,
24331 };
24332
24333-struct pv_time_ops pv_time_ops = {
24334+struct pv_time_ops pv_time_ops __read_only = {
24335 .sched_clock = native_sched_clock,
24336 .steal_clock = native_steal_clock,
24337 };
24338
24339-struct pv_irq_ops pv_irq_ops = {
24340+struct pv_irq_ops pv_irq_ops __read_only = {
24341 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
24342 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
24343 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
24344@@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
24345 #endif
24346 };
24347
24348-struct pv_cpu_ops pv_cpu_ops = {
24349+struct pv_cpu_ops pv_cpu_ops __read_only = {
24350 .cpuid = native_cpuid,
24351 .get_debugreg = native_get_debugreg,
24352 .set_debugreg = native_set_debugreg,
24353@@ -394,21 +401,26 @@ struct pv_cpu_ops pv_cpu_ops = {
24354 .end_context_switch = paravirt_nop,
24355 };
24356
24357-struct pv_apic_ops pv_apic_ops = {
24358+struct pv_apic_ops pv_apic_ops __read_only= {
24359 #ifdef CONFIG_X86_LOCAL_APIC
24360 .startup_ipi_hook = paravirt_nop,
24361 #endif
24362 };
24363
24364-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
24365+#ifdef CONFIG_X86_32
24366+#ifdef CONFIG_X86_PAE
24367+/* 64-bit pagetable entries */
24368+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
24369+#else
24370 /* 32-bit pagetable entries */
24371 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
24372+#endif
24373 #else
24374 /* 64-bit pagetable entries */
24375 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
24376 #endif
24377
24378-struct pv_mmu_ops pv_mmu_ops = {
24379+struct pv_mmu_ops pv_mmu_ops __read_only = {
24380
24381 .read_cr2 = native_read_cr2,
24382 .write_cr2 = native_write_cr2,
24383@@ -458,6 +470,7 @@ struct pv_mmu_ops pv_mmu_ops = {
24384 .make_pud = PTE_IDENT,
24385
24386 .set_pgd = native_set_pgd,
24387+ .set_pgd_batched = native_set_pgd_batched,
24388 #endif
24389 #endif /* PAGETABLE_LEVELS >= 3 */
24390
24391@@ -478,6 +491,12 @@ struct pv_mmu_ops pv_mmu_ops = {
24392 },
24393
24394 .set_fixmap = native_set_fixmap,
24395+
24396+#ifdef CONFIG_PAX_KERNEXEC
24397+ .pax_open_kernel = native_pax_open_kernel,
24398+ .pax_close_kernel = native_pax_close_kernel,
24399+#endif
24400+
24401 };
24402
24403 EXPORT_SYMBOL_GPL(pv_time_ops);
24404diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
24405index 299d493..2ccb0ee 100644
24406--- a/arch/x86/kernel/pci-calgary_64.c
24407+++ b/arch/x86/kernel/pci-calgary_64.c
24408@@ -1339,7 +1339,7 @@ static void __init get_tce_space_from_tar(void)
24409 tce_space = be64_to_cpu(readq(target));
24410 tce_space = tce_space & TAR_SW_BITS;
24411
24412- tce_space = tce_space & (~specified_table_size);
24413+ tce_space = tce_space & (~(unsigned long)specified_table_size);
24414 info->tce_space = (u64 *)__va(tce_space);
24415 }
24416 }
24417diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
24418index 35ccf75..7a15747 100644
24419--- a/arch/x86/kernel/pci-iommu_table.c
24420+++ b/arch/x86/kernel/pci-iommu_table.c
24421@@ -2,7 +2,7 @@
24422 #include <asm/iommu_table.h>
24423 #include <linux/string.h>
24424 #include <linux/kallsyms.h>
24425-
24426+#include <linux/sched.h>
24427
24428 #define DEBUG 1
24429
24430diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
24431index 6c483ba..d10ce2f 100644
24432--- a/arch/x86/kernel/pci-swiotlb.c
24433+++ b/arch/x86/kernel/pci-swiotlb.c
24434@@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
24435 void *vaddr, dma_addr_t dma_addr,
24436 struct dma_attrs *attrs)
24437 {
24438- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
24439+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
24440 }
24441
24442 static struct dma_map_ops swiotlb_dma_ops = {
24443diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
24444index 83369e5..52b93f0 100644
24445--- a/arch/x86/kernel/process.c
24446+++ b/arch/x86/kernel/process.c
24447@@ -36,7 +36,8 @@
24448 * section. Since TSS's are completely CPU-local, we want them
24449 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
24450 */
24451-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
24452+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
24453+EXPORT_SYMBOL(init_tss);
24454
24455 #ifdef CONFIG_X86_64
24456 static DEFINE_PER_CPU(unsigned char, is_idle);
24457@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
24458 task_xstate_cachep =
24459 kmem_cache_create("task_xstate", xstate_size,
24460 __alignof__(union thread_xstate),
24461- SLAB_PANIC | SLAB_NOTRACK, NULL);
24462+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
24463 }
24464
24465 /*
24466@@ -105,7 +106,7 @@ void exit_thread(void)
24467 unsigned long *bp = t->io_bitmap_ptr;
24468
24469 if (bp) {
24470- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
24471+ struct tss_struct *tss = init_tss + get_cpu();
24472
24473 t->io_bitmap_ptr = NULL;
24474 clear_thread_flag(TIF_IO_BITMAP);
24475@@ -125,6 +126,9 @@ void flush_thread(void)
24476 {
24477 struct task_struct *tsk = current;
24478
24479+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
24480+ loadsegment(gs, 0);
24481+#endif
24482 flush_ptrace_hw_breakpoint(tsk);
24483 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
24484 drop_init_fpu(tsk);
24485@@ -271,7 +275,7 @@ static void __exit_idle(void)
24486 void exit_idle(void)
24487 {
24488 /* idle loop has pid 0 */
24489- if (current->pid)
24490+ if (task_pid_nr(current))
24491 return;
24492 __exit_idle();
24493 }
24494@@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
24495 return ret;
24496 }
24497 #endif
24498-void stop_this_cpu(void *dummy)
24499+__noreturn void stop_this_cpu(void *dummy)
24500 {
24501 local_irq_disable();
24502 /*
24503@@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
24504 }
24505 early_param("idle", idle_setup);
24506
24507-unsigned long arch_align_stack(unsigned long sp)
24508+#ifdef CONFIG_PAX_RANDKSTACK
24509+void pax_randomize_kstack(struct pt_regs *regs)
24510 {
24511- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
24512- sp -= get_random_int() % 8192;
24513- return sp & ~0xf;
24514-}
24515+ struct thread_struct *thread = &current->thread;
24516+ unsigned long time;
24517
24518-unsigned long arch_randomize_brk(struct mm_struct *mm)
24519-{
24520- unsigned long range_end = mm->brk + 0x02000000;
24521- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
24522-}
24523+ if (!randomize_va_space)
24524+ return;
24525+
24526+ if (v8086_mode(regs))
24527+ return;
24528
24529+ rdtscl(time);
24530+
24531+ /* P4 seems to return a 0 LSB, ignore it */
24532+#ifdef CONFIG_MPENTIUM4
24533+ time &= 0x3EUL;
24534+ time <<= 2;
24535+#elif defined(CONFIG_X86_64)
24536+ time &= 0xFUL;
24537+ time <<= 4;
24538+#else
24539+ time &= 0x1FUL;
24540+ time <<= 3;
24541+#endif
24542+
24543+ thread->sp0 ^= time;
24544+ load_sp0(init_tss + smp_processor_id(), thread);
24545+
24546+#ifdef CONFIG_X86_64
24547+ this_cpu_write(kernel_stack, thread->sp0);
24548+#endif
24549+}
24550+#endif
24551diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
24552index f8adefc..4bce3d6 100644
24553--- a/arch/x86/kernel/process_32.c
24554+++ b/arch/x86/kernel/process_32.c
24555@@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
24556 unsigned long thread_saved_pc(struct task_struct *tsk)
24557 {
24558 return ((unsigned long *)tsk->thread.sp)[3];
24559+//XXX return tsk->thread.eip;
24560 }
24561
24562 void __show_regs(struct pt_regs *regs, int all)
24563@@ -74,19 +75,18 @@ void __show_regs(struct pt_regs *regs, int all)
24564 unsigned long sp;
24565 unsigned short ss, gs;
24566
24567- if (user_mode_vm(regs)) {
24568+ if (user_mode(regs)) {
24569 sp = regs->sp;
24570 ss = regs->ss & 0xffff;
24571- gs = get_user_gs(regs);
24572 } else {
24573 sp = kernel_stack_pointer(regs);
24574 savesegment(ss, ss);
24575- savesegment(gs, gs);
24576 }
24577+ gs = get_user_gs(regs);
24578
24579 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
24580 (u16)regs->cs, regs->ip, regs->flags,
24581- smp_processor_id());
24582+ raw_smp_processor_id());
24583 print_symbol("EIP is at %s\n", regs->ip);
24584
24585 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
24586@@ -133,20 +133,21 @@ void release_thread(struct task_struct *dead_task)
24587 int copy_thread(unsigned long clone_flags, unsigned long sp,
24588 unsigned long arg, struct task_struct *p)
24589 {
24590- struct pt_regs *childregs = task_pt_regs(p);
24591+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
24592 struct task_struct *tsk;
24593 int err;
24594
24595 p->thread.sp = (unsigned long) childregs;
24596 p->thread.sp0 = (unsigned long) (childregs+1);
24597+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
24598
24599 if (unlikely(p->flags & PF_KTHREAD)) {
24600 /* kernel thread */
24601 memset(childregs, 0, sizeof(struct pt_regs));
24602 p->thread.ip = (unsigned long) ret_from_kernel_thread;
24603- task_user_gs(p) = __KERNEL_STACK_CANARY;
24604- childregs->ds = __USER_DS;
24605- childregs->es = __USER_DS;
24606+ savesegment(gs, childregs->gs);
24607+ childregs->ds = __KERNEL_DS;
24608+ childregs->es = __KERNEL_DS;
24609 childregs->fs = __KERNEL_PERCPU;
24610 childregs->bx = sp; /* function */
24611 childregs->bp = arg;
24612@@ -253,7 +254,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24613 struct thread_struct *prev = &prev_p->thread,
24614 *next = &next_p->thread;
24615 int cpu = smp_processor_id();
24616- struct tss_struct *tss = &per_cpu(init_tss, cpu);
24617+ struct tss_struct *tss = init_tss + cpu;
24618 fpu_switch_t fpu;
24619
24620 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
24621@@ -277,6 +278,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24622 */
24623 lazy_save_gs(prev->gs);
24624
24625+#ifdef CONFIG_PAX_MEMORY_UDEREF
24626+ __set_fs(task_thread_info(next_p)->addr_limit);
24627+#endif
24628+
24629 /*
24630 * Load the per-thread Thread-Local Storage descriptor.
24631 */
24632@@ -307,6 +312,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24633 */
24634 arch_end_context_switch(next_p);
24635
24636+ this_cpu_write(current_task, next_p);
24637+ this_cpu_write(current_tinfo, &next_p->tinfo);
24638+
24639 /*
24640 * Restore %gs if needed (which is common)
24641 */
24642@@ -315,8 +323,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24643
24644 switch_fpu_finish(next_p, fpu);
24645
24646- this_cpu_write(current_task, next_p);
24647-
24648 return prev_p;
24649 }
24650
24651@@ -346,4 +352,3 @@ unsigned long get_wchan(struct task_struct *p)
24652 } while (count++ < 16);
24653 return 0;
24654 }
24655-
24656diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
24657index 05646ba..0c2906d 100644
24658--- a/arch/x86/kernel/process_64.c
24659+++ b/arch/x86/kernel/process_64.c
24660@@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
24661 struct pt_regs *childregs;
24662 struct task_struct *me = current;
24663
24664- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
24665+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
24666 childregs = task_pt_regs(p);
24667 p->thread.sp = (unsigned long) childregs;
24668 p->thread.usersp = me->thread.usersp;
24669+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
24670 set_tsk_thread_flag(p, TIF_FORK);
24671 p->fpu_counter = 0;
24672 p->thread.io_bitmap_ptr = NULL;
24673@@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
24674 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
24675 savesegment(es, p->thread.es);
24676 savesegment(ds, p->thread.ds);
24677+ savesegment(ss, p->thread.ss);
24678+ BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
24679 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
24680
24681 if (unlikely(p->flags & PF_KTHREAD)) {
24682@@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24683 struct thread_struct *prev = &prev_p->thread;
24684 struct thread_struct *next = &next_p->thread;
24685 int cpu = smp_processor_id();
24686- struct tss_struct *tss = &per_cpu(init_tss, cpu);
24687+ struct tss_struct *tss = init_tss + cpu;
24688 unsigned fsindex, gsindex;
24689 fpu_switch_t fpu;
24690
24691@@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24692 if (unlikely(next->ds | prev->ds))
24693 loadsegment(ds, next->ds);
24694
24695+ savesegment(ss, prev->ss);
24696+ if (unlikely(next->ss != prev->ss))
24697+ loadsegment(ss, next->ss);
24698
24699 /* We must save %fs and %gs before load_TLS() because
24700 * %fs and %gs may be cleared by load_TLS().
24701@@ -362,10 +368,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
24702 prev->usersp = this_cpu_read(old_rsp);
24703 this_cpu_write(old_rsp, next->usersp);
24704 this_cpu_write(current_task, next_p);
24705+ this_cpu_write(current_tinfo, &next_p->tinfo);
24706
24707- this_cpu_write(kernel_stack,
24708- (unsigned long)task_stack_page(next_p) +
24709- THREAD_SIZE - KERNEL_STACK_OFFSET);
24710+ this_cpu_write(kernel_stack, next->sp0);
24711
24712 /*
24713 * Now maybe reload the debug registers and handle I/O bitmaps
24714@@ -434,12 +439,11 @@ unsigned long get_wchan(struct task_struct *p)
24715 if (!p || p == current || p->state == TASK_RUNNING)
24716 return 0;
24717 stack = (unsigned long)task_stack_page(p);
24718- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
24719+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
24720 return 0;
24721 fp = *(u64 *)(p->thread.sp);
24722 do {
24723- if (fp < (unsigned long)stack ||
24724- fp >= (unsigned long)stack+THREAD_SIZE)
24725+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
24726 return 0;
24727 ip = *(u64 *)(fp+8);
24728 if (!in_sched_functions(ip))
24729diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
24730index 7461f50..1334029 100644
24731--- a/arch/x86/kernel/ptrace.c
24732+++ b/arch/x86/kernel/ptrace.c
24733@@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
24734 {
24735 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
24736 unsigned long sp = (unsigned long)&regs->sp;
24737- struct thread_info *tinfo;
24738
24739- if (context == (sp & ~(THREAD_SIZE - 1)))
24740+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
24741 return sp;
24742
24743- tinfo = (struct thread_info *)context;
24744- if (tinfo->previous_esp)
24745- return tinfo->previous_esp;
24746+ sp = *(unsigned long *)context;
24747+ if (sp)
24748+ return sp;
24749
24750 return (unsigned long)regs;
24751 }
24752@@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
24753 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
24754 {
24755 int i;
24756- int dr7 = 0;
24757+ unsigned long dr7 = 0;
24758 struct arch_hw_breakpoint *info;
24759
24760 for (i = 0; i < HBP_NUM; i++) {
24761@@ -822,7 +821,7 @@ long arch_ptrace(struct task_struct *child, long request,
24762 unsigned long addr, unsigned long data)
24763 {
24764 int ret;
24765- unsigned long __user *datap = (unsigned long __user *)data;
24766+ unsigned long __user *datap = (__force unsigned long __user *)data;
24767
24768 switch (request) {
24769 /* read the word at location addr in the USER area. */
24770@@ -907,14 +906,14 @@ long arch_ptrace(struct task_struct *child, long request,
24771 if ((int) addr < 0)
24772 return -EIO;
24773 ret = do_get_thread_area(child, addr,
24774- (struct user_desc __user *)data);
24775+ (__force struct user_desc __user *) data);
24776 break;
24777
24778 case PTRACE_SET_THREAD_AREA:
24779 if ((int) addr < 0)
24780 return -EIO;
24781 ret = do_set_thread_area(child, addr,
24782- (struct user_desc __user *)data, 0);
24783+ (__force struct user_desc __user *) data, 0);
24784 break;
24785 #endif
24786
24787@@ -1292,7 +1291,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
24788
24789 #ifdef CONFIG_X86_64
24790
24791-static struct user_regset x86_64_regsets[] __read_mostly = {
24792+static user_regset_no_const x86_64_regsets[] __read_only = {
24793 [REGSET_GENERAL] = {
24794 .core_note_type = NT_PRSTATUS,
24795 .n = sizeof(struct user_regs_struct) / sizeof(long),
24796@@ -1333,7 +1332,7 @@ static const struct user_regset_view user_x86_64_view = {
24797 #endif /* CONFIG_X86_64 */
24798
24799 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
24800-static struct user_regset x86_32_regsets[] __read_mostly = {
24801+static user_regset_no_const x86_32_regsets[] __read_only = {
24802 [REGSET_GENERAL] = {
24803 .core_note_type = NT_PRSTATUS,
24804 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
24805@@ -1386,7 +1385,7 @@ static const struct user_regset_view user_x86_32_view = {
24806 */
24807 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
24808
24809-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
24810+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
24811 {
24812 #ifdef CONFIG_X86_64
24813 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
24814@@ -1421,7 +1420,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
24815 memset(info, 0, sizeof(*info));
24816 info->si_signo = SIGTRAP;
24817 info->si_code = si_code;
24818- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
24819+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
24820 }
24821
24822 void user_single_step_siginfo(struct task_struct *tsk,
24823@@ -1450,6 +1449,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
24824 # define IS_IA32 0
24825 #endif
24826
24827+#ifdef CONFIG_GRKERNSEC_SETXID
24828+extern void gr_delayed_cred_worker(void);
24829+#endif
24830+
24831 /*
24832 * We must return the syscall number to actually look up in the table.
24833 * This can be -1L to skip running any syscall at all.
24834@@ -1460,6 +1463,11 @@ long syscall_trace_enter(struct pt_regs *regs)
24835
24836 user_exit();
24837
24838+#ifdef CONFIG_GRKERNSEC_SETXID
24839+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
24840+ gr_delayed_cred_worker();
24841+#endif
24842+
24843 /*
24844 * If we stepped into a sysenter/syscall insn, it trapped in
24845 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
24846@@ -1515,6 +1523,11 @@ void syscall_trace_leave(struct pt_regs *regs)
24847 */
24848 user_exit();
24849
24850+#ifdef CONFIG_GRKERNSEC_SETXID
24851+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
24852+ gr_delayed_cred_worker();
24853+#endif
24854+
24855 audit_syscall_exit(regs);
24856
24857 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
24858diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
24859index 2cb9470..ff1fd80 100644
24860--- a/arch/x86/kernel/pvclock.c
24861+++ b/arch/x86/kernel/pvclock.c
24862@@ -43,11 +43,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
24863 return pv_tsc_khz;
24864 }
24865
24866-static atomic64_t last_value = ATOMIC64_INIT(0);
24867+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
24868
24869 void pvclock_resume(void)
24870 {
24871- atomic64_set(&last_value, 0);
24872+ atomic64_set_unchecked(&last_value, 0);
24873 }
24874
24875 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
24876@@ -92,11 +92,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
24877 * updating at the same time, and one of them could be slightly behind,
24878 * making the assumption that last_value always go forward fail to hold.
24879 */
24880- last = atomic64_read(&last_value);
24881+ last = atomic64_read_unchecked(&last_value);
24882 do {
24883 if (ret < last)
24884 return last;
24885- last = atomic64_cmpxchg(&last_value, last, ret);
24886+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
24887 } while (unlikely(last != ret));
24888
24889 return ret;
24890diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
24891index 563ed91..b9c3313 100644
24892--- a/arch/x86/kernel/reboot.c
24893+++ b/arch/x86/kernel/reboot.c
24894@@ -68,6 +68,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
24895
24896 void __noreturn machine_real_restart(unsigned int type)
24897 {
24898+
24899+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
24900+ struct desc_struct *gdt;
24901+#endif
24902+
24903 local_irq_disable();
24904
24905 /*
24906@@ -95,7 +100,29 @@ void __noreturn machine_real_restart(unsigned int type)
24907
24908 /* Jump to the identity-mapped low memory code */
24909 #ifdef CONFIG_X86_32
24910- asm volatile("jmpl *%0" : :
24911+
24912+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
24913+ gdt = get_cpu_gdt_table(smp_processor_id());
24914+ pax_open_kernel();
24915+#ifdef CONFIG_PAX_MEMORY_UDEREF
24916+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
24917+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
24918+ loadsegment(ds, __KERNEL_DS);
24919+ loadsegment(es, __KERNEL_DS);
24920+ loadsegment(ss, __KERNEL_DS);
24921+#endif
24922+#ifdef CONFIG_PAX_KERNEXEC
24923+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
24924+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
24925+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
24926+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
24927+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
24928+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
24929+#endif
24930+ pax_close_kernel();
24931+#endif
24932+
24933+ asm volatile("ljmpl *%0" : :
24934 "rm" (real_mode_header->machine_real_restart_asm),
24935 "a" (type));
24936 #else
24937@@ -442,7 +469,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
24938 * try to force a triple fault and then cycle between hitting the keyboard
24939 * controller and doing that
24940 */
24941-static void native_machine_emergency_restart(void)
24942+static void __noreturn native_machine_emergency_restart(void)
24943 {
24944 int i;
24945 int attempt = 0;
24946@@ -551,13 +578,13 @@ void native_machine_shutdown(void)
24947 #endif
24948 }
24949
24950-static void __machine_emergency_restart(int emergency)
24951+static void __noreturn __machine_emergency_restart(int emergency)
24952 {
24953 reboot_emergency = emergency;
24954 machine_ops.emergency_restart();
24955 }
24956
24957-static void native_machine_restart(char *__unused)
24958+static void __noreturn native_machine_restart(char *__unused)
24959 {
24960 pr_notice("machine restart\n");
24961
24962@@ -566,7 +593,7 @@ static void native_machine_restart(char *__unused)
24963 __machine_emergency_restart(0);
24964 }
24965
24966-static void native_machine_halt(void)
24967+static void __noreturn native_machine_halt(void)
24968 {
24969 /* Stop other cpus and apics */
24970 machine_shutdown();
24971@@ -576,7 +603,7 @@ static void native_machine_halt(void)
24972 stop_this_cpu(NULL);
24973 }
24974
24975-static void native_machine_power_off(void)
24976+static void __noreturn native_machine_power_off(void)
24977 {
24978 if (pm_power_off) {
24979 if (!reboot_force)
24980@@ -585,9 +612,10 @@ static void native_machine_power_off(void)
24981 }
24982 /* A fallback in case there is no PM info available */
24983 tboot_shutdown(TB_SHUTDOWN_HALT);
24984+ unreachable();
24985 }
24986
24987-struct machine_ops machine_ops = {
24988+struct machine_ops machine_ops __read_only = {
24989 .power_off = native_machine_power_off,
24990 .shutdown = native_machine_shutdown,
24991 .emergency_restart = native_machine_emergency_restart,
24992diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
24993index c8e41e9..64049ef 100644
24994--- a/arch/x86/kernel/reboot_fixups_32.c
24995+++ b/arch/x86/kernel/reboot_fixups_32.c
24996@@ -57,7 +57,7 @@ struct device_fixup {
24997 unsigned int vendor;
24998 unsigned int device;
24999 void (*reboot_fixup)(struct pci_dev *);
25000-};
25001+} __do_const;
25002
25003 /*
25004 * PCI ids solely used for fixups_table go here
25005diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
25006index 3fd2c69..16ef367 100644
25007--- a/arch/x86/kernel/relocate_kernel_64.S
25008+++ b/arch/x86/kernel/relocate_kernel_64.S
25009@@ -11,6 +11,7 @@
25010 #include <asm/kexec.h>
25011 #include <asm/processor-flags.h>
25012 #include <asm/pgtable_types.h>
25013+#include <asm/alternative-asm.h>
25014
25015 /*
25016 * Must be relocatable PIC code callable as a C function
25017@@ -96,8 +97,7 @@ relocate_kernel:
25018
25019 /* jump to identity mapped page */
25020 addq $(identity_mapped - relocate_kernel), %r8
25021- pushq %r8
25022- ret
25023+ jmp *%r8
25024
25025 identity_mapped:
25026 /* set return address to 0 if not preserving context */
25027@@ -167,6 +167,7 @@ identity_mapped:
25028 xorl %r14d, %r14d
25029 xorl %r15d, %r15d
25030
25031+ pax_force_retaddr 0, 1
25032 ret
25033
25034 1:
25035diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
25036index f8ec578..0cc110a 100644
25037--- a/arch/x86/kernel/setup.c
25038+++ b/arch/x86/kernel/setup.c
25039@@ -110,6 +110,7 @@
25040 #include <asm/mce.h>
25041 #include <asm/alternative.h>
25042 #include <asm/prom.h>
25043+#include <asm/boot.h>
25044
25045 /*
25046 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
25047@@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
25048 #endif
25049
25050
25051-#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
25052-unsigned long mmu_cr4_features;
25053+#ifdef CONFIG_X86_64
25054+unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
25055+#elif defined(CONFIG_X86_PAE)
25056+unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
25057 #else
25058-unsigned long mmu_cr4_features = X86_CR4_PAE;
25059+unsigned long mmu_cr4_features __read_only;
25060 #endif
25061
25062+void set_in_cr4(unsigned long mask)
25063+{
25064+ unsigned long cr4 = read_cr4();
25065+
25066+ if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
25067+ return;
25068+
25069+ pax_open_kernel();
25070+ mmu_cr4_features |= mask;
25071+ pax_close_kernel();
25072+
25073+ if (trampoline_cr4_features)
25074+ *trampoline_cr4_features = mmu_cr4_features;
25075+ cr4 |= mask;
25076+ write_cr4(cr4);
25077+}
25078+EXPORT_SYMBOL(set_in_cr4);
25079+
25080+void clear_in_cr4(unsigned long mask)
25081+{
25082+ unsigned long cr4 = read_cr4();
25083+
25084+ if (!(cr4 & mask) && cr4 == mmu_cr4_features)
25085+ return;
25086+
25087+ pax_open_kernel();
25088+ mmu_cr4_features &= ~mask;
25089+ pax_close_kernel();
25090+
25091+ if (trampoline_cr4_features)
25092+ *trampoline_cr4_features = mmu_cr4_features;
25093+ cr4 &= ~mask;
25094+ write_cr4(cr4);
25095+}
25096+EXPORT_SYMBOL(clear_in_cr4);
25097+
25098 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
25099 int bootloader_type, bootloader_version;
25100
25101@@ -444,7 +483,7 @@ static void __init parse_setup_data(void)
25102
25103 switch (data->type) {
25104 case SETUP_E820_EXT:
25105- parse_e820_ext(data);
25106+ parse_e820_ext((struct setup_data __force_kernel *)data);
25107 break;
25108 case SETUP_DTB:
25109 add_dtb(pa_data);
25110@@ -771,7 +810,7 @@ static void __init trim_bios_range(void)
25111 * area (640->1Mb) as ram even though it is not.
25112 * take them out.
25113 */
25114- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
25115+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
25116
25117 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
25118 }
25119@@ -779,7 +818,7 @@ static void __init trim_bios_range(void)
25120 /* called before trim_bios_range() to spare extra sanitize */
25121 static void __init e820_add_kernel_range(void)
25122 {
25123- u64 start = __pa_symbol(_text);
25124+ u64 start = __pa_symbol(ktla_ktva(_text));
25125 u64 size = __pa_symbol(_end) - start;
25126
25127 /*
25128@@ -841,8 +880,12 @@ static void __init trim_low_memory_range(void)
25129
25130 void __init setup_arch(char **cmdline_p)
25131 {
25132+#ifdef CONFIG_X86_32
25133+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
25134+#else
25135 memblock_reserve(__pa_symbol(_text),
25136 (unsigned long)__bss_stop - (unsigned long)_text);
25137+#endif
25138
25139 early_reserve_initrd();
25140
25141@@ -934,14 +977,14 @@ void __init setup_arch(char **cmdline_p)
25142
25143 if (!boot_params.hdr.root_flags)
25144 root_mountflags &= ~MS_RDONLY;
25145- init_mm.start_code = (unsigned long) _text;
25146- init_mm.end_code = (unsigned long) _etext;
25147+ init_mm.start_code = ktla_ktva((unsigned long) _text);
25148+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
25149 init_mm.end_data = (unsigned long) _edata;
25150 init_mm.brk = _brk_end;
25151
25152- code_resource.start = __pa_symbol(_text);
25153- code_resource.end = __pa_symbol(_etext)-1;
25154- data_resource.start = __pa_symbol(_etext);
25155+ code_resource.start = __pa_symbol(ktla_ktva(_text));
25156+ code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
25157+ data_resource.start = __pa_symbol(_sdata);
25158 data_resource.end = __pa_symbol(_edata)-1;
25159 bss_resource.start = __pa_symbol(__bss_start);
25160 bss_resource.end = __pa_symbol(__bss_stop)-1;
25161diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
25162index 5cdff03..80fa283 100644
25163--- a/arch/x86/kernel/setup_percpu.c
25164+++ b/arch/x86/kernel/setup_percpu.c
25165@@ -21,19 +21,17 @@
25166 #include <asm/cpu.h>
25167 #include <asm/stackprotector.h>
25168
25169-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
25170+#ifdef CONFIG_SMP
25171+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
25172 EXPORT_PER_CPU_SYMBOL(cpu_number);
25173+#endif
25174
25175-#ifdef CONFIG_X86_64
25176 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
25177-#else
25178-#define BOOT_PERCPU_OFFSET 0
25179-#endif
25180
25181 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
25182 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
25183
25184-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
25185+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
25186 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
25187 };
25188 EXPORT_SYMBOL(__per_cpu_offset);
25189@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
25190 {
25191 #ifdef CONFIG_NEED_MULTIPLE_NODES
25192 pg_data_t *last = NULL;
25193- unsigned int cpu;
25194+ int cpu;
25195
25196 for_each_possible_cpu(cpu) {
25197 int node = early_cpu_to_node(cpu);
25198@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
25199 {
25200 #ifdef CONFIG_X86_32
25201 struct desc_struct gdt;
25202+ unsigned long base = per_cpu_offset(cpu);
25203
25204- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
25205- 0x2 | DESCTYPE_S, 0x8);
25206- gdt.s = 1;
25207+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
25208+ 0x83 | DESCTYPE_S, 0xC);
25209 write_gdt_entry(get_cpu_gdt_table(cpu),
25210 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
25211 #endif
25212@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
25213 /* alrighty, percpu areas up and running */
25214 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
25215 for_each_possible_cpu(cpu) {
25216+#ifdef CONFIG_CC_STACKPROTECTOR
25217+#ifdef CONFIG_X86_32
25218+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
25219+#endif
25220+#endif
25221 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
25222 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
25223 per_cpu(cpu_number, cpu) = cpu;
25224@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
25225 */
25226 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
25227 #endif
25228+#ifdef CONFIG_CC_STACKPROTECTOR
25229+#ifdef CONFIG_X86_32
25230+ if (!cpu)
25231+ per_cpu(stack_canary.canary, cpu) = canary;
25232+#endif
25233+#endif
25234 /*
25235 * Up to this point, the boot CPU has been using .init.data
25236 * area. Reload any changed state for the boot CPU.
25237diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
25238index cf91358..a7081ea 100644
25239--- a/arch/x86/kernel/signal.c
25240+++ b/arch/x86/kernel/signal.c
25241@@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
25242 * Align the stack pointer according to the i386 ABI,
25243 * i.e. so that on function entry ((sp + 4) & 15) == 0.
25244 */
25245- sp = ((sp + 4) & -16ul) - 4;
25246+ sp = ((sp - 12) & -16ul) - 4;
25247 #else /* !CONFIG_X86_32 */
25248 sp = round_down(sp, 16) - 8;
25249 #endif
25250@@ -298,9 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
25251 }
25252
25253 if (current->mm->context.vdso)
25254- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
25255+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
25256 else
25257- restorer = &frame->retcode;
25258+ restorer = (void __user *)&frame->retcode;
25259 if (ksig->ka.sa.sa_flags & SA_RESTORER)
25260 restorer = ksig->ka.sa.sa_restorer;
25261
25262@@ -314,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
25263 * reasons and because gdb uses it as a signature to notice
25264 * signal handler stack frames.
25265 */
25266- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
25267+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
25268
25269 if (err)
25270 return -EFAULT;
25271@@ -358,10 +358,13 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
25272 else
25273 put_user_ex(0, &frame->uc.uc_flags);
25274 put_user_ex(0, &frame->uc.uc_link);
25275- err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
25276+ __save_altstack_ex(&frame->uc.uc_stack, regs->sp);
25277
25278 /* Set up to return from userspace. */
25279- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
25280+ if (current->mm->context.vdso)
25281+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
25282+ else
25283+ restorer = (void __user *)&frame->retcode;
25284 if (ksig->ka.sa.sa_flags & SA_RESTORER)
25285 restorer = ksig->ka.sa.sa_restorer;
25286 put_user_ex(restorer, &frame->pretcode);
25287@@ -373,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
25288 * reasons and because gdb uses it as a signature to notice
25289 * signal handler stack frames.
25290 */
25291- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
25292+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
25293 } put_user_catch(err);
25294
25295 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
25296@@ -423,7 +426,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
25297 else
25298 put_user_ex(0, &frame->uc.uc_flags);
25299 put_user_ex(0, &frame->uc.uc_link);
25300- err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
25301+ __save_altstack_ex(&frame->uc.uc_stack, regs->sp);
25302
25303 /* Set up to return from userspace. If provided, use a stub
25304 already in userspace. */
25305@@ -609,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
25306 {
25307 int usig = signr_convert(ksig->sig);
25308 sigset_t *set = sigmask_to_save();
25309- compat_sigset_t *cset = (compat_sigset_t *) set;
25310+ sigset_t sigcopy;
25311+ compat_sigset_t *cset;
25312+
25313+ sigcopy = *set;
25314+
25315+ cset = (compat_sigset_t *) &sigcopy;
25316
25317 /* Set up the stack frame */
25318 if (is_ia32_frame()) {
25319@@ -620,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
25320 } else if (is_x32_frame()) {
25321 return x32_setup_rt_frame(ksig, cset, regs);
25322 } else {
25323- return __setup_rt_frame(ksig->sig, ksig, set, regs);
25324+ return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
25325 }
25326 }
25327
25328diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
25329index cdaa347..f5af55d 100644
25330--- a/arch/x86/kernel/smp.c
25331+++ b/arch/x86/kernel/smp.c
25332@@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
25333
25334 __setup("nonmi_ipi", nonmi_ipi_setup);
25335
25336-struct smp_ops smp_ops = {
25337+struct smp_ops smp_ops __read_only = {
25338 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
25339 .smp_prepare_cpus = native_smp_prepare_cpus,
25340 .smp_cpus_done = native_smp_cpus_done,
25341diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
25342index aecc98a..0244a53 100644
25343--- a/arch/x86/kernel/smpboot.c
25344+++ b/arch/x86/kernel/smpboot.c
25345@@ -251,14 +251,18 @@ static void notrace start_secondary(void *unused)
25346
25347 enable_start_cpu0 = 0;
25348
25349-#ifdef CONFIG_X86_32
25350- /* switch away from the initial page table */
25351- load_cr3(swapper_pg_dir);
25352- __flush_tlb_all();
25353-#endif
25354-
25355 /* otherwise gcc will move up smp_processor_id before the cpu_init */
25356 barrier();
25357+
25358+ /* switch away from the initial page table */
25359+#ifdef CONFIG_PAX_PER_CPU_PGD
25360+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
25361+ __flush_tlb_all();
25362+#elif defined(CONFIG_X86_32)
25363+ load_cr3(swapper_pg_dir);
25364+ __flush_tlb_all();
25365+#endif
25366+
25367 /*
25368 * Check TSC synchronization with the BP:
25369 */
25370@@ -748,6 +752,7 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
25371 idle->thread.sp = (unsigned long) (((struct pt_regs *)
25372 (THREAD_SIZE + task_stack_page(idle))) - 1);
25373 per_cpu(current_task, cpu) = idle;
25374+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
25375
25376 #ifdef CONFIG_X86_32
25377 /* Stack for startup_32 can be just as for start_secondary onwards */
25378@@ -755,11 +760,13 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
25379 #else
25380 clear_tsk_thread_flag(idle, TIF_FORK);
25381 initial_gs = per_cpu_offset(cpu);
25382- per_cpu(kernel_stack, cpu) =
25383- (unsigned long)task_stack_page(idle) -
25384- KERNEL_STACK_OFFSET + THREAD_SIZE;
25385+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
25386 #endif
25387+
25388+ pax_open_kernel();
25389 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
25390+ pax_close_kernel();
25391+
25392 initial_code = (unsigned long)start_secondary;
25393 stack_start = idle->thread.sp;
25394
25395@@ -908,6 +915,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
25396 /* the FPU context is blank, nobody can own it */
25397 __cpu_disable_lazy_restore(cpu);
25398
25399+#ifdef CONFIG_PAX_PER_CPU_PGD
25400+ clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
25401+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25402+ KERNEL_PGD_PTRS);
25403+ clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
25404+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25405+ KERNEL_PGD_PTRS);
25406+#endif
25407+
25408 err = do_boot_cpu(apicid, cpu, tidle);
25409 if (err) {
25410 pr_debug("do_boot_cpu failed %d\n", err);
25411diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
25412index 9b4d51d..5d28b58 100644
25413--- a/arch/x86/kernel/step.c
25414+++ b/arch/x86/kernel/step.c
25415@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
25416 struct desc_struct *desc;
25417 unsigned long base;
25418
25419- seg &= ~7UL;
25420+ seg >>= 3;
25421
25422 mutex_lock(&child->mm->context.lock);
25423- if (unlikely((seg >> 3) >= child->mm->context.size))
25424+ if (unlikely(seg >= child->mm->context.size))
25425 addr = -1L; /* bogus selector, access would fault */
25426 else {
25427 desc = child->mm->context.ldt + seg;
25428@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
25429 addr += base;
25430 }
25431 mutex_unlock(&child->mm->context.lock);
25432- }
25433+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
25434+ addr = ktla_ktva(addr);
25435
25436 return addr;
25437 }
25438@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
25439 unsigned char opcode[15];
25440 unsigned long addr = convert_ip_to_linear(child, regs);
25441
25442+ if (addr == -EINVAL)
25443+ return 0;
25444+
25445 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
25446 for (i = 0; i < copied; i++) {
25447 switch (opcode[i]) {
25448diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
25449new file mode 100644
25450index 0000000..5877189
25451--- /dev/null
25452+++ b/arch/x86/kernel/sys_i386_32.c
25453@@ -0,0 +1,189 @@
25454+/*
25455+ * This file contains various random system calls that
25456+ * have a non-standard calling sequence on the Linux/i386
25457+ * platform.
25458+ */
25459+
25460+#include <linux/errno.h>
25461+#include <linux/sched.h>
25462+#include <linux/mm.h>
25463+#include <linux/fs.h>
25464+#include <linux/smp.h>
25465+#include <linux/sem.h>
25466+#include <linux/msg.h>
25467+#include <linux/shm.h>
25468+#include <linux/stat.h>
25469+#include <linux/syscalls.h>
25470+#include <linux/mman.h>
25471+#include <linux/file.h>
25472+#include <linux/utsname.h>
25473+#include <linux/ipc.h>
25474+#include <linux/elf.h>
25475+
25476+#include <linux/uaccess.h>
25477+#include <linux/unistd.h>
25478+
25479+#include <asm/syscalls.h>
25480+
25481+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
25482+{
25483+ unsigned long pax_task_size = TASK_SIZE;
25484+
25485+#ifdef CONFIG_PAX_SEGMEXEC
25486+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
25487+ pax_task_size = SEGMEXEC_TASK_SIZE;
25488+#endif
25489+
25490+ if (flags & MAP_FIXED)
25491+ if (len > pax_task_size || addr > pax_task_size - len)
25492+ return -EINVAL;
25493+
25494+ return 0;
25495+}
25496+
25497+/*
25498+ * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
25499+ */
25500+static unsigned long get_align_mask(void)
25501+{
25502+ if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
25503+ return 0;
25504+
25505+ if (!(current->flags & PF_RANDOMIZE))
25506+ return 0;
25507+
25508+ return va_align.mask;
25509+}
25510+
25511+unsigned long
25512+arch_get_unmapped_area(struct file *filp, unsigned long addr,
25513+ unsigned long len, unsigned long pgoff, unsigned long flags)
25514+{
25515+ struct mm_struct *mm = current->mm;
25516+ struct vm_area_struct *vma;
25517+ unsigned long pax_task_size = TASK_SIZE;
25518+ struct vm_unmapped_area_info info;
25519+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
25520+
25521+#ifdef CONFIG_PAX_SEGMEXEC
25522+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25523+ pax_task_size = SEGMEXEC_TASK_SIZE;
25524+#endif
25525+
25526+ pax_task_size -= PAGE_SIZE;
25527+
25528+ if (len > pax_task_size)
25529+ return -ENOMEM;
25530+
25531+ if (flags & MAP_FIXED)
25532+ return addr;
25533+
25534+#ifdef CONFIG_PAX_RANDMMAP
25535+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
25536+#endif
25537+
25538+ if (addr) {
25539+ addr = PAGE_ALIGN(addr);
25540+ if (pax_task_size - len >= addr) {
25541+ vma = find_vma(mm, addr);
25542+ if (check_heap_stack_gap(vma, addr, len, offset))
25543+ return addr;
25544+ }
25545+ }
25546+
25547+ info.flags = 0;
25548+ info.length = len;
25549+ info.align_mask = filp ? get_align_mask() : 0;
25550+ info.align_offset = pgoff << PAGE_SHIFT;
25551+ info.threadstack_offset = offset;
25552+
25553+#ifdef CONFIG_PAX_PAGEEXEC
25554+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
25555+ info.low_limit = 0x00110000UL;
25556+ info.high_limit = mm->start_code;
25557+
25558+#ifdef CONFIG_PAX_RANDMMAP
25559+ if (mm->pax_flags & MF_PAX_RANDMMAP)
25560+ info.low_limit += mm->delta_mmap & 0x03FFF000UL;
25561+#endif
25562+
25563+ if (info.low_limit < info.high_limit) {
25564+ addr = vm_unmapped_area(&info);
25565+ if (!IS_ERR_VALUE(addr))
25566+ return addr;
25567+ }
25568+ } else
25569+#endif
25570+
25571+ info.low_limit = mm->mmap_base;
25572+ info.high_limit = pax_task_size;
25573+
25574+ return vm_unmapped_area(&info);
25575+}
25576+
25577+unsigned long
25578+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
25579+ const unsigned long len, const unsigned long pgoff,
25580+ const unsigned long flags)
25581+{
25582+ struct vm_area_struct *vma;
25583+ struct mm_struct *mm = current->mm;
25584+ unsigned long addr = addr0, pax_task_size = TASK_SIZE;
25585+ struct vm_unmapped_area_info info;
25586+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
25587+
25588+#ifdef CONFIG_PAX_SEGMEXEC
25589+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
25590+ pax_task_size = SEGMEXEC_TASK_SIZE;
25591+#endif
25592+
25593+ pax_task_size -= PAGE_SIZE;
25594+
25595+ /* requested length too big for entire address space */
25596+ if (len > pax_task_size)
25597+ return -ENOMEM;
25598+
25599+ if (flags & MAP_FIXED)
25600+ return addr;
25601+
25602+#ifdef CONFIG_PAX_PAGEEXEC
25603+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
25604+ goto bottomup;
25605+#endif
25606+
25607+#ifdef CONFIG_PAX_RANDMMAP
25608+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
25609+#endif
25610+
25611+ /* requesting a specific address */
25612+ if (addr) {
25613+ addr = PAGE_ALIGN(addr);
25614+ if (pax_task_size - len >= addr) {
25615+ vma = find_vma(mm, addr);
25616+ if (check_heap_stack_gap(vma, addr, len, offset))
25617+ return addr;
25618+ }
25619+ }
25620+
25621+ info.flags = VM_UNMAPPED_AREA_TOPDOWN;
25622+ info.length = len;
25623+ info.low_limit = PAGE_SIZE;
25624+ info.high_limit = mm->mmap_base;
25625+ info.align_mask = filp ? get_align_mask() : 0;
25626+ info.align_offset = pgoff << PAGE_SHIFT;
25627+ info.threadstack_offset = offset;
25628+
25629+ addr = vm_unmapped_area(&info);
25630+ if (!(addr & ~PAGE_MASK))
25631+ return addr;
25632+ VM_BUG_ON(addr != -ENOMEM);
25633+
25634+bottomup:
25635+ /*
25636+ * A failed mmap() very likely causes application failure,
25637+ * so fall back to the bottom-up function here. This scenario
25638+ * can happen with large stack limits and large mmap()
25639+ * allocations.
25640+ */
25641+ return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
25642+}
25643diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
25644index 30277e2..5664a29 100644
25645--- a/arch/x86/kernel/sys_x86_64.c
25646+++ b/arch/x86/kernel/sys_x86_64.c
25647@@ -81,8 +81,8 @@ out:
25648 return error;
25649 }
25650
25651-static void find_start_end(unsigned long flags, unsigned long *begin,
25652- unsigned long *end)
25653+static void find_start_end(struct mm_struct *mm, unsigned long flags,
25654+ unsigned long *begin, unsigned long *end)
25655 {
25656 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
25657 unsigned long new_begin;
25658@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
25659 *begin = new_begin;
25660 }
25661 } else {
25662- *begin = current->mm->mmap_legacy_base;
25663+ *begin = mm->mmap_legacy_base;
25664 *end = TASK_SIZE;
25665 }
25666 }
25667@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
25668 struct vm_area_struct *vma;
25669 struct vm_unmapped_area_info info;
25670 unsigned long begin, end;
25671+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
25672
25673 if (flags & MAP_FIXED)
25674 return addr;
25675
25676- find_start_end(flags, &begin, &end);
25677+ find_start_end(mm, flags, &begin, &end);
25678
25679 if (len > end)
25680 return -ENOMEM;
25681
25682+#ifdef CONFIG_PAX_RANDMMAP
25683+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
25684+#endif
25685+
25686 if (addr) {
25687 addr = PAGE_ALIGN(addr);
25688 vma = find_vma(mm, addr);
25689- if (end - len >= addr &&
25690- (!vma || addr + len <= vma->vm_start))
25691+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
25692 return addr;
25693 }
25694
25695@@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
25696 info.high_limit = end;
25697 info.align_mask = filp ? get_align_mask() : 0;
25698 info.align_offset = pgoff << PAGE_SHIFT;
25699+ info.threadstack_offset = offset;
25700 return vm_unmapped_area(&info);
25701 }
25702
25703@@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
25704 struct mm_struct *mm = current->mm;
25705 unsigned long addr = addr0;
25706 struct vm_unmapped_area_info info;
25707+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
25708
25709 /* requested length too big for entire address space */
25710 if (len > TASK_SIZE)
25711@@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
25712 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
25713 goto bottomup;
25714
25715+#ifdef CONFIG_PAX_RANDMMAP
25716+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
25717+#endif
25718+
25719 /* requesting a specific address */
25720 if (addr) {
25721 addr = PAGE_ALIGN(addr);
25722 vma = find_vma(mm, addr);
25723- if (TASK_SIZE - len >= addr &&
25724- (!vma || addr + len <= vma->vm_start))
25725+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
25726 return addr;
25727 }
25728
25729@@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
25730 info.high_limit = mm->mmap_base;
25731 info.align_mask = filp ? get_align_mask() : 0;
25732 info.align_offset = pgoff << PAGE_SHIFT;
25733+ info.threadstack_offset = offset;
25734 addr = vm_unmapped_area(&info);
25735 if (!(addr & ~PAGE_MASK))
25736 return addr;
25737diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
25738index addf7b5..f960685 100644
25739--- a/arch/x86/kernel/tboot.c
25740+++ b/arch/x86/kernel/tboot.c
25741@@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
25742
25743 void tboot_shutdown(u32 shutdown_type)
25744 {
25745- void (*shutdown)(void);
25746+ void (* __noreturn shutdown)(void);
25747
25748 if (!tboot_enabled())
25749 return;
25750@@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
25751
25752 switch_to_tboot_pt();
25753
25754- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
25755+ shutdown = (void *)tboot->shutdown_entry;
25756 shutdown();
25757
25758 /* should not reach here */
25759@@ -301,7 +301,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
25760 return 0;
25761 }
25762
25763-static atomic_t ap_wfs_count;
25764+static atomic_unchecked_t ap_wfs_count;
25765
25766 static int tboot_wait_for_aps(int num_aps)
25767 {
25768@@ -325,9 +325,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
25769 {
25770 switch (action) {
25771 case CPU_DYING:
25772- atomic_inc(&ap_wfs_count);
25773+ atomic_inc_unchecked(&ap_wfs_count);
25774 if (num_online_cpus() == 1)
25775- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
25776+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
25777 return NOTIFY_BAD;
25778 break;
25779 }
25780@@ -413,7 +413,7 @@ static __init int tboot_late_init(void)
25781
25782 tboot_create_trampoline();
25783
25784- atomic_set(&ap_wfs_count, 0);
25785+ atomic_set_unchecked(&ap_wfs_count, 0);
25786 register_hotcpu_notifier(&tboot_cpu_notifier);
25787
25788 #ifdef CONFIG_DEBUG_FS
25789diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
25790index 24d3c91..d06b473 100644
25791--- a/arch/x86/kernel/time.c
25792+++ b/arch/x86/kernel/time.c
25793@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
25794 {
25795 unsigned long pc = instruction_pointer(regs);
25796
25797- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
25798+ if (!user_mode(regs) && in_lock_functions(pc)) {
25799 #ifdef CONFIG_FRAME_POINTER
25800- return *(unsigned long *)(regs->bp + sizeof(long));
25801+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
25802 #else
25803 unsigned long *sp =
25804 (unsigned long *)kernel_stack_pointer(regs);
25805@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
25806 * or above a saved flags. Eflags has bits 22-31 zero,
25807 * kernel addresses don't.
25808 */
25809+
25810+#ifdef CONFIG_PAX_KERNEXEC
25811+ return ktla_ktva(sp[0]);
25812+#else
25813 if (sp[0] >> 22)
25814 return sp[0];
25815 if (sp[1] >> 22)
25816 return sp[1];
25817 #endif
25818+
25819+#endif
25820 }
25821 return pc;
25822 }
25823diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
25824index f7fec09..9991981 100644
25825--- a/arch/x86/kernel/tls.c
25826+++ b/arch/x86/kernel/tls.c
25827@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
25828 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
25829 return -EINVAL;
25830
25831+#ifdef CONFIG_PAX_SEGMEXEC
25832+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
25833+ return -EINVAL;
25834+#endif
25835+
25836 set_tls_desc(p, idx, &info, 1);
25837
25838 return 0;
25839@@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
25840
25841 if (kbuf)
25842 info = kbuf;
25843- else if (__copy_from_user(infobuf, ubuf, count))
25844+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
25845 return -EFAULT;
25846 else
25847 info = infobuf;
25848diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
25849index 1c113db..287b42e 100644
25850--- a/arch/x86/kernel/tracepoint.c
25851+++ b/arch/x86/kernel/tracepoint.c
25852@@ -9,11 +9,11 @@
25853 #include <linux/atomic.h>
25854
25855 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
25856-struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
25857+const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
25858 (unsigned long) trace_idt_table };
25859
25860 /* No need to be aligned, but done to keep all IDTs defined the same way. */
25861-gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
25862+gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
25863
25864 static int trace_irq_vector_refcount;
25865 static DEFINE_MUTEX(irq_vector_mutex);
25866diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
25867index 1b23a1c..910de0d 100644
25868--- a/arch/x86/kernel/traps.c
25869+++ b/arch/x86/kernel/traps.c
25870@@ -65,7 +65,7 @@
25871 #include <asm/proto.h>
25872
25873 /* No need to be aligned, but done to keep all IDTs defined the same way. */
25874-gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
25875+gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
25876 #else
25877 #include <asm/processor-flags.h>
25878 #include <asm/setup.h>
25879@@ -74,7 +74,7 @@ asmlinkage int system_call(void);
25880 #endif
25881
25882 /* Must be page-aligned because the real IDT is used in a fixmap. */
25883-gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
25884+gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
25885
25886 DECLARE_BITMAP(used_vectors, NR_VECTORS);
25887 EXPORT_SYMBOL_GPL(used_vectors);
25888@@ -106,11 +106,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
25889 }
25890
25891 static int __kprobes
25892-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
25893+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
25894 struct pt_regs *regs, long error_code)
25895 {
25896 #ifdef CONFIG_X86_32
25897- if (regs->flags & X86_VM_MASK) {
25898+ if (v8086_mode(regs)) {
25899 /*
25900 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
25901 * On nmi (interrupt 2), do_trap should not be called.
25902@@ -123,12 +123,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
25903 return -1;
25904 }
25905 #endif
25906- if (!user_mode(regs)) {
25907+ if (!user_mode_novm(regs)) {
25908 if (!fixup_exception(regs)) {
25909 tsk->thread.error_code = error_code;
25910 tsk->thread.trap_nr = trapnr;
25911+
25912+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25913+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
25914+ str = "PAX: suspicious stack segment fault";
25915+#endif
25916+
25917 die(str, regs, error_code);
25918 }
25919+
25920+#ifdef CONFIG_PAX_REFCOUNT
25921+ if (trapnr == 4)
25922+ pax_report_refcount_overflow(regs);
25923+#endif
25924+
25925 return 0;
25926 }
25927
25928@@ -136,7 +148,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
25929 }
25930
25931 static void __kprobes
25932-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
25933+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
25934 long error_code, siginfo_t *info)
25935 {
25936 struct task_struct *tsk = current;
25937@@ -160,7 +172,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
25938 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
25939 printk_ratelimit()) {
25940 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
25941- tsk->comm, tsk->pid, str,
25942+ tsk->comm, task_pid_nr(tsk), str,
25943 regs->ip, regs->sp, error_code);
25944 print_vma_addr(" in ", regs->ip);
25945 pr_cont("\n");
25946@@ -276,7 +288,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
25947 conditional_sti(regs);
25948
25949 #ifdef CONFIG_X86_32
25950- if (regs->flags & X86_VM_MASK) {
25951+ if (v8086_mode(regs)) {
25952 local_irq_enable();
25953 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
25954 goto exit;
25955@@ -284,18 +296,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
25956 #endif
25957
25958 tsk = current;
25959- if (!user_mode(regs)) {
25960+ if (!user_mode_novm(regs)) {
25961 if (fixup_exception(regs))
25962 goto exit;
25963
25964 tsk->thread.error_code = error_code;
25965 tsk->thread.trap_nr = X86_TRAP_GP;
25966 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
25967- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
25968+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
25969+
25970+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25971+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
25972+ die("PAX: suspicious general protection fault", regs, error_code);
25973+ else
25974+#endif
25975+
25976 die("general protection fault", regs, error_code);
25977+ }
25978 goto exit;
25979 }
25980
25981+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
25982+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
25983+ struct mm_struct *mm = tsk->mm;
25984+ unsigned long limit;
25985+
25986+ down_write(&mm->mmap_sem);
25987+ limit = mm->context.user_cs_limit;
25988+ if (limit < TASK_SIZE) {
25989+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
25990+ up_write(&mm->mmap_sem);
25991+ return;
25992+ }
25993+ up_write(&mm->mmap_sem);
25994+ }
25995+#endif
25996+
25997 tsk->thread.error_code = error_code;
25998 tsk->thread.trap_nr = X86_TRAP_GP;
25999
26000@@ -453,7 +489,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
26001 /* It's safe to allow irq's after DR6 has been saved */
26002 preempt_conditional_sti(regs);
26003
26004- if (regs->flags & X86_VM_MASK) {
26005+ if (v8086_mode(regs)) {
26006 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
26007 X86_TRAP_DB);
26008 preempt_conditional_cli(regs);
26009@@ -468,7 +504,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
26010 * We already checked v86 mode above, so we can check for kernel mode
26011 * by just checking the CPL of CS.
26012 */
26013- if ((dr6 & DR_STEP) && !user_mode(regs)) {
26014+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
26015 tsk->thread.debugreg6 &= ~DR_STEP;
26016 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
26017 regs->flags &= ~X86_EFLAGS_TF;
26018@@ -500,7 +536,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
26019 return;
26020 conditional_sti(regs);
26021
26022- if (!user_mode_vm(regs))
26023+ if (!user_mode(regs))
26024 {
26025 if (!fixup_exception(regs)) {
26026 task->thread.error_code = error_code;
26027diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
26028index 2ed8459..7cf329f 100644
26029--- a/arch/x86/kernel/uprobes.c
26030+++ b/arch/x86/kernel/uprobes.c
26031@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
26032 int ret = NOTIFY_DONE;
26033
26034 /* We are only interested in userspace traps */
26035- if (regs && !user_mode_vm(regs))
26036+ if (regs && !user_mode(regs))
26037 return NOTIFY_DONE;
26038
26039 switch (val) {
26040@@ -719,7 +719,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
26041
26042 if (ncopied != rasize) {
26043 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
26044- "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
26045+ "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
26046
26047 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
26048 }
26049diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
26050index b9242ba..50c5edd 100644
26051--- a/arch/x86/kernel/verify_cpu.S
26052+++ b/arch/x86/kernel/verify_cpu.S
26053@@ -20,6 +20,7 @@
26054 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
26055 * arch/x86/kernel/trampoline_64.S: secondary processor verification
26056 * arch/x86/kernel/head_32.S: processor startup
26057+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
26058 *
26059 * verify_cpu, returns the status of longmode and SSE in register %eax.
26060 * 0: Success 1: Failure
26061diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
26062index e8edcf5..27f9344 100644
26063--- a/arch/x86/kernel/vm86_32.c
26064+++ b/arch/x86/kernel/vm86_32.c
26065@@ -44,6 +44,7 @@
26066 #include <linux/ptrace.h>
26067 #include <linux/audit.h>
26068 #include <linux/stddef.h>
26069+#include <linux/grsecurity.h>
26070
26071 #include <asm/uaccess.h>
26072 #include <asm/io.h>
26073@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
26074 do_exit(SIGSEGV);
26075 }
26076
26077- tss = &per_cpu(init_tss, get_cpu());
26078+ tss = init_tss + get_cpu();
26079 current->thread.sp0 = current->thread.saved_sp0;
26080 current->thread.sysenter_cs = __KERNEL_CS;
26081 load_sp0(tss, &current->thread);
26082@@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
26083
26084 if (tsk->thread.saved_sp0)
26085 return -EPERM;
26086+
26087+#ifdef CONFIG_GRKERNSEC_VM86
26088+ if (!capable(CAP_SYS_RAWIO)) {
26089+ gr_handle_vm86();
26090+ return -EPERM;
26091+ }
26092+#endif
26093+
26094 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
26095 offsetof(struct kernel_vm86_struct, vm86plus) -
26096 sizeof(info.regs));
26097@@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
26098 int tmp;
26099 struct vm86plus_struct __user *v86;
26100
26101+#ifdef CONFIG_GRKERNSEC_VM86
26102+ if (!capable(CAP_SYS_RAWIO)) {
26103+ gr_handle_vm86();
26104+ return -EPERM;
26105+ }
26106+#endif
26107+
26108 tsk = current;
26109 switch (cmd) {
26110 case VM86_REQUEST_IRQ:
26111@@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
26112 tsk->thread.saved_fs = info->regs32->fs;
26113 tsk->thread.saved_gs = get_user_gs(info->regs32);
26114
26115- tss = &per_cpu(init_tss, get_cpu());
26116+ tss = init_tss + get_cpu();
26117 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
26118 if (cpu_has_sep)
26119 tsk->thread.sysenter_cs = 0;
26120@@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
26121 goto cannot_handle;
26122 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
26123 goto cannot_handle;
26124- intr_ptr = (unsigned long __user *) (i << 2);
26125+ intr_ptr = (__force unsigned long __user *) (i << 2);
26126 if (get_user(segoffs, intr_ptr))
26127 goto cannot_handle;
26128 if ((segoffs >> 16) == BIOSSEG)
26129diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
26130index 10c4f30..65408b9 100644
26131--- a/arch/x86/kernel/vmlinux.lds.S
26132+++ b/arch/x86/kernel/vmlinux.lds.S
26133@@ -26,6 +26,13 @@
26134 #include <asm/page_types.h>
26135 #include <asm/cache.h>
26136 #include <asm/boot.h>
26137+#include <asm/segment.h>
26138+
26139+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26140+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
26141+#else
26142+#define __KERNEL_TEXT_OFFSET 0
26143+#endif
26144
26145 #undef i386 /* in case the preprocessor is a 32bit one */
26146
26147@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
26148
26149 PHDRS {
26150 text PT_LOAD FLAGS(5); /* R_E */
26151+#ifdef CONFIG_X86_32
26152+ module PT_LOAD FLAGS(5); /* R_E */
26153+#endif
26154+#ifdef CONFIG_XEN
26155+ rodata PT_LOAD FLAGS(5); /* R_E */
26156+#else
26157+ rodata PT_LOAD FLAGS(4); /* R__ */
26158+#endif
26159 data PT_LOAD FLAGS(6); /* RW_ */
26160-#ifdef CONFIG_X86_64
26161+ init.begin PT_LOAD FLAGS(6); /* RW_ */
26162 #ifdef CONFIG_SMP
26163 percpu PT_LOAD FLAGS(6); /* RW_ */
26164 #endif
26165+ text.init PT_LOAD FLAGS(5); /* R_E */
26166+ text.exit PT_LOAD FLAGS(5); /* R_E */
26167 init PT_LOAD FLAGS(7); /* RWE */
26168-#endif
26169 note PT_NOTE FLAGS(0); /* ___ */
26170 }
26171
26172 SECTIONS
26173 {
26174 #ifdef CONFIG_X86_32
26175- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
26176- phys_startup_32 = startup_32 - LOAD_OFFSET;
26177+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
26178 #else
26179- . = __START_KERNEL;
26180- phys_startup_64 = startup_64 - LOAD_OFFSET;
26181+ . = __START_KERNEL;
26182 #endif
26183
26184 /* Text and read-only data */
26185- .text : AT(ADDR(.text) - LOAD_OFFSET) {
26186- _text = .;
26187+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
26188 /* bootstrapping code */
26189+#ifdef CONFIG_X86_32
26190+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
26191+#else
26192+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
26193+#endif
26194+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
26195+ _text = .;
26196 HEAD_TEXT
26197 . = ALIGN(8);
26198 _stext = .;
26199@@ -104,13 +124,47 @@ SECTIONS
26200 IRQENTRY_TEXT
26201 *(.fixup)
26202 *(.gnu.warning)
26203- /* End of text section */
26204- _etext = .;
26205 } :text = 0x9090
26206
26207- NOTES :text :note
26208+ . += __KERNEL_TEXT_OFFSET;
26209
26210- EXCEPTION_TABLE(16) :text = 0x9090
26211+#ifdef CONFIG_X86_32
26212+ . = ALIGN(PAGE_SIZE);
26213+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
26214+
26215+#ifdef CONFIG_PAX_KERNEXEC
26216+ MODULES_EXEC_VADDR = .;
26217+ BYTE(0)
26218+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
26219+ . = ALIGN(HPAGE_SIZE) - 1;
26220+ MODULES_EXEC_END = .;
26221+#endif
26222+
26223+ } :module
26224+#endif
26225+
26226+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
26227+ /* End of text section */
26228+ BYTE(0)
26229+ _etext = . - __KERNEL_TEXT_OFFSET;
26230+ }
26231+
26232+#ifdef CONFIG_X86_32
26233+ . = ALIGN(PAGE_SIZE);
26234+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
26235+ . = ALIGN(PAGE_SIZE);
26236+ *(.empty_zero_page)
26237+ *(.initial_pg_fixmap)
26238+ *(.initial_pg_pmd)
26239+ *(.initial_page_table)
26240+ *(.swapper_pg_dir)
26241+ } :rodata
26242+#endif
26243+
26244+ . = ALIGN(PAGE_SIZE);
26245+ NOTES :rodata :note
26246+
26247+ EXCEPTION_TABLE(16) :rodata
26248
26249 #if defined(CONFIG_DEBUG_RODATA)
26250 /* .text should occupy whole number of pages */
26251@@ -122,16 +176,20 @@ SECTIONS
26252
26253 /* Data */
26254 .data : AT(ADDR(.data) - LOAD_OFFSET) {
26255+
26256+#ifdef CONFIG_PAX_KERNEXEC
26257+ . = ALIGN(HPAGE_SIZE);
26258+#else
26259+ . = ALIGN(PAGE_SIZE);
26260+#endif
26261+
26262 /* Start of data section */
26263 _sdata = .;
26264
26265 /* init_task */
26266 INIT_TASK_DATA(THREAD_SIZE)
26267
26268-#ifdef CONFIG_X86_32
26269- /* 32 bit has nosave before _edata */
26270 NOSAVE_DATA
26271-#endif
26272
26273 PAGE_ALIGNED_DATA(PAGE_SIZE)
26274
26275@@ -172,12 +230,19 @@ SECTIONS
26276 #endif /* CONFIG_X86_64 */
26277
26278 /* Init code and data - will be freed after init */
26279- . = ALIGN(PAGE_SIZE);
26280 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
26281+ BYTE(0)
26282+
26283+#ifdef CONFIG_PAX_KERNEXEC
26284+ . = ALIGN(HPAGE_SIZE);
26285+#else
26286+ . = ALIGN(PAGE_SIZE);
26287+#endif
26288+
26289 __init_begin = .; /* paired with __init_end */
26290- }
26291+ } :init.begin
26292
26293-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
26294+#ifdef CONFIG_SMP
26295 /*
26296 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
26297 * output PHDR, so the next output section - .init.text - should
26298@@ -186,12 +251,27 @@ SECTIONS
26299 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
26300 #endif
26301
26302- INIT_TEXT_SECTION(PAGE_SIZE)
26303-#ifdef CONFIG_X86_64
26304- :init
26305-#endif
26306+ . = ALIGN(PAGE_SIZE);
26307+ init_begin = .;
26308+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
26309+ VMLINUX_SYMBOL(_sinittext) = .;
26310+ INIT_TEXT
26311+ VMLINUX_SYMBOL(_einittext) = .;
26312+ . = ALIGN(PAGE_SIZE);
26313+ } :text.init
26314
26315- INIT_DATA_SECTION(16)
26316+ /*
26317+ * .exit.text is discard at runtime, not link time, to deal with
26318+ * references from .altinstructions and .eh_frame
26319+ */
26320+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
26321+ EXIT_TEXT
26322+ . = ALIGN(16);
26323+ } :text.exit
26324+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
26325+
26326+ . = ALIGN(PAGE_SIZE);
26327+ INIT_DATA_SECTION(16) :init
26328
26329 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
26330 __x86_cpu_dev_start = .;
26331@@ -253,19 +333,12 @@ SECTIONS
26332 }
26333
26334 . = ALIGN(8);
26335- /*
26336- * .exit.text is discard at runtime, not link time, to deal with
26337- * references from .altinstructions and .eh_frame
26338- */
26339- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
26340- EXIT_TEXT
26341- }
26342
26343 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
26344 EXIT_DATA
26345 }
26346
26347-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
26348+#ifndef CONFIG_SMP
26349 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
26350 #endif
26351
26352@@ -284,16 +357,10 @@ SECTIONS
26353 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
26354 __smp_locks = .;
26355 *(.smp_locks)
26356- . = ALIGN(PAGE_SIZE);
26357 __smp_locks_end = .;
26358+ . = ALIGN(PAGE_SIZE);
26359 }
26360
26361-#ifdef CONFIG_X86_64
26362- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
26363- NOSAVE_DATA
26364- }
26365-#endif
26366-
26367 /* BSS */
26368 . = ALIGN(PAGE_SIZE);
26369 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
26370@@ -309,6 +376,7 @@ SECTIONS
26371 __brk_base = .;
26372 . += 64 * 1024; /* 64k alignment slop space */
26373 *(.brk_reservation) /* areas brk users have reserved */
26374+ . = ALIGN(HPAGE_SIZE);
26375 __brk_limit = .;
26376 }
26377
26378@@ -335,13 +403,12 @@ SECTIONS
26379 * for the boot processor.
26380 */
26381 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
26382-INIT_PER_CPU(gdt_page);
26383 INIT_PER_CPU(irq_stack_union);
26384
26385 /*
26386 * Build-time check on the image size:
26387 */
26388-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
26389+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
26390 "kernel image bigger than KERNEL_IMAGE_SIZE");
26391
26392 #ifdef CONFIG_SMP
26393diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
26394index 1f96f93..d5c8f7a 100644
26395--- a/arch/x86/kernel/vsyscall_64.c
26396+++ b/arch/x86/kernel/vsyscall_64.c
26397@@ -56,15 +56,13 @@
26398 DEFINE_VVAR(int, vgetcpu_mode);
26399 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
26400
26401-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
26402+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
26403
26404 static int __init vsyscall_setup(char *str)
26405 {
26406 if (str) {
26407 if (!strcmp("emulate", str))
26408 vsyscall_mode = EMULATE;
26409- else if (!strcmp("native", str))
26410- vsyscall_mode = NATIVE;
26411 else if (!strcmp("none", str))
26412 vsyscall_mode = NONE;
26413 else
26414@@ -323,8 +321,7 @@ do_ret:
26415 return true;
26416
26417 sigsegv:
26418- force_sig(SIGSEGV, current);
26419- return true;
26420+ do_group_exit(SIGKILL);
26421 }
26422
26423 /*
26424@@ -377,10 +374,7 @@ void __init map_vsyscall(void)
26425 extern char __vvar_page;
26426 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
26427
26428- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
26429- vsyscall_mode == NATIVE
26430- ? PAGE_KERNEL_VSYSCALL
26431- : PAGE_KERNEL_VVAR);
26432+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
26433 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
26434 (unsigned long)VSYSCALL_START);
26435
26436diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
26437index b014d94..e775258 100644
26438--- a/arch/x86/kernel/x8664_ksyms_64.c
26439+++ b/arch/x86/kernel/x8664_ksyms_64.c
26440@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
26441 EXPORT_SYMBOL(copy_user_generic_unrolled);
26442 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
26443 EXPORT_SYMBOL(__copy_user_nocache);
26444-EXPORT_SYMBOL(_copy_from_user);
26445-EXPORT_SYMBOL(_copy_to_user);
26446
26447 EXPORT_SYMBOL(copy_page);
26448 EXPORT_SYMBOL(clear_page);
26449@@ -66,3 +64,7 @@ EXPORT_SYMBOL(empty_zero_page);
26450 #ifndef CONFIG_PARAVIRT
26451 EXPORT_SYMBOL(native_load_gs_index);
26452 #endif
26453+
26454+#ifdef CONFIG_PAX_PER_CPU_PGD
26455+EXPORT_SYMBOL(cpu_pgd);
26456+#endif
26457diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
26458index 5f24c71..1dadf09 100644
26459--- a/arch/x86/kernel/x86_init.c
26460+++ b/arch/x86/kernel/x86_init.c
26461@@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
26462 static void default_nmi_init(void) { };
26463 static int default_i8042_detect(void) { return 1; };
26464
26465-struct x86_platform_ops x86_platform = {
26466+struct x86_platform_ops x86_platform __read_only = {
26467 .calibrate_tsc = native_calibrate_tsc,
26468 .get_wallclock = mach_get_cmos_time,
26469 .set_wallclock = mach_set_rtc_mmss,
26470@@ -107,7 +107,7 @@ struct x86_platform_ops x86_platform = {
26471 };
26472
26473 EXPORT_SYMBOL_GPL(x86_platform);
26474-struct x86_msi_ops x86_msi = {
26475+struct x86_msi_ops x86_msi __read_only = {
26476 .setup_msi_irqs = native_setup_msi_irqs,
26477 .compose_msi_msg = native_compose_msi_msg,
26478 .teardown_msi_irq = native_teardown_msi_irq,
26479@@ -116,7 +116,7 @@ struct x86_msi_ops x86_msi = {
26480 .setup_hpet_msi = default_setup_hpet_msi,
26481 };
26482
26483-struct x86_io_apic_ops x86_io_apic_ops = {
26484+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
26485 .init = native_io_apic_init_mappings,
26486 .read = native_io_apic_read,
26487 .write = native_io_apic_write,
26488diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
26489index 422fd82..c3687ca 100644
26490--- a/arch/x86/kernel/xsave.c
26491+++ b/arch/x86/kernel/xsave.c
26492@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
26493 {
26494 int err;
26495
26496+ buf = (struct xsave_struct __user *)____m(buf);
26497 if (use_xsave())
26498 err = xsave_user(buf);
26499 else if (use_fxsr())
26500@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
26501 */
26502 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
26503 {
26504+ buf = (void __user *)____m(buf);
26505 if (use_xsave()) {
26506 if ((unsigned long)buf % 64 || fx_only) {
26507 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
26508diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
26509index a20ecb5..d0e2194 100644
26510--- a/arch/x86/kvm/cpuid.c
26511+++ b/arch/x86/kvm/cpuid.c
26512@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
26513 struct kvm_cpuid2 *cpuid,
26514 struct kvm_cpuid_entry2 __user *entries)
26515 {
26516- int r;
26517+ int r, i;
26518
26519 r = -E2BIG;
26520 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
26521 goto out;
26522 r = -EFAULT;
26523- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
26524- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
26525+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
26526 goto out;
26527+ for (i = 0; i < cpuid->nent; ++i) {
26528+ struct kvm_cpuid_entry2 cpuid_entry;
26529+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
26530+ goto out;
26531+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
26532+ }
26533 vcpu->arch.cpuid_nent = cpuid->nent;
26534 kvm_apic_set_version(vcpu);
26535 kvm_x86_ops->cpuid_update(vcpu);
26536@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
26537 struct kvm_cpuid2 *cpuid,
26538 struct kvm_cpuid_entry2 __user *entries)
26539 {
26540- int r;
26541+ int r, i;
26542
26543 r = -E2BIG;
26544 if (cpuid->nent < vcpu->arch.cpuid_nent)
26545 goto out;
26546 r = -EFAULT;
26547- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
26548- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
26549+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
26550 goto out;
26551+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
26552+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
26553+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
26554+ goto out;
26555+ }
26556 return 0;
26557
26558 out:
26559diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
26560index afc1124..3e431f2 100644
26561--- a/arch/x86/kvm/lapic.c
26562+++ b/arch/x86/kvm/lapic.c
26563@@ -55,7 +55,7 @@
26564 #define APIC_BUS_CYCLE_NS 1
26565
26566 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
26567-#define apic_debug(fmt, arg...)
26568+#define apic_debug(fmt, arg...) do {} while (0)
26569
26570 #define APIC_LVT_NUM 6
26571 /* 14 is the version for Xeon and Pentium 8.4.8*/
26572diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
26573index 7769699..c8aca4a7f 100644
26574--- a/arch/x86/kvm/paging_tmpl.h
26575+++ b/arch/x86/kvm/paging_tmpl.h
26576@@ -208,7 +208,7 @@ retry_walk:
26577 if (unlikely(kvm_is_error_hva(host_addr)))
26578 goto error;
26579
26580- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
26581+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
26582 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
26583 goto error;
26584 walker->ptep_user[walker->level - 1] = ptep_user;
26585diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
26586index c0bc803..6837a50 100644
26587--- a/arch/x86/kvm/svm.c
26588+++ b/arch/x86/kvm/svm.c
26589@@ -3501,7 +3501,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
26590 int cpu = raw_smp_processor_id();
26591
26592 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
26593+
26594+ pax_open_kernel();
26595 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
26596+ pax_close_kernel();
26597+
26598 load_TR_desc();
26599 }
26600
26601@@ -3902,6 +3906,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
26602 #endif
26603 #endif
26604
26605+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
26606+ __set_fs(current_thread_info()->addr_limit);
26607+#endif
26608+
26609 reload_tss(vcpu);
26610
26611 local_irq_disable();
26612diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
26613index 064d0be..f5f758e 100644
26614--- a/arch/x86/kvm/vmx.c
26615+++ b/arch/x86/kvm/vmx.c
26616@@ -1311,12 +1311,12 @@ static void vmcs_write64(unsigned long field, u64 value)
26617 #endif
26618 }
26619
26620-static void vmcs_clear_bits(unsigned long field, u32 mask)
26621+static void vmcs_clear_bits(unsigned long field, unsigned long mask)
26622 {
26623 vmcs_writel(field, vmcs_readl(field) & ~mask);
26624 }
26625
26626-static void vmcs_set_bits(unsigned long field, u32 mask)
26627+static void vmcs_set_bits(unsigned long field, unsigned long mask)
26628 {
26629 vmcs_writel(field, vmcs_readl(field) | mask);
26630 }
26631@@ -1517,7 +1517,11 @@ static void reload_tss(void)
26632 struct desc_struct *descs;
26633
26634 descs = (void *)gdt->address;
26635+
26636+ pax_open_kernel();
26637 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
26638+ pax_close_kernel();
26639+
26640 load_TR_desc();
26641 }
26642
26643@@ -1741,6 +1745,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
26644 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
26645 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
26646
26647+#ifdef CONFIG_PAX_PER_CPU_PGD
26648+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
26649+#endif
26650+
26651 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
26652 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
26653 vmx->loaded_vmcs->cpu = cpu;
26654@@ -2940,8 +2948,11 @@ static __init int hardware_setup(void)
26655 if (!cpu_has_vmx_flexpriority())
26656 flexpriority_enabled = 0;
26657
26658- if (!cpu_has_vmx_tpr_shadow())
26659- kvm_x86_ops->update_cr8_intercept = NULL;
26660+ if (!cpu_has_vmx_tpr_shadow()) {
26661+ pax_open_kernel();
26662+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
26663+ pax_close_kernel();
26664+ }
26665
26666 if (enable_ept && !cpu_has_vmx_ept_2m_page())
26667 kvm_disable_largepages();
26668@@ -2952,13 +2963,15 @@ static __init int hardware_setup(void)
26669 if (!cpu_has_vmx_apicv())
26670 enable_apicv = 0;
26671
26672+ pax_open_kernel();
26673 if (enable_apicv)
26674- kvm_x86_ops->update_cr8_intercept = NULL;
26675+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
26676 else {
26677- kvm_x86_ops->hwapic_irr_update = NULL;
26678- kvm_x86_ops->deliver_posted_interrupt = NULL;
26679- kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
26680+ *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
26681+ *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
26682+ *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
26683 }
26684+ pax_close_kernel();
26685
26686 if (nested)
26687 nested_vmx_setup_ctls_msrs();
26688@@ -4081,7 +4094,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
26689
26690 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
26691 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
26692+
26693+#ifndef CONFIG_PAX_PER_CPU_PGD
26694 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
26695+#endif
26696
26697 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
26698 #ifdef CONFIG_X86_64
26699@@ -4103,7 +4119,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
26700 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
26701 vmx->host_idt_base = dt.address;
26702
26703- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
26704+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
26705
26706 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
26707 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
26708@@ -7039,6 +7055,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
26709 "jmp 2f \n\t"
26710 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
26711 "2: "
26712+
26713+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26714+ "ljmp %[cs],$3f\n\t"
26715+ "3: "
26716+#endif
26717+
26718 /* Save guest registers, load host registers, keep flags */
26719 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
26720 "pop %0 \n\t"
26721@@ -7091,6 +7113,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
26722 #endif
26723 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
26724 [wordsize]"i"(sizeof(ulong))
26725+
26726+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26727+ ,[cs]"i"(__KERNEL_CS)
26728+#endif
26729+
26730 : "cc", "memory"
26731 #ifdef CONFIG_X86_64
26732 , "rax", "rbx", "rdi", "rsi"
26733@@ -7104,7 +7131,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
26734 if (debugctlmsr)
26735 update_debugctlmsr(debugctlmsr);
26736
26737-#ifndef CONFIG_X86_64
26738+#ifdef CONFIG_X86_32
26739 /*
26740 * The sysexit path does not restore ds/es, so we must set them to
26741 * a reasonable value ourselves.
26742@@ -7113,8 +7140,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
26743 * may be executed in interrupt context, which saves and restore segments
26744 * around it, nullifying its effect.
26745 */
26746- loadsegment(ds, __USER_DS);
26747- loadsegment(es, __USER_DS);
26748+ loadsegment(ds, __KERNEL_DS);
26749+ loadsegment(es, __KERNEL_DS);
26750+ loadsegment(ss, __KERNEL_DS);
26751+
26752+#ifdef CONFIG_PAX_KERNEXEC
26753+ loadsegment(fs, __KERNEL_PERCPU);
26754+#endif
26755+
26756+#ifdef CONFIG_PAX_MEMORY_UDEREF
26757+ __set_fs(current_thread_info()->addr_limit);
26758+#endif
26759+
26760 #endif
26761
26762 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
26763diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
26764index d21bce5..fdae9f1 100644
26765--- a/arch/x86/kvm/x86.c
26766+++ b/arch/x86/kvm/x86.c
26767@@ -1766,8 +1766,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
26768 {
26769 struct kvm *kvm = vcpu->kvm;
26770 int lm = is_long_mode(vcpu);
26771- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
26772- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
26773+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
26774+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
26775 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
26776 : kvm->arch.xen_hvm_config.blob_size_32;
26777 u32 page_num = data & ~PAGE_MASK;
26778@@ -2650,6 +2650,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
26779 if (n < msr_list.nmsrs)
26780 goto out;
26781 r = -EFAULT;
26782+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
26783+ goto out;
26784 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
26785 num_msrs_to_save * sizeof(u32)))
26786 goto out;
26787@@ -5344,7 +5346,7 @@ static struct notifier_block pvclock_gtod_notifier = {
26788 };
26789 #endif
26790
26791-int kvm_arch_init(void *opaque)
26792+int kvm_arch_init(const void *opaque)
26793 {
26794 int r;
26795 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
26796diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
26797index 6a22c19..1763f04 100644
26798--- a/arch/x86/lguest/boot.c
26799+++ b/arch/x86/lguest/boot.c
26800@@ -1201,9 +1201,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
26801 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
26802 * Launcher to reboot us.
26803 */
26804-static void lguest_restart(char *reason)
26805+static __noreturn void lguest_restart(char *reason)
26806 {
26807 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
26808+ BUG();
26809 }
26810
26811 /*G:050
26812diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
26813index 00933d5..3a64af9 100644
26814--- a/arch/x86/lib/atomic64_386_32.S
26815+++ b/arch/x86/lib/atomic64_386_32.S
26816@@ -48,6 +48,10 @@ BEGIN(read)
26817 movl (v), %eax
26818 movl 4(v), %edx
26819 RET_ENDP
26820+BEGIN(read_unchecked)
26821+ movl (v), %eax
26822+ movl 4(v), %edx
26823+RET_ENDP
26824 #undef v
26825
26826 #define v %esi
26827@@ -55,6 +59,10 @@ BEGIN(set)
26828 movl %ebx, (v)
26829 movl %ecx, 4(v)
26830 RET_ENDP
26831+BEGIN(set_unchecked)
26832+ movl %ebx, (v)
26833+ movl %ecx, 4(v)
26834+RET_ENDP
26835 #undef v
26836
26837 #define v %esi
26838@@ -70,6 +78,20 @@ RET_ENDP
26839 BEGIN(add)
26840 addl %eax, (v)
26841 adcl %edx, 4(v)
26842+
26843+#ifdef CONFIG_PAX_REFCOUNT
26844+ jno 0f
26845+ subl %eax, (v)
26846+ sbbl %edx, 4(v)
26847+ int $4
26848+0:
26849+ _ASM_EXTABLE(0b, 0b)
26850+#endif
26851+
26852+RET_ENDP
26853+BEGIN(add_unchecked)
26854+ addl %eax, (v)
26855+ adcl %edx, 4(v)
26856 RET_ENDP
26857 #undef v
26858
26859@@ -77,6 +99,24 @@ RET_ENDP
26860 BEGIN(add_return)
26861 addl (v), %eax
26862 adcl 4(v), %edx
26863+
26864+#ifdef CONFIG_PAX_REFCOUNT
26865+ into
26866+1234:
26867+ _ASM_EXTABLE(1234b, 2f)
26868+#endif
26869+
26870+ movl %eax, (v)
26871+ movl %edx, 4(v)
26872+
26873+#ifdef CONFIG_PAX_REFCOUNT
26874+2:
26875+#endif
26876+
26877+RET_ENDP
26878+BEGIN(add_return_unchecked)
26879+ addl (v), %eax
26880+ adcl 4(v), %edx
26881 movl %eax, (v)
26882 movl %edx, 4(v)
26883 RET_ENDP
26884@@ -86,6 +126,20 @@ RET_ENDP
26885 BEGIN(sub)
26886 subl %eax, (v)
26887 sbbl %edx, 4(v)
26888+
26889+#ifdef CONFIG_PAX_REFCOUNT
26890+ jno 0f
26891+ addl %eax, (v)
26892+ adcl %edx, 4(v)
26893+ int $4
26894+0:
26895+ _ASM_EXTABLE(0b, 0b)
26896+#endif
26897+
26898+RET_ENDP
26899+BEGIN(sub_unchecked)
26900+ subl %eax, (v)
26901+ sbbl %edx, 4(v)
26902 RET_ENDP
26903 #undef v
26904
26905@@ -96,6 +150,27 @@ BEGIN(sub_return)
26906 sbbl $0, %edx
26907 addl (v), %eax
26908 adcl 4(v), %edx
26909+
26910+#ifdef CONFIG_PAX_REFCOUNT
26911+ into
26912+1234:
26913+ _ASM_EXTABLE(1234b, 2f)
26914+#endif
26915+
26916+ movl %eax, (v)
26917+ movl %edx, 4(v)
26918+
26919+#ifdef CONFIG_PAX_REFCOUNT
26920+2:
26921+#endif
26922+
26923+RET_ENDP
26924+BEGIN(sub_return_unchecked)
26925+ negl %edx
26926+ negl %eax
26927+ sbbl $0, %edx
26928+ addl (v), %eax
26929+ adcl 4(v), %edx
26930 movl %eax, (v)
26931 movl %edx, 4(v)
26932 RET_ENDP
26933@@ -105,6 +180,20 @@ RET_ENDP
26934 BEGIN(inc)
26935 addl $1, (v)
26936 adcl $0, 4(v)
26937+
26938+#ifdef CONFIG_PAX_REFCOUNT
26939+ jno 0f
26940+ subl $1, (v)
26941+ sbbl $0, 4(v)
26942+ int $4
26943+0:
26944+ _ASM_EXTABLE(0b, 0b)
26945+#endif
26946+
26947+RET_ENDP
26948+BEGIN(inc_unchecked)
26949+ addl $1, (v)
26950+ adcl $0, 4(v)
26951 RET_ENDP
26952 #undef v
26953
26954@@ -114,6 +203,26 @@ BEGIN(inc_return)
26955 movl 4(v), %edx
26956 addl $1, %eax
26957 adcl $0, %edx
26958+
26959+#ifdef CONFIG_PAX_REFCOUNT
26960+ into
26961+1234:
26962+ _ASM_EXTABLE(1234b, 2f)
26963+#endif
26964+
26965+ movl %eax, (v)
26966+ movl %edx, 4(v)
26967+
26968+#ifdef CONFIG_PAX_REFCOUNT
26969+2:
26970+#endif
26971+
26972+RET_ENDP
26973+BEGIN(inc_return_unchecked)
26974+ movl (v), %eax
26975+ movl 4(v), %edx
26976+ addl $1, %eax
26977+ adcl $0, %edx
26978 movl %eax, (v)
26979 movl %edx, 4(v)
26980 RET_ENDP
26981@@ -123,6 +232,20 @@ RET_ENDP
26982 BEGIN(dec)
26983 subl $1, (v)
26984 sbbl $0, 4(v)
26985+
26986+#ifdef CONFIG_PAX_REFCOUNT
26987+ jno 0f
26988+ addl $1, (v)
26989+ adcl $0, 4(v)
26990+ int $4
26991+0:
26992+ _ASM_EXTABLE(0b, 0b)
26993+#endif
26994+
26995+RET_ENDP
26996+BEGIN(dec_unchecked)
26997+ subl $1, (v)
26998+ sbbl $0, 4(v)
26999 RET_ENDP
27000 #undef v
27001
27002@@ -132,6 +255,26 @@ BEGIN(dec_return)
27003 movl 4(v), %edx
27004 subl $1, %eax
27005 sbbl $0, %edx
27006+
27007+#ifdef CONFIG_PAX_REFCOUNT
27008+ into
27009+1234:
27010+ _ASM_EXTABLE(1234b, 2f)
27011+#endif
27012+
27013+ movl %eax, (v)
27014+ movl %edx, 4(v)
27015+
27016+#ifdef CONFIG_PAX_REFCOUNT
27017+2:
27018+#endif
27019+
27020+RET_ENDP
27021+BEGIN(dec_return_unchecked)
27022+ movl (v), %eax
27023+ movl 4(v), %edx
27024+ subl $1, %eax
27025+ sbbl $0, %edx
27026 movl %eax, (v)
27027 movl %edx, 4(v)
27028 RET_ENDP
27029@@ -143,6 +286,13 @@ BEGIN(add_unless)
27030 adcl %edx, %edi
27031 addl (v), %eax
27032 adcl 4(v), %edx
27033+
27034+#ifdef CONFIG_PAX_REFCOUNT
27035+ into
27036+1234:
27037+ _ASM_EXTABLE(1234b, 2f)
27038+#endif
27039+
27040 cmpl %eax, %ecx
27041 je 3f
27042 1:
27043@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
27044 1:
27045 addl $1, %eax
27046 adcl $0, %edx
27047+
27048+#ifdef CONFIG_PAX_REFCOUNT
27049+ into
27050+1234:
27051+ _ASM_EXTABLE(1234b, 2f)
27052+#endif
27053+
27054 movl %eax, (v)
27055 movl %edx, 4(v)
27056 movl $1, %eax
27057@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
27058 movl 4(v), %edx
27059 subl $1, %eax
27060 sbbl $0, %edx
27061+
27062+#ifdef CONFIG_PAX_REFCOUNT
27063+ into
27064+1234:
27065+ _ASM_EXTABLE(1234b, 1f)
27066+#endif
27067+
27068 js 1f
27069 movl %eax, (v)
27070 movl %edx, 4(v)
27071diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
27072index f5cc9eb..51fa319 100644
27073--- a/arch/x86/lib/atomic64_cx8_32.S
27074+++ b/arch/x86/lib/atomic64_cx8_32.S
27075@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
27076 CFI_STARTPROC
27077
27078 read64 %ecx
27079+ pax_force_retaddr
27080 ret
27081 CFI_ENDPROC
27082 ENDPROC(atomic64_read_cx8)
27083
27084+ENTRY(atomic64_read_unchecked_cx8)
27085+ CFI_STARTPROC
27086+
27087+ read64 %ecx
27088+ pax_force_retaddr
27089+ ret
27090+ CFI_ENDPROC
27091+ENDPROC(atomic64_read_unchecked_cx8)
27092+
27093 ENTRY(atomic64_set_cx8)
27094 CFI_STARTPROC
27095
27096@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
27097 cmpxchg8b (%esi)
27098 jne 1b
27099
27100+ pax_force_retaddr
27101 ret
27102 CFI_ENDPROC
27103 ENDPROC(atomic64_set_cx8)
27104
27105+ENTRY(atomic64_set_unchecked_cx8)
27106+ CFI_STARTPROC
27107+
27108+1:
27109+/* we don't need LOCK_PREFIX since aligned 64-bit writes
27110+ * are atomic on 586 and newer */
27111+ cmpxchg8b (%esi)
27112+ jne 1b
27113+
27114+ pax_force_retaddr
27115+ ret
27116+ CFI_ENDPROC
27117+ENDPROC(atomic64_set_unchecked_cx8)
27118+
27119 ENTRY(atomic64_xchg_cx8)
27120 CFI_STARTPROC
27121
27122@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
27123 cmpxchg8b (%esi)
27124 jne 1b
27125
27126+ pax_force_retaddr
27127 ret
27128 CFI_ENDPROC
27129 ENDPROC(atomic64_xchg_cx8)
27130
27131-.macro addsub_return func ins insc
27132-ENTRY(atomic64_\func\()_return_cx8)
27133+.macro addsub_return func ins insc unchecked=""
27134+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
27135 CFI_STARTPROC
27136 SAVE ebp
27137 SAVE ebx
27138@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
27139 movl %edx, %ecx
27140 \ins\()l %esi, %ebx
27141 \insc\()l %edi, %ecx
27142+
27143+.ifb \unchecked
27144+#ifdef CONFIG_PAX_REFCOUNT
27145+ into
27146+2:
27147+ _ASM_EXTABLE(2b, 3f)
27148+#endif
27149+.endif
27150+
27151 LOCK_PREFIX
27152 cmpxchg8b (%ebp)
27153 jne 1b
27154-
27155-10:
27156 movl %ebx, %eax
27157 movl %ecx, %edx
27158+
27159+.ifb \unchecked
27160+#ifdef CONFIG_PAX_REFCOUNT
27161+3:
27162+#endif
27163+.endif
27164+
27165 RESTORE edi
27166 RESTORE esi
27167 RESTORE ebx
27168 RESTORE ebp
27169+ pax_force_retaddr
27170 ret
27171 CFI_ENDPROC
27172-ENDPROC(atomic64_\func\()_return_cx8)
27173+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
27174 .endm
27175
27176 addsub_return add add adc
27177 addsub_return sub sub sbb
27178+addsub_return add add adc _unchecked
27179+addsub_return sub sub sbb _unchecked
27180
27181-.macro incdec_return func ins insc
27182-ENTRY(atomic64_\func\()_return_cx8)
27183+.macro incdec_return func ins insc unchecked=""
27184+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
27185 CFI_STARTPROC
27186 SAVE ebx
27187
27188@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
27189 movl %edx, %ecx
27190 \ins\()l $1, %ebx
27191 \insc\()l $0, %ecx
27192+
27193+.ifb \unchecked
27194+#ifdef CONFIG_PAX_REFCOUNT
27195+ into
27196+2:
27197+ _ASM_EXTABLE(2b, 3f)
27198+#endif
27199+.endif
27200+
27201 LOCK_PREFIX
27202 cmpxchg8b (%esi)
27203 jne 1b
27204
27205-10:
27206 movl %ebx, %eax
27207 movl %ecx, %edx
27208+
27209+.ifb \unchecked
27210+#ifdef CONFIG_PAX_REFCOUNT
27211+3:
27212+#endif
27213+.endif
27214+
27215 RESTORE ebx
27216+ pax_force_retaddr
27217 ret
27218 CFI_ENDPROC
27219-ENDPROC(atomic64_\func\()_return_cx8)
27220+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
27221 .endm
27222
27223 incdec_return inc add adc
27224 incdec_return dec sub sbb
27225+incdec_return inc add adc _unchecked
27226+incdec_return dec sub sbb _unchecked
27227
27228 ENTRY(atomic64_dec_if_positive_cx8)
27229 CFI_STARTPROC
27230@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
27231 movl %edx, %ecx
27232 subl $1, %ebx
27233 sbb $0, %ecx
27234+
27235+#ifdef CONFIG_PAX_REFCOUNT
27236+ into
27237+1234:
27238+ _ASM_EXTABLE(1234b, 2f)
27239+#endif
27240+
27241 js 2f
27242 LOCK_PREFIX
27243 cmpxchg8b (%esi)
27244@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
27245 movl %ebx, %eax
27246 movl %ecx, %edx
27247 RESTORE ebx
27248+ pax_force_retaddr
27249 ret
27250 CFI_ENDPROC
27251 ENDPROC(atomic64_dec_if_positive_cx8)
27252@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
27253 movl %edx, %ecx
27254 addl %ebp, %ebx
27255 adcl %edi, %ecx
27256+
27257+#ifdef CONFIG_PAX_REFCOUNT
27258+ into
27259+1234:
27260+ _ASM_EXTABLE(1234b, 3f)
27261+#endif
27262+
27263 LOCK_PREFIX
27264 cmpxchg8b (%esi)
27265 jne 1b
27266@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
27267 CFI_ADJUST_CFA_OFFSET -8
27268 RESTORE ebx
27269 RESTORE ebp
27270+ pax_force_retaddr
27271 ret
27272 4:
27273 cmpl %edx, 4(%esp)
27274@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
27275 xorl %ecx, %ecx
27276 addl $1, %ebx
27277 adcl %edx, %ecx
27278+
27279+#ifdef CONFIG_PAX_REFCOUNT
27280+ into
27281+1234:
27282+ _ASM_EXTABLE(1234b, 3f)
27283+#endif
27284+
27285 LOCK_PREFIX
27286 cmpxchg8b (%esi)
27287 jne 1b
27288@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
27289 movl $1, %eax
27290 3:
27291 RESTORE ebx
27292+ pax_force_retaddr
27293 ret
27294 CFI_ENDPROC
27295 ENDPROC(atomic64_inc_not_zero_cx8)
27296diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
27297index e78b8ee..7e173a8 100644
27298--- a/arch/x86/lib/checksum_32.S
27299+++ b/arch/x86/lib/checksum_32.S
27300@@ -29,7 +29,8 @@
27301 #include <asm/dwarf2.h>
27302 #include <asm/errno.h>
27303 #include <asm/asm.h>
27304-
27305+#include <asm/segment.h>
27306+
27307 /*
27308 * computes a partial checksum, e.g. for TCP/UDP fragments
27309 */
27310@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
27311
27312 #define ARGBASE 16
27313 #define FP 12
27314-
27315-ENTRY(csum_partial_copy_generic)
27316+
27317+ENTRY(csum_partial_copy_generic_to_user)
27318 CFI_STARTPROC
27319+
27320+#ifdef CONFIG_PAX_MEMORY_UDEREF
27321+ pushl_cfi %gs
27322+ popl_cfi %es
27323+ jmp csum_partial_copy_generic
27324+#endif
27325+
27326+ENTRY(csum_partial_copy_generic_from_user)
27327+
27328+#ifdef CONFIG_PAX_MEMORY_UDEREF
27329+ pushl_cfi %gs
27330+ popl_cfi %ds
27331+#endif
27332+
27333+ENTRY(csum_partial_copy_generic)
27334 subl $4,%esp
27335 CFI_ADJUST_CFA_OFFSET 4
27336 pushl_cfi %edi
27337@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
27338 jmp 4f
27339 SRC(1: movw (%esi), %bx )
27340 addl $2, %esi
27341-DST( movw %bx, (%edi) )
27342+DST( movw %bx, %es:(%edi) )
27343 addl $2, %edi
27344 addw %bx, %ax
27345 adcl $0, %eax
27346@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
27347 SRC(1: movl (%esi), %ebx )
27348 SRC( movl 4(%esi), %edx )
27349 adcl %ebx, %eax
27350-DST( movl %ebx, (%edi) )
27351+DST( movl %ebx, %es:(%edi) )
27352 adcl %edx, %eax
27353-DST( movl %edx, 4(%edi) )
27354+DST( movl %edx, %es:4(%edi) )
27355
27356 SRC( movl 8(%esi), %ebx )
27357 SRC( movl 12(%esi), %edx )
27358 adcl %ebx, %eax
27359-DST( movl %ebx, 8(%edi) )
27360+DST( movl %ebx, %es:8(%edi) )
27361 adcl %edx, %eax
27362-DST( movl %edx, 12(%edi) )
27363+DST( movl %edx, %es:12(%edi) )
27364
27365 SRC( movl 16(%esi), %ebx )
27366 SRC( movl 20(%esi), %edx )
27367 adcl %ebx, %eax
27368-DST( movl %ebx, 16(%edi) )
27369+DST( movl %ebx, %es:16(%edi) )
27370 adcl %edx, %eax
27371-DST( movl %edx, 20(%edi) )
27372+DST( movl %edx, %es:20(%edi) )
27373
27374 SRC( movl 24(%esi), %ebx )
27375 SRC( movl 28(%esi), %edx )
27376 adcl %ebx, %eax
27377-DST( movl %ebx, 24(%edi) )
27378+DST( movl %ebx, %es:24(%edi) )
27379 adcl %edx, %eax
27380-DST( movl %edx, 28(%edi) )
27381+DST( movl %edx, %es:28(%edi) )
27382
27383 lea 32(%esi), %esi
27384 lea 32(%edi), %edi
27385@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
27386 shrl $2, %edx # This clears CF
27387 SRC(3: movl (%esi), %ebx )
27388 adcl %ebx, %eax
27389-DST( movl %ebx, (%edi) )
27390+DST( movl %ebx, %es:(%edi) )
27391 lea 4(%esi), %esi
27392 lea 4(%edi), %edi
27393 dec %edx
27394@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
27395 jb 5f
27396 SRC( movw (%esi), %cx )
27397 leal 2(%esi), %esi
27398-DST( movw %cx, (%edi) )
27399+DST( movw %cx, %es:(%edi) )
27400 leal 2(%edi), %edi
27401 je 6f
27402 shll $16,%ecx
27403 SRC(5: movb (%esi), %cl )
27404-DST( movb %cl, (%edi) )
27405+DST( movb %cl, %es:(%edi) )
27406 6: addl %ecx, %eax
27407 adcl $0, %eax
27408 7:
27409@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
27410
27411 6001:
27412 movl ARGBASE+20(%esp), %ebx # src_err_ptr
27413- movl $-EFAULT, (%ebx)
27414+ movl $-EFAULT, %ss:(%ebx)
27415
27416 # zero the complete destination - computing the rest
27417 # is too much work
27418@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
27419
27420 6002:
27421 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
27422- movl $-EFAULT,(%ebx)
27423+ movl $-EFAULT,%ss:(%ebx)
27424 jmp 5000b
27425
27426 .previous
27427
27428+ pushl_cfi %ss
27429+ popl_cfi %ds
27430+ pushl_cfi %ss
27431+ popl_cfi %es
27432 popl_cfi %ebx
27433 CFI_RESTORE ebx
27434 popl_cfi %esi
27435@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
27436 popl_cfi %ecx # equivalent to addl $4,%esp
27437 ret
27438 CFI_ENDPROC
27439-ENDPROC(csum_partial_copy_generic)
27440+ENDPROC(csum_partial_copy_generic_to_user)
27441
27442 #else
27443
27444 /* Version for PentiumII/PPro */
27445
27446 #define ROUND1(x) \
27447+ nop; nop; nop; \
27448 SRC(movl x(%esi), %ebx ) ; \
27449 addl %ebx, %eax ; \
27450- DST(movl %ebx, x(%edi) ) ;
27451+ DST(movl %ebx, %es:x(%edi)) ;
27452
27453 #define ROUND(x) \
27454+ nop; nop; nop; \
27455 SRC(movl x(%esi), %ebx ) ; \
27456 adcl %ebx, %eax ; \
27457- DST(movl %ebx, x(%edi) ) ;
27458+ DST(movl %ebx, %es:x(%edi)) ;
27459
27460 #define ARGBASE 12
27461-
27462-ENTRY(csum_partial_copy_generic)
27463+
27464+ENTRY(csum_partial_copy_generic_to_user)
27465 CFI_STARTPROC
27466+
27467+#ifdef CONFIG_PAX_MEMORY_UDEREF
27468+ pushl_cfi %gs
27469+ popl_cfi %es
27470+ jmp csum_partial_copy_generic
27471+#endif
27472+
27473+ENTRY(csum_partial_copy_generic_from_user)
27474+
27475+#ifdef CONFIG_PAX_MEMORY_UDEREF
27476+ pushl_cfi %gs
27477+ popl_cfi %ds
27478+#endif
27479+
27480+ENTRY(csum_partial_copy_generic)
27481 pushl_cfi %ebx
27482 CFI_REL_OFFSET ebx, 0
27483 pushl_cfi %edi
27484@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
27485 subl %ebx, %edi
27486 lea -1(%esi),%edx
27487 andl $-32,%edx
27488- lea 3f(%ebx,%ebx), %ebx
27489+ lea 3f(%ebx,%ebx,2), %ebx
27490 testl %esi, %esi
27491 jmp *%ebx
27492 1: addl $64,%esi
27493@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
27494 jb 5f
27495 SRC( movw (%esi), %dx )
27496 leal 2(%esi), %esi
27497-DST( movw %dx, (%edi) )
27498+DST( movw %dx, %es:(%edi) )
27499 leal 2(%edi), %edi
27500 je 6f
27501 shll $16,%edx
27502 5:
27503 SRC( movb (%esi), %dl )
27504-DST( movb %dl, (%edi) )
27505+DST( movb %dl, %es:(%edi) )
27506 6: addl %edx, %eax
27507 adcl $0, %eax
27508 7:
27509 .section .fixup, "ax"
27510 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
27511- movl $-EFAULT, (%ebx)
27512+ movl $-EFAULT, %ss:(%ebx)
27513 # zero the complete destination (computing the rest is too much work)
27514 movl ARGBASE+8(%esp),%edi # dst
27515 movl ARGBASE+12(%esp),%ecx # len
27516@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
27517 rep; stosb
27518 jmp 7b
27519 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
27520- movl $-EFAULT, (%ebx)
27521+ movl $-EFAULT, %ss:(%ebx)
27522 jmp 7b
27523 .previous
27524
27525+#ifdef CONFIG_PAX_MEMORY_UDEREF
27526+ pushl_cfi %ss
27527+ popl_cfi %ds
27528+ pushl_cfi %ss
27529+ popl_cfi %es
27530+#endif
27531+
27532 popl_cfi %esi
27533 CFI_RESTORE esi
27534 popl_cfi %edi
27535@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
27536 CFI_RESTORE ebx
27537 ret
27538 CFI_ENDPROC
27539-ENDPROC(csum_partial_copy_generic)
27540+ENDPROC(csum_partial_copy_generic_to_user)
27541
27542 #undef ROUND
27543 #undef ROUND1
27544diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
27545index f2145cf..cea889d 100644
27546--- a/arch/x86/lib/clear_page_64.S
27547+++ b/arch/x86/lib/clear_page_64.S
27548@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
27549 movl $4096/8,%ecx
27550 xorl %eax,%eax
27551 rep stosq
27552+ pax_force_retaddr
27553 ret
27554 CFI_ENDPROC
27555 ENDPROC(clear_page_c)
27556@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
27557 movl $4096,%ecx
27558 xorl %eax,%eax
27559 rep stosb
27560+ pax_force_retaddr
27561 ret
27562 CFI_ENDPROC
27563 ENDPROC(clear_page_c_e)
27564@@ -43,6 +45,7 @@ ENTRY(clear_page)
27565 leaq 64(%rdi),%rdi
27566 jnz .Lloop
27567 nop
27568+ pax_force_retaddr
27569 ret
27570 CFI_ENDPROC
27571 .Lclear_page_end:
27572@@ -58,7 +61,7 @@ ENDPROC(clear_page)
27573
27574 #include <asm/cpufeature.h>
27575
27576- .section .altinstr_replacement,"ax"
27577+ .section .altinstr_replacement,"a"
27578 1: .byte 0xeb /* jmp <disp8> */
27579 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
27580 2: .byte 0xeb /* jmp <disp8> */
27581diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
27582index 1e572c5..2a162cd 100644
27583--- a/arch/x86/lib/cmpxchg16b_emu.S
27584+++ b/arch/x86/lib/cmpxchg16b_emu.S
27585@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
27586
27587 popf
27588 mov $1, %al
27589+ pax_force_retaddr
27590 ret
27591
27592 not_same:
27593 popf
27594 xor %al,%al
27595+ pax_force_retaddr
27596 ret
27597
27598 CFI_ENDPROC
27599diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
27600index 176cca6..1166c50 100644
27601--- a/arch/x86/lib/copy_page_64.S
27602+++ b/arch/x86/lib/copy_page_64.S
27603@@ -9,6 +9,7 @@ copy_page_rep:
27604 CFI_STARTPROC
27605 movl $4096/8, %ecx
27606 rep movsq
27607+ pax_force_retaddr
27608 ret
27609 CFI_ENDPROC
27610 ENDPROC(copy_page_rep)
27611@@ -20,12 +21,14 @@ ENDPROC(copy_page_rep)
27612
27613 ENTRY(copy_page)
27614 CFI_STARTPROC
27615- subq $2*8, %rsp
27616- CFI_ADJUST_CFA_OFFSET 2*8
27617+ subq $3*8, %rsp
27618+ CFI_ADJUST_CFA_OFFSET 3*8
27619 movq %rbx, (%rsp)
27620 CFI_REL_OFFSET rbx, 0
27621 movq %r12, 1*8(%rsp)
27622 CFI_REL_OFFSET r12, 1*8
27623+ movq %r13, 2*8(%rsp)
27624+ CFI_REL_OFFSET r13, 2*8
27625
27626 movl $(4096/64)-5, %ecx
27627 .p2align 4
27628@@ -36,7 +39,7 @@ ENTRY(copy_page)
27629 movq 0x8*2(%rsi), %rdx
27630 movq 0x8*3(%rsi), %r8
27631 movq 0x8*4(%rsi), %r9
27632- movq 0x8*5(%rsi), %r10
27633+ movq 0x8*5(%rsi), %r13
27634 movq 0x8*6(%rsi), %r11
27635 movq 0x8*7(%rsi), %r12
27636
27637@@ -47,7 +50,7 @@ ENTRY(copy_page)
27638 movq %rdx, 0x8*2(%rdi)
27639 movq %r8, 0x8*3(%rdi)
27640 movq %r9, 0x8*4(%rdi)
27641- movq %r10, 0x8*5(%rdi)
27642+ movq %r13, 0x8*5(%rdi)
27643 movq %r11, 0x8*6(%rdi)
27644 movq %r12, 0x8*7(%rdi)
27645
27646@@ -66,7 +69,7 @@ ENTRY(copy_page)
27647 movq 0x8*2(%rsi), %rdx
27648 movq 0x8*3(%rsi), %r8
27649 movq 0x8*4(%rsi), %r9
27650- movq 0x8*5(%rsi), %r10
27651+ movq 0x8*5(%rsi), %r13
27652 movq 0x8*6(%rsi), %r11
27653 movq 0x8*7(%rsi), %r12
27654
27655@@ -75,7 +78,7 @@ ENTRY(copy_page)
27656 movq %rdx, 0x8*2(%rdi)
27657 movq %r8, 0x8*3(%rdi)
27658 movq %r9, 0x8*4(%rdi)
27659- movq %r10, 0x8*5(%rdi)
27660+ movq %r13, 0x8*5(%rdi)
27661 movq %r11, 0x8*6(%rdi)
27662 movq %r12, 0x8*7(%rdi)
27663
27664@@ -87,8 +90,11 @@ ENTRY(copy_page)
27665 CFI_RESTORE rbx
27666 movq 1*8(%rsp), %r12
27667 CFI_RESTORE r12
27668- addq $2*8, %rsp
27669- CFI_ADJUST_CFA_OFFSET -2*8
27670+ movq 2*8(%rsp), %r13
27671+ CFI_RESTORE r13
27672+ addq $3*8, %rsp
27673+ CFI_ADJUST_CFA_OFFSET -3*8
27674+ pax_force_retaddr
27675 ret
27676 .Lcopy_page_end:
27677 CFI_ENDPROC
27678@@ -99,7 +105,7 @@ ENDPROC(copy_page)
27679
27680 #include <asm/cpufeature.h>
27681
27682- .section .altinstr_replacement,"ax"
27683+ .section .altinstr_replacement,"a"
27684 1: .byte 0xeb /* jmp <disp8> */
27685 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
27686 2:
27687diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
27688index a30ca15..6b3f4e1 100644
27689--- a/arch/x86/lib/copy_user_64.S
27690+++ b/arch/x86/lib/copy_user_64.S
27691@@ -18,31 +18,7 @@
27692 #include <asm/alternative-asm.h>
27693 #include <asm/asm.h>
27694 #include <asm/smap.h>
27695-
27696-/*
27697- * By placing feature2 after feature1 in altinstructions section, we logically
27698- * implement:
27699- * If CPU has feature2, jmp to alt2 is used
27700- * else if CPU has feature1, jmp to alt1 is used
27701- * else jmp to orig is used.
27702- */
27703- .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
27704-0:
27705- .byte 0xe9 /* 32bit jump */
27706- .long \orig-1f /* by default jump to orig */
27707-1:
27708- .section .altinstr_replacement,"ax"
27709-2: .byte 0xe9 /* near jump with 32bit immediate */
27710- .long \alt1-1b /* offset */ /* or alternatively to alt1 */
27711-3: .byte 0xe9 /* near jump with 32bit immediate */
27712- .long \alt2-1b /* offset */ /* or alternatively to alt2 */
27713- .previous
27714-
27715- .section .altinstructions,"a"
27716- altinstruction_entry 0b,2b,\feature1,5,5
27717- altinstruction_entry 0b,3b,\feature2,5,5
27718- .previous
27719- .endm
27720+#include <asm/pgtable.h>
27721
27722 .macro ALIGN_DESTINATION
27723 #ifdef FIX_ALIGNMENT
27724@@ -70,52 +46,6 @@
27725 #endif
27726 .endm
27727
27728-/* Standard copy_to_user with segment limit checking */
27729-ENTRY(_copy_to_user)
27730- CFI_STARTPROC
27731- GET_THREAD_INFO(%rax)
27732- movq %rdi,%rcx
27733- addq %rdx,%rcx
27734- jc bad_to_user
27735- cmpq TI_addr_limit(%rax),%rcx
27736- ja bad_to_user
27737- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
27738- copy_user_generic_unrolled,copy_user_generic_string, \
27739- copy_user_enhanced_fast_string
27740- CFI_ENDPROC
27741-ENDPROC(_copy_to_user)
27742-
27743-/* Standard copy_from_user with segment limit checking */
27744-ENTRY(_copy_from_user)
27745- CFI_STARTPROC
27746- GET_THREAD_INFO(%rax)
27747- movq %rsi,%rcx
27748- addq %rdx,%rcx
27749- jc bad_from_user
27750- cmpq TI_addr_limit(%rax),%rcx
27751- ja bad_from_user
27752- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
27753- copy_user_generic_unrolled,copy_user_generic_string, \
27754- copy_user_enhanced_fast_string
27755- CFI_ENDPROC
27756-ENDPROC(_copy_from_user)
27757-
27758- .section .fixup,"ax"
27759- /* must zero dest */
27760-ENTRY(bad_from_user)
27761-bad_from_user:
27762- CFI_STARTPROC
27763- movl %edx,%ecx
27764- xorl %eax,%eax
27765- rep
27766- stosb
27767-bad_to_user:
27768- movl %edx,%eax
27769- ret
27770- CFI_ENDPROC
27771-ENDPROC(bad_from_user)
27772- .previous
27773-
27774 /*
27775 * copy_user_generic_unrolled - memory copy with exception handling.
27776 * This version is for CPUs like P4 that don't have efficient micro
27777@@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
27778 */
27779 ENTRY(copy_user_generic_unrolled)
27780 CFI_STARTPROC
27781+ ASM_PAX_OPEN_USERLAND
27782 ASM_STAC
27783 cmpl $8,%edx
27784 jb 20f /* less then 8 bytes, go to byte copy loop */
27785@@ -141,19 +72,19 @@ ENTRY(copy_user_generic_unrolled)
27786 jz 17f
27787 1: movq (%rsi),%r8
27788 2: movq 1*8(%rsi),%r9
27789-3: movq 2*8(%rsi),%r10
27790+3: movq 2*8(%rsi),%rax
27791 4: movq 3*8(%rsi),%r11
27792 5: movq %r8,(%rdi)
27793 6: movq %r9,1*8(%rdi)
27794-7: movq %r10,2*8(%rdi)
27795+7: movq %rax,2*8(%rdi)
27796 8: movq %r11,3*8(%rdi)
27797 9: movq 4*8(%rsi),%r8
27798 10: movq 5*8(%rsi),%r9
27799-11: movq 6*8(%rsi),%r10
27800+11: movq 6*8(%rsi),%rax
27801 12: movq 7*8(%rsi),%r11
27802 13: movq %r8,4*8(%rdi)
27803 14: movq %r9,5*8(%rdi)
27804-15: movq %r10,6*8(%rdi)
27805+15: movq %rax,6*8(%rdi)
27806 16: movq %r11,7*8(%rdi)
27807 leaq 64(%rsi),%rsi
27808 leaq 64(%rdi),%rdi
27809@@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
27810 jnz 21b
27811 23: xor %eax,%eax
27812 ASM_CLAC
27813+ ASM_PAX_CLOSE_USERLAND
27814+ pax_force_retaddr
27815 ret
27816
27817 .section .fixup,"ax"
27818@@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
27819 */
27820 ENTRY(copy_user_generic_string)
27821 CFI_STARTPROC
27822+ ASM_PAX_OPEN_USERLAND
27823 ASM_STAC
27824 andl %edx,%edx
27825 jz 4f
27826@@ -251,6 +185,8 @@ ENTRY(copy_user_generic_string)
27827 movsb
27828 4: xorl %eax,%eax
27829 ASM_CLAC
27830+ ASM_PAX_CLOSE_USERLAND
27831+ pax_force_retaddr
27832 ret
27833
27834 .section .fixup,"ax"
27835@@ -278,6 +214,7 @@ ENDPROC(copy_user_generic_string)
27836 */
27837 ENTRY(copy_user_enhanced_fast_string)
27838 CFI_STARTPROC
27839+ ASM_PAX_OPEN_USERLAND
27840 ASM_STAC
27841 andl %edx,%edx
27842 jz 2f
27843@@ -286,6 +223,8 @@ ENTRY(copy_user_enhanced_fast_string)
27844 movsb
27845 2: xorl %eax,%eax
27846 ASM_CLAC
27847+ ASM_PAX_CLOSE_USERLAND
27848+ pax_force_retaddr
27849 ret
27850
27851 .section .fixup,"ax"
27852diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
27853index 6a4f43c..55d26f2 100644
27854--- a/arch/x86/lib/copy_user_nocache_64.S
27855+++ b/arch/x86/lib/copy_user_nocache_64.S
27856@@ -8,6 +8,7 @@
27857
27858 #include <linux/linkage.h>
27859 #include <asm/dwarf2.h>
27860+#include <asm/alternative-asm.h>
27861
27862 #define FIX_ALIGNMENT 1
27863
27864@@ -16,6 +17,7 @@
27865 #include <asm/thread_info.h>
27866 #include <asm/asm.h>
27867 #include <asm/smap.h>
27868+#include <asm/pgtable.h>
27869
27870 .macro ALIGN_DESTINATION
27871 #ifdef FIX_ALIGNMENT
27872@@ -49,6 +51,16 @@
27873 */
27874 ENTRY(__copy_user_nocache)
27875 CFI_STARTPROC
27876+
27877+#ifdef CONFIG_PAX_MEMORY_UDEREF
27878+ mov pax_user_shadow_base,%rcx
27879+ cmp %rcx,%rsi
27880+ jae 1f
27881+ add %rcx,%rsi
27882+1:
27883+#endif
27884+
27885+ ASM_PAX_OPEN_USERLAND
27886 ASM_STAC
27887 cmpl $8,%edx
27888 jb 20f /* less then 8 bytes, go to byte copy loop */
27889@@ -59,19 +71,19 @@ ENTRY(__copy_user_nocache)
27890 jz 17f
27891 1: movq (%rsi),%r8
27892 2: movq 1*8(%rsi),%r9
27893-3: movq 2*8(%rsi),%r10
27894+3: movq 2*8(%rsi),%rax
27895 4: movq 3*8(%rsi),%r11
27896 5: movnti %r8,(%rdi)
27897 6: movnti %r9,1*8(%rdi)
27898-7: movnti %r10,2*8(%rdi)
27899+7: movnti %rax,2*8(%rdi)
27900 8: movnti %r11,3*8(%rdi)
27901 9: movq 4*8(%rsi),%r8
27902 10: movq 5*8(%rsi),%r9
27903-11: movq 6*8(%rsi),%r10
27904+11: movq 6*8(%rsi),%rax
27905 12: movq 7*8(%rsi),%r11
27906 13: movnti %r8,4*8(%rdi)
27907 14: movnti %r9,5*8(%rdi)
27908-15: movnti %r10,6*8(%rdi)
27909+15: movnti %rax,6*8(%rdi)
27910 16: movnti %r11,7*8(%rdi)
27911 leaq 64(%rsi),%rsi
27912 leaq 64(%rdi),%rdi
27913@@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
27914 jnz 21b
27915 23: xorl %eax,%eax
27916 ASM_CLAC
27917+ ASM_PAX_CLOSE_USERLAND
27918 sfence
27919+ pax_force_retaddr
27920 ret
27921
27922 .section .fixup,"ax"
27923diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
27924index 2419d5f..953ee51 100644
27925--- a/arch/x86/lib/csum-copy_64.S
27926+++ b/arch/x86/lib/csum-copy_64.S
27927@@ -9,6 +9,7 @@
27928 #include <asm/dwarf2.h>
27929 #include <asm/errno.h>
27930 #include <asm/asm.h>
27931+#include <asm/alternative-asm.h>
27932
27933 /*
27934 * Checksum copy with exception handling.
27935@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
27936 CFI_RESTORE rbp
27937 addq $7*8, %rsp
27938 CFI_ADJUST_CFA_OFFSET -7*8
27939+ pax_force_retaddr 0, 1
27940 ret
27941 CFI_RESTORE_STATE
27942
27943diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
27944index 25b7ae8..c40113e 100644
27945--- a/arch/x86/lib/csum-wrappers_64.c
27946+++ b/arch/x86/lib/csum-wrappers_64.c
27947@@ -52,8 +52,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
27948 len -= 2;
27949 }
27950 }
27951- isum = csum_partial_copy_generic((__force const void *)src,
27952+ pax_open_userland();
27953+ stac();
27954+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
27955 dst, len, isum, errp, NULL);
27956+ clac();
27957+ pax_close_userland();
27958 if (unlikely(*errp))
27959 goto out_err;
27960
27961@@ -105,8 +109,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
27962 }
27963
27964 *errp = 0;
27965- return csum_partial_copy_generic(src, (void __force *)dst,
27966+ pax_open_userland();
27967+ stac();
27968+ isum = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
27969 len, isum, NULL, errp);
27970+ clac();
27971+ pax_close_userland();
27972+ return isum;
27973 }
27974 EXPORT_SYMBOL(csum_partial_copy_to_user);
27975
27976diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
27977index a451235..1daa956 100644
27978--- a/arch/x86/lib/getuser.S
27979+++ b/arch/x86/lib/getuser.S
27980@@ -33,17 +33,40 @@
27981 #include <asm/thread_info.h>
27982 #include <asm/asm.h>
27983 #include <asm/smap.h>
27984+#include <asm/segment.h>
27985+#include <asm/pgtable.h>
27986+#include <asm/alternative-asm.h>
27987+
27988+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
27989+#define __copyuser_seg gs;
27990+#else
27991+#define __copyuser_seg
27992+#endif
27993
27994 .text
27995 ENTRY(__get_user_1)
27996 CFI_STARTPROC
27997+
27998+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
27999 GET_THREAD_INFO(%_ASM_DX)
28000 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28001 jae bad_get_user
28002 ASM_STAC
28003-1: movzbl (%_ASM_AX),%edx
28004+
28005+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28006+ mov pax_user_shadow_base,%_ASM_DX
28007+ cmp %_ASM_DX,%_ASM_AX
28008+ jae 1234f
28009+ add %_ASM_DX,%_ASM_AX
28010+1234:
28011+#endif
28012+
28013+#endif
28014+
28015+1: __copyuser_seg movzbl (%_ASM_AX),%edx
28016 xor %eax,%eax
28017 ASM_CLAC
28018+ pax_force_retaddr
28019 ret
28020 CFI_ENDPROC
28021 ENDPROC(__get_user_1)
28022@@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
28023 ENTRY(__get_user_2)
28024 CFI_STARTPROC
28025 add $1,%_ASM_AX
28026+
28027+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28028 jc bad_get_user
28029 GET_THREAD_INFO(%_ASM_DX)
28030 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28031 jae bad_get_user
28032 ASM_STAC
28033-2: movzwl -1(%_ASM_AX),%edx
28034+
28035+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28036+ mov pax_user_shadow_base,%_ASM_DX
28037+ cmp %_ASM_DX,%_ASM_AX
28038+ jae 1234f
28039+ add %_ASM_DX,%_ASM_AX
28040+1234:
28041+#endif
28042+
28043+#endif
28044+
28045+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
28046 xor %eax,%eax
28047 ASM_CLAC
28048+ pax_force_retaddr
28049 ret
28050 CFI_ENDPROC
28051 ENDPROC(__get_user_2)
28052@@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
28053 ENTRY(__get_user_4)
28054 CFI_STARTPROC
28055 add $3,%_ASM_AX
28056+
28057+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28058 jc bad_get_user
28059 GET_THREAD_INFO(%_ASM_DX)
28060 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28061 jae bad_get_user
28062 ASM_STAC
28063-3: movl -3(%_ASM_AX),%edx
28064+
28065+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28066+ mov pax_user_shadow_base,%_ASM_DX
28067+ cmp %_ASM_DX,%_ASM_AX
28068+ jae 1234f
28069+ add %_ASM_DX,%_ASM_AX
28070+1234:
28071+#endif
28072+
28073+#endif
28074+
28075+3: __copyuser_seg movl -3(%_ASM_AX),%edx
28076 xor %eax,%eax
28077 ASM_CLAC
28078+ pax_force_retaddr
28079 ret
28080 CFI_ENDPROC
28081 ENDPROC(__get_user_4)
28082@@ -86,10 +137,20 @@ ENTRY(__get_user_8)
28083 GET_THREAD_INFO(%_ASM_DX)
28084 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28085 jae bad_get_user
28086+
28087+#ifdef CONFIG_PAX_MEMORY_UDEREF
28088+ mov pax_user_shadow_base,%_ASM_DX
28089+ cmp %_ASM_DX,%_ASM_AX
28090+ jae 1234f
28091+ add %_ASM_DX,%_ASM_AX
28092+1234:
28093+#endif
28094+
28095 ASM_STAC
28096 4: movq -7(%_ASM_AX),%rdx
28097 xor %eax,%eax
28098 ASM_CLAC
28099+ pax_force_retaddr
28100 ret
28101 #else
28102 add $7,%_ASM_AX
28103@@ -98,10 +159,11 @@ ENTRY(__get_user_8)
28104 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
28105 jae bad_get_user_8
28106 ASM_STAC
28107-4: movl -7(%_ASM_AX),%edx
28108-5: movl -3(%_ASM_AX),%ecx
28109+4: __copyuser_seg movl -7(%_ASM_AX),%edx
28110+5: __copyuser_seg movl -3(%_ASM_AX),%ecx
28111 xor %eax,%eax
28112 ASM_CLAC
28113+ pax_force_retaddr
28114 ret
28115 #endif
28116 CFI_ENDPROC
28117@@ -113,6 +175,7 @@ bad_get_user:
28118 xor %edx,%edx
28119 mov $(-EFAULT),%_ASM_AX
28120 ASM_CLAC
28121+ pax_force_retaddr
28122 ret
28123 CFI_ENDPROC
28124 END(bad_get_user)
28125@@ -124,6 +187,7 @@ bad_get_user_8:
28126 xor %ecx,%ecx
28127 mov $(-EFAULT),%_ASM_AX
28128 ASM_CLAC
28129+ pax_force_retaddr
28130 ret
28131 CFI_ENDPROC
28132 END(bad_get_user_8)
28133diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
28134index 54fcffe..7be149e 100644
28135--- a/arch/x86/lib/insn.c
28136+++ b/arch/x86/lib/insn.c
28137@@ -20,8 +20,10 @@
28138
28139 #ifdef __KERNEL__
28140 #include <linux/string.h>
28141+#include <asm/pgtable_types.h>
28142 #else
28143 #include <string.h>
28144+#define ktla_ktva(addr) addr
28145 #endif
28146 #include <asm/inat.h>
28147 #include <asm/insn.h>
28148@@ -53,8 +55,8 @@
28149 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
28150 {
28151 memset(insn, 0, sizeof(*insn));
28152- insn->kaddr = kaddr;
28153- insn->next_byte = kaddr;
28154+ insn->kaddr = ktla_ktva(kaddr);
28155+ insn->next_byte = ktla_ktva(kaddr);
28156 insn->x86_64 = x86_64 ? 1 : 0;
28157 insn->opnd_bytes = 4;
28158 if (x86_64)
28159diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
28160index 05a95e7..326f2fa 100644
28161--- a/arch/x86/lib/iomap_copy_64.S
28162+++ b/arch/x86/lib/iomap_copy_64.S
28163@@ -17,6 +17,7 @@
28164
28165 #include <linux/linkage.h>
28166 #include <asm/dwarf2.h>
28167+#include <asm/alternative-asm.h>
28168
28169 /*
28170 * override generic version in lib/iomap_copy.c
28171@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
28172 CFI_STARTPROC
28173 movl %edx,%ecx
28174 rep movsd
28175+ pax_force_retaddr
28176 ret
28177 CFI_ENDPROC
28178 ENDPROC(__iowrite32_copy)
28179diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
28180index 56313a3..9b59269 100644
28181--- a/arch/x86/lib/memcpy_64.S
28182+++ b/arch/x86/lib/memcpy_64.S
28183@@ -24,7 +24,7 @@
28184 * This gets patched over the unrolled variant (below) via the
28185 * alternative instructions framework:
28186 */
28187- .section .altinstr_replacement, "ax", @progbits
28188+ .section .altinstr_replacement, "a", @progbits
28189 .Lmemcpy_c:
28190 movq %rdi, %rax
28191 movq %rdx, %rcx
28192@@ -33,6 +33,7 @@
28193 rep movsq
28194 movl %edx, %ecx
28195 rep movsb
28196+ pax_force_retaddr
28197 ret
28198 .Lmemcpy_e:
28199 .previous
28200@@ -44,11 +45,12 @@
28201 * This gets patched over the unrolled variant (below) via the
28202 * alternative instructions framework:
28203 */
28204- .section .altinstr_replacement, "ax", @progbits
28205+ .section .altinstr_replacement, "a", @progbits
28206 .Lmemcpy_c_e:
28207 movq %rdi, %rax
28208 movq %rdx, %rcx
28209 rep movsb
28210+ pax_force_retaddr
28211 ret
28212 .Lmemcpy_e_e:
28213 .previous
28214@@ -76,13 +78,13 @@ ENTRY(memcpy)
28215 */
28216 movq 0*8(%rsi), %r8
28217 movq 1*8(%rsi), %r9
28218- movq 2*8(%rsi), %r10
28219+ movq 2*8(%rsi), %rcx
28220 movq 3*8(%rsi), %r11
28221 leaq 4*8(%rsi), %rsi
28222
28223 movq %r8, 0*8(%rdi)
28224 movq %r9, 1*8(%rdi)
28225- movq %r10, 2*8(%rdi)
28226+ movq %rcx, 2*8(%rdi)
28227 movq %r11, 3*8(%rdi)
28228 leaq 4*8(%rdi), %rdi
28229 jae .Lcopy_forward_loop
28230@@ -105,12 +107,12 @@ ENTRY(memcpy)
28231 subq $0x20, %rdx
28232 movq -1*8(%rsi), %r8
28233 movq -2*8(%rsi), %r9
28234- movq -3*8(%rsi), %r10
28235+ movq -3*8(%rsi), %rcx
28236 movq -4*8(%rsi), %r11
28237 leaq -4*8(%rsi), %rsi
28238 movq %r8, -1*8(%rdi)
28239 movq %r9, -2*8(%rdi)
28240- movq %r10, -3*8(%rdi)
28241+ movq %rcx, -3*8(%rdi)
28242 movq %r11, -4*8(%rdi)
28243 leaq -4*8(%rdi), %rdi
28244 jae .Lcopy_backward_loop
28245@@ -130,12 +132,13 @@ ENTRY(memcpy)
28246 */
28247 movq 0*8(%rsi), %r8
28248 movq 1*8(%rsi), %r9
28249- movq -2*8(%rsi, %rdx), %r10
28250+ movq -2*8(%rsi, %rdx), %rcx
28251 movq -1*8(%rsi, %rdx), %r11
28252 movq %r8, 0*8(%rdi)
28253 movq %r9, 1*8(%rdi)
28254- movq %r10, -2*8(%rdi, %rdx)
28255+ movq %rcx, -2*8(%rdi, %rdx)
28256 movq %r11, -1*8(%rdi, %rdx)
28257+ pax_force_retaddr
28258 retq
28259 .p2align 4
28260 .Lless_16bytes:
28261@@ -148,6 +151,7 @@ ENTRY(memcpy)
28262 movq -1*8(%rsi, %rdx), %r9
28263 movq %r8, 0*8(%rdi)
28264 movq %r9, -1*8(%rdi, %rdx)
28265+ pax_force_retaddr
28266 retq
28267 .p2align 4
28268 .Lless_8bytes:
28269@@ -161,6 +165,7 @@ ENTRY(memcpy)
28270 movl -4(%rsi, %rdx), %r8d
28271 movl %ecx, (%rdi)
28272 movl %r8d, -4(%rdi, %rdx)
28273+ pax_force_retaddr
28274 retq
28275 .p2align 4
28276 .Lless_3bytes:
28277@@ -179,6 +184,7 @@ ENTRY(memcpy)
28278 movb %cl, (%rdi)
28279
28280 .Lend:
28281+ pax_force_retaddr
28282 retq
28283 CFI_ENDPROC
28284 ENDPROC(memcpy)
28285diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
28286index 65268a6..5aa7815 100644
28287--- a/arch/x86/lib/memmove_64.S
28288+++ b/arch/x86/lib/memmove_64.S
28289@@ -61,13 +61,13 @@ ENTRY(memmove)
28290 5:
28291 sub $0x20, %rdx
28292 movq 0*8(%rsi), %r11
28293- movq 1*8(%rsi), %r10
28294+ movq 1*8(%rsi), %rcx
28295 movq 2*8(%rsi), %r9
28296 movq 3*8(%rsi), %r8
28297 leaq 4*8(%rsi), %rsi
28298
28299 movq %r11, 0*8(%rdi)
28300- movq %r10, 1*8(%rdi)
28301+ movq %rcx, 1*8(%rdi)
28302 movq %r9, 2*8(%rdi)
28303 movq %r8, 3*8(%rdi)
28304 leaq 4*8(%rdi), %rdi
28305@@ -81,10 +81,10 @@ ENTRY(memmove)
28306 4:
28307 movq %rdx, %rcx
28308 movq -8(%rsi, %rdx), %r11
28309- lea -8(%rdi, %rdx), %r10
28310+ lea -8(%rdi, %rdx), %r9
28311 shrq $3, %rcx
28312 rep movsq
28313- movq %r11, (%r10)
28314+ movq %r11, (%r9)
28315 jmp 13f
28316 .Lmemmove_end_forward:
28317
28318@@ -95,14 +95,14 @@ ENTRY(memmove)
28319 7:
28320 movq %rdx, %rcx
28321 movq (%rsi), %r11
28322- movq %rdi, %r10
28323+ movq %rdi, %r9
28324 leaq -8(%rsi, %rdx), %rsi
28325 leaq -8(%rdi, %rdx), %rdi
28326 shrq $3, %rcx
28327 std
28328 rep movsq
28329 cld
28330- movq %r11, (%r10)
28331+ movq %r11, (%r9)
28332 jmp 13f
28333
28334 /*
28335@@ -127,13 +127,13 @@ ENTRY(memmove)
28336 8:
28337 subq $0x20, %rdx
28338 movq -1*8(%rsi), %r11
28339- movq -2*8(%rsi), %r10
28340+ movq -2*8(%rsi), %rcx
28341 movq -3*8(%rsi), %r9
28342 movq -4*8(%rsi), %r8
28343 leaq -4*8(%rsi), %rsi
28344
28345 movq %r11, -1*8(%rdi)
28346- movq %r10, -2*8(%rdi)
28347+ movq %rcx, -2*8(%rdi)
28348 movq %r9, -3*8(%rdi)
28349 movq %r8, -4*8(%rdi)
28350 leaq -4*8(%rdi), %rdi
28351@@ -151,11 +151,11 @@ ENTRY(memmove)
28352 * Move data from 16 bytes to 31 bytes.
28353 */
28354 movq 0*8(%rsi), %r11
28355- movq 1*8(%rsi), %r10
28356+ movq 1*8(%rsi), %rcx
28357 movq -2*8(%rsi, %rdx), %r9
28358 movq -1*8(%rsi, %rdx), %r8
28359 movq %r11, 0*8(%rdi)
28360- movq %r10, 1*8(%rdi)
28361+ movq %rcx, 1*8(%rdi)
28362 movq %r9, -2*8(%rdi, %rdx)
28363 movq %r8, -1*8(%rdi, %rdx)
28364 jmp 13f
28365@@ -167,9 +167,9 @@ ENTRY(memmove)
28366 * Move data from 8 bytes to 15 bytes.
28367 */
28368 movq 0*8(%rsi), %r11
28369- movq -1*8(%rsi, %rdx), %r10
28370+ movq -1*8(%rsi, %rdx), %r9
28371 movq %r11, 0*8(%rdi)
28372- movq %r10, -1*8(%rdi, %rdx)
28373+ movq %r9, -1*8(%rdi, %rdx)
28374 jmp 13f
28375 10:
28376 cmpq $4, %rdx
28377@@ -178,9 +178,9 @@ ENTRY(memmove)
28378 * Move data from 4 bytes to 7 bytes.
28379 */
28380 movl (%rsi), %r11d
28381- movl -4(%rsi, %rdx), %r10d
28382+ movl -4(%rsi, %rdx), %r9d
28383 movl %r11d, (%rdi)
28384- movl %r10d, -4(%rdi, %rdx)
28385+ movl %r9d, -4(%rdi, %rdx)
28386 jmp 13f
28387 11:
28388 cmp $2, %rdx
28389@@ -189,9 +189,9 @@ ENTRY(memmove)
28390 * Move data from 2 bytes to 3 bytes.
28391 */
28392 movw (%rsi), %r11w
28393- movw -2(%rsi, %rdx), %r10w
28394+ movw -2(%rsi, %rdx), %r9w
28395 movw %r11w, (%rdi)
28396- movw %r10w, -2(%rdi, %rdx)
28397+ movw %r9w, -2(%rdi, %rdx)
28398 jmp 13f
28399 12:
28400 cmp $1, %rdx
28401@@ -202,14 +202,16 @@ ENTRY(memmove)
28402 movb (%rsi), %r11b
28403 movb %r11b, (%rdi)
28404 13:
28405+ pax_force_retaddr
28406 retq
28407 CFI_ENDPROC
28408
28409- .section .altinstr_replacement,"ax"
28410+ .section .altinstr_replacement,"a"
28411 .Lmemmove_begin_forward_efs:
28412 /* Forward moving data. */
28413 movq %rdx, %rcx
28414 rep movsb
28415+ pax_force_retaddr
28416 retq
28417 .Lmemmove_end_forward_efs:
28418 .previous
28419diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
28420index 2dcb380..50a78bc 100644
28421--- a/arch/x86/lib/memset_64.S
28422+++ b/arch/x86/lib/memset_64.S
28423@@ -16,7 +16,7 @@
28424 *
28425 * rax original destination
28426 */
28427- .section .altinstr_replacement, "ax", @progbits
28428+ .section .altinstr_replacement, "a", @progbits
28429 .Lmemset_c:
28430 movq %rdi,%r9
28431 movq %rdx,%rcx
28432@@ -30,6 +30,7 @@
28433 movl %edx,%ecx
28434 rep stosb
28435 movq %r9,%rax
28436+ pax_force_retaddr
28437 ret
28438 .Lmemset_e:
28439 .previous
28440@@ -45,13 +46,14 @@
28441 *
28442 * rax original destination
28443 */
28444- .section .altinstr_replacement, "ax", @progbits
28445+ .section .altinstr_replacement, "a", @progbits
28446 .Lmemset_c_e:
28447 movq %rdi,%r9
28448 movb %sil,%al
28449 movq %rdx,%rcx
28450 rep stosb
28451 movq %r9,%rax
28452+ pax_force_retaddr
28453 ret
28454 .Lmemset_e_e:
28455 .previous
28456@@ -59,7 +61,7 @@
28457 ENTRY(memset)
28458 ENTRY(__memset)
28459 CFI_STARTPROC
28460- movq %rdi,%r10
28461+ movq %rdi,%r11
28462
28463 /* expand byte value */
28464 movzbl %sil,%ecx
28465@@ -117,7 +119,8 @@ ENTRY(__memset)
28466 jnz .Lloop_1
28467
28468 .Lende:
28469- movq %r10,%rax
28470+ movq %r11,%rax
28471+ pax_force_retaddr
28472 ret
28473
28474 CFI_RESTORE_STATE
28475diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
28476index c9f2d9b..e7fd2c0 100644
28477--- a/arch/x86/lib/mmx_32.c
28478+++ b/arch/x86/lib/mmx_32.c
28479@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
28480 {
28481 void *p;
28482 int i;
28483+ unsigned long cr0;
28484
28485 if (unlikely(in_interrupt()))
28486 return __memcpy(to, from, len);
28487@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
28488 kernel_fpu_begin();
28489
28490 __asm__ __volatile__ (
28491- "1: prefetch (%0)\n" /* This set is 28 bytes */
28492- " prefetch 64(%0)\n"
28493- " prefetch 128(%0)\n"
28494- " prefetch 192(%0)\n"
28495- " prefetch 256(%0)\n"
28496+ "1: prefetch (%1)\n" /* This set is 28 bytes */
28497+ " prefetch 64(%1)\n"
28498+ " prefetch 128(%1)\n"
28499+ " prefetch 192(%1)\n"
28500+ " prefetch 256(%1)\n"
28501 "2: \n"
28502 ".section .fixup, \"ax\"\n"
28503- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28504+ "3: \n"
28505+
28506+#ifdef CONFIG_PAX_KERNEXEC
28507+ " movl %%cr0, %0\n"
28508+ " movl %0, %%eax\n"
28509+ " andl $0xFFFEFFFF, %%eax\n"
28510+ " movl %%eax, %%cr0\n"
28511+#endif
28512+
28513+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28514+
28515+#ifdef CONFIG_PAX_KERNEXEC
28516+ " movl %0, %%cr0\n"
28517+#endif
28518+
28519 " jmp 2b\n"
28520 ".previous\n"
28521 _ASM_EXTABLE(1b, 3b)
28522- : : "r" (from));
28523+ : "=&r" (cr0) : "r" (from) : "ax");
28524
28525 for ( ; i > 5; i--) {
28526 __asm__ __volatile__ (
28527- "1: prefetch 320(%0)\n"
28528- "2: movq (%0), %%mm0\n"
28529- " movq 8(%0), %%mm1\n"
28530- " movq 16(%0), %%mm2\n"
28531- " movq 24(%0), %%mm3\n"
28532- " movq %%mm0, (%1)\n"
28533- " movq %%mm1, 8(%1)\n"
28534- " movq %%mm2, 16(%1)\n"
28535- " movq %%mm3, 24(%1)\n"
28536- " movq 32(%0), %%mm0\n"
28537- " movq 40(%0), %%mm1\n"
28538- " movq 48(%0), %%mm2\n"
28539- " movq 56(%0), %%mm3\n"
28540- " movq %%mm0, 32(%1)\n"
28541- " movq %%mm1, 40(%1)\n"
28542- " movq %%mm2, 48(%1)\n"
28543- " movq %%mm3, 56(%1)\n"
28544+ "1: prefetch 320(%1)\n"
28545+ "2: movq (%1), %%mm0\n"
28546+ " movq 8(%1), %%mm1\n"
28547+ " movq 16(%1), %%mm2\n"
28548+ " movq 24(%1), %%mm3\n"
28549+ " movq %%mm0, (%2)\n"
28550+ " movq %%mm1, 8(%2)\n"
28551+ " movq %%mm2, 16(%2)\n"
28552+ " movq %%mm3, 24(%2)\n"
28553+ " movq 32(%1), %%mm0\n"
28554+ " movq 40(%1), %%mm1\n"
28555+ " movq 48(%1), %%mm2\n"
28556+ " movq 56(%1), %%mm3\n"
28557+ " movq %%mm0, 32(%2)\n"
28558+ " movq %%mm1, 40(%2)\n"
28559+ " movq %%mm2, 48(%2)\n"
28560+ " movq %%mm3, 56(%2)\n"
28561 ".section .fixup, \"ax\"\n"
28562- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28563+ "3:\n"
28564+
28565+#ifdef CONFIG_PAX_KERNEXEC
28566+ " movl %%cr0, %0\n"
28567+ " movl %0, %%eax\n"
28568+ " andl $0xFFFEFFFF, %%eax\n"
28569+ " movl %%eax, %%cr0\n"
28570+#endif
28571+
28572+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28573+
28574+#ifdef CONFIG_PAX_KERNEXEC
28575+ " movl %0, %%cr0\n"
28576+#endif
28577+
28578 " jmp 2b\n"
28579 ".previous\n"
28580 _ASM_EXTABLE(1b, 3b)
28581- : : "r" (from), "r" (to) : "memory");
28582+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
28583
28584 from += 64;
28585 to += 64;
28586@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
28587 static void fast_copy_page(void *to, void *from)
28588 {
28589 int i;
28590+ unsigned long cr0;
28591
28592 kernel_fpu_begin();
28593
28594@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
28595 * but that is for later. -AV
28596 */
28597 __asm__ __volatile__(
28598- "1: prefetch (%0)\n"
28599- " prefetch 64(%0)\n"
28600- " prefetch 128(%0)\n"
28601- " prefetch 192(%0)\n"
28602- " prefetch 256(%0)\n"
28603+ "1: prefetch (%1)\n"
28604+ " prefetch 64(%1)\n"
28605+ " prefetch 128(%1)\n"
28606+ " prefetch 192(%1)\n"
28607+ " prefetch 256(%1)\n"
28608 "2: \n"
28609 ".section .fixup, \"ax\"\n"
28610- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28611+ "3: \n"
28612+
28613+#ifdef CONFIG_PAX_KERNEXEC
28614+ " movl %%cr0, %0\n"
28615+ " movl %0, %%eax\n"
28616+ " andl $0xFFFEFFFF, %%eax\n"
28617+ " movl %%eax, %%cr0\n"
28618+#endif
28619+
28620+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28621+
28622+#ifdef CONFIG_PAX_KERNEXEC
28623+ " movl %0, %%cr0\n"
28624+#endif
28625+
28626 " jmp 2b\n"
28627 ".previous\n"
28628- _ASM_EXTABLE(1b, 3b) : : "r" (from));
28629+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
28630
28631 for (i = 0; i < (4096-320)/64; i++) {
28632 __asm__ __volatile__ (
28633- "1: prefetch 320(%0)\n"
28634- "2: movq (%0), %%mm0\n"
28635- " movntq %%mm0, (%1)\n"
28636- " movq 8(%0), %%mm1\n"
28637- " movntq %%mm1, 8(%1)\n"
28638- " movq 16(%0), %%mm2\n"
28639- " movntq %%mm2, 16(%1)\n"
28640- " movq 24(%0), %%mm3\n"
28641- " movntq %%mm3, 24(%1)\n"
28642- " movq 32(%0), %%mm4\n"
28643- " movntq %%mm4, 32(%1)\n"
28644- " movq 40(%0), %%mm5\n"
28645- " movntq %%mm5, 40(%1)\n"
28646- " movq 48(%0), %%mm6\n"
28647- " movntq %%mm6, 48(%1)\n"
28648- " movq 56(%0), %%mm7\n"
28649- " movntq %%mm7, 56(%1)\n"
28650+ "1: prefetch 320(%1)\n"
28651+ "2: movq (%1), %%mm0\n"
28652+ " movntq %%mm0, (%2)\n"
28653+ " movq 8(%1), %%mm1\n"
28654+ " movntq %%mm1, 8(%2)\n"
28655+ " movq 16(%1), %%mm2\n"
28656+ " movntq %%mm2, 16(%2)\n"
28657+ " movq 24(%1), %%mm3\n"
28658+ " movntq %%mm3, 24(%2)\n"
28659+ " movq 32(%1), %%mm4\n"
28660+ " movntq %%mm4, 32(%2)\n"
28661+ " movq 40(%1), %%mm5\n"
28662+ " movntq %%mm5, 40(%2)\n"
28663+ " movq 48(%1), %%mm6\n"
28664+ " movntq %%mm6, 48(%2)\n"
28665+ " movq 56(%1), %%mm7\n"
28666+ " movntq %%mm7, 56(%2)\n"
28667 ".section .fixup, \"ax\"\n"
28668- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28669+ "3:\n"
28670+
28671+#ifdef CONFIG_PAX_KERNEXEC
28672+ " movl %%cr0, %0\n"
28673+ " movl %0, %%eax\n"
28674+ " andl $0xFFFEFFFF, %%eax\n"
28675+ " movl %%eax, %%cr0\n"
28676+#endif
28677+
28678+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28679+
28680+#ifdef CONFIG_PAX_KERNEXEC
28681+ " movl %0, %%cr0\n"
28682+#endif
28683+
28684 " jmp 2b\n"
28685 ".previous\n"
28686- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
28687+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
28688
28689 from += 64;
28690 to += 64;
28691@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
28692 static void fast_copy_page(void *to, void *from)
28693 {
28694 int i;
28695+ unsigned long cr0;
28696
28697 kernel_fpu_begin();
28698
28699 __asm__ __volatile__ (
28700- "1: prefetch (%0)\n"
28701- " prefetch 64(%0)\n"
28702- " prefetch 128(%0)\n"
28703- " prefetch 192(%0)\n"
28704- " prefetch 256(%0)\n"
28705+ "1: prefetch (%1)\n"
28706+ " prefetch 64(%1)\n"
28707+ " prefetch 128(%1)\n"
28708+ " prefetch 192(%1)\n"
28709+ " prefetch 256(%1)\n"
28710 "2: \n"
28711 ".section .fixup, \"ax\"\n"
28712- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28713+ "3: \n"
28714+
28715+#ifdef CONFIG_PAX_KERNEXEC
28716+ " movl %%cr0, %0\n"
28717+ " movl %0, %%eax\n"
28718+ " andl $0xFFFEFFFF, %%eax\n"
28719+ " movl %%eax, %%cr0\n"
28720+#endif
28721+
28722+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
28723+
28724+#ifdef CONFIG_PAX_KERNEXEC
28725+ " movl %0, %%cr0\n"
28726+#endif
28727+
28728 " jmp 2b\n"
28729 ".previous\n"
28730- _ASM_EXTABLE(1b, 3b) : : "r" (from));
28731+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
28732
28733 for (i = 0; i < 4096/64; i++) {
28734 __asm__ __volatile__ (
28735- "1: prefetch 320(%0)\n"
28736- "2: movq (%0), %%mm0\n"
28737- " movq 8(%0), %%mm1\n"
28738- " movq 16(%0), %%mm2\n"
28739- " movq 24(%0), %%mm3\n"
28740- " movq %%mm0, (%1)\n"
28741- " movq %%mm1, 8(%1)\n"
28742- " movq %%mm2, 16(%1)\n"
28743- " movq %%mm3, 24(%1)\n"
28744- " movq 32(%0), %%mm0\n"
28745- " movq 40(%0), %%mm1\n"
28746- " movq 48(%0), %%mm2\n"
28747- " movq 56(%0), %%mm3\n"
28748- " movq %%mm0, 32(%1)\n"
28749- " movq %%mm1, 40(%1)\n"
28750- " movq %%mm2, 48(%1)\n"
28751- " movq %%mm3, 56(%1)\n"
28752+ "1: prefetch 320(%1)\n"
28753+ "2: movq (%1), %%mm0\n"
28754+ " movq 8(%1), %%mm1\n"
28755+ " movq 16(%1), %%mm2\n"
28756+ " movq 24(%1), %%mm3\n"
28757+ " movq %%mm0, (%2)\n"
28758+ " movq %%mm1, 8(%2)\n"
28759+ " movq %%mm2, 16(%2)\n"
28760+ " movq %%mm3, 24(%2)\n"
28761+ " movq 32(%1), %%mm0\n"
28762+ " movq 40(%1), %%mm1\n"
28763+ " movq 48(%1), %%mm2\n"
28764+ " movq 56(%1), %%mm3\n"
28765+ " movq %%mm0, 32(%2)\n"
28766+ " movq %%mm1, 40(%2)\n"
28767+ " movq %%mm2, 48(%2)\n"
28768+ " movq %%mm3, 56(%2)\n"
28769 ".section .fixup, \"ax\"\n"
28770- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28771+ "3:\n"
28772+
28773+#ifdef CONFIG_PAX_KERNEXEC
28774+ " movl %%cr0, %0\n"
28775+ " movl %0, %%eax\n"
28776+ " andl $0xFFFEFFFF, %%eax\n"
28777+ " movl %%eax, %%cr0\n"
28778+#endif
28779+
28780+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
28781+
28782+#ifdef CONFIG_PAX_KERNEXEC
28783+ " movl %0, %%cr0\n"
28784+#endif
28785+
28786 " jmp 2b\n"
28787 ".previous\n"
28788 _ASM_EXTABLE(1b, 3b)
28789- : : "r" (from), "r" (to) : "memory");
28790+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
28791
28792 from += 64;
28793 to += 64;
28794diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
28795index f6d13ee..aca5f0b 100644
28796--- a/arch/x86/lib/msr-reg.S
28797+++ b/arch/x86/lib/msr-reg.S
28798@@ -3,6 +3,7 @@
28799 #include <asm/dwarf2.h>
28800 #include <asm/asm.h>
28801 #include <asm/msr.h>
28802+#include <asm/alternative-asm.h>
28803
28804 #ifdef CONFIG_X86_64
28805 /*
28806@@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
28807 CFI_STARTPROC
28808 pushq_cfi %rbx
28809 pushq_cfi %rbp
28810- movq %rdi, %r10 /* Save pointer */
28811+ movq %rdi, %r9 /* Save pointer */
28812 xorl %r11d, %r11d /* Return value */
28813 movl (%rdi), %eax
28814 movl 4(%rdi), %ecx
28815@@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
28816 movl 28(%rdi), %edi
28817 CFI_REMEMBER_STATE
28818 1: \op
28819-2: movl %eax, (%r10)
28820+2: movl %eax, (%r9)
28821 movl %r11d, %eax /* Return value */
28822- movl %ecx, 4(%r10)
28823- movl %edx, 8(%r10)
28824- movl %ebx, 12(%r10)
28825- movl %ebp, 20(%r10)
28826- movl %esi, 24(%r10)
28827- movl %edi, 28(%r10)
28828+ movl %ecx, 4(%r9)
28829+ movl %edx, 8(%r9)
28830+ movl %ebx, 12(%r9)
28831+ movl %ebp, 20(%r9)
28832+ movl %esi, 24(%r9)
28833+ movl %edi, 28(%r9)
28834 popq_cfi %rbp
28835 popq_cfi %rbx
28836+ pax_force_retaddr
28837 ret
28838 3:
28839 CFI_RESTORE_STATE
28840diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
28841index fc6ba17..d4d989d 100644
28842--- a/arch/x86/lib/putuser.S
28843+++ b/arch/x86/lib/putuser.S
28844@@ -16,7 +16,9 @@
28845 #include <asm/errno.h>
28846 #include <asm/asm.h>
28847 #include <asm/smap.h>
28848-
28849+#include <asm/segment.h>
28850+#include <asm/pgtable.h>
28851+#include <asm/alternative-asm.h>
28852
28853 /*
28854 * __put_user_X
28855@@ -30,57 +32,125 @@
28856 * as they get called from within inline assembly.
28857 */
28858
28859-#define ENTER CFI_STARTPROC ; \
28860- GET_THREAD_INFO(%_ASM_BX)
28861-#define EXIT ASM_CLAC ; \
28862- ret ; \
28863+#define ENTER CFI_STARTPROC
28864+#define EXIT ASM_CLAC ; \
28865+ pax_force_retaddr ; \
28866+ ret ; \
28867 CFI_ENDPROC
28868
28869+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28870+#define _DEST %_ASM_CX,%_ASM_BX
28871+#else
28872+#define _DEST %_ASM_CX
28873+#endif
28874+
28875+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28876+#define __copyuser_seg gs;
28877+#else
28878+#define __copyuser_seg
28879+#endif
28880+
28881 .text
28882 ENTRY(__put_user_1)
28883 ENTER
28884+
28885+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28886+ GET_THREAD_INFO(%_ASM_BX)
28887 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
28888 jae bad_put_user
28889 ASM_STAC
28890-1: movb %al,(%_ASM_CX)
28891+
28892+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28893+ mov pax_user_shadow_base,%_ASM_BX
28894+ cmp %_ASM_BX,%_ASM_CX
28895+ jb 1234f
28896+ xor %ebx,%ebx
28897+1234:
28898+#endif
28899+
28900+#endif
28901+
28902+1: __copyuser_seg movb %al,(_DEST)
28903 xor %eax,%eax
28904 EXIT
28905 ENDPROC(__put_user_1)
28906
28907 ENTRY(__put_user_2)
28908 ENTER
28909+
28910+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28911+ GET_THREAD_INFO(%_ASM_BX)
28912 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
28913 sub $1,%_ASM_BX
28914 cmp %_ASM_BX,%_ASM_CX
28915 jae bad_put_user
28916 ASM_STAC
28917-2: movw %ax,(%_ASM_CX)
28918+
28919+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28920+ mov pax_user_shadow_base,%_ASM_BX
28921+ cmp %_ASM_BX,%_ASM_CX
28922+ jb 1234f
28923+ xor %ebx,%ebx
28924+1234:
28925+#endif
28926+
28927+#endif
28928+
28929+2: __copyuser_seg movw %ax,(_DEST)
28930 xor %eax,%eax
28931 EXIT
28932 ENDPROC(__put_user_2)
28933
28934 ENTRY(__put_user_4)
28935 ENTER
28936+
28937+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28938+ GET_THREAD_INFO(%_ASM_BX)
28939 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
28940 sub $3,%_ASM_BX
28941 cmp %_ASM_BX,%_ASM_CX
28942 jae bad_put_user
28943 ASM_STAC
28944-3: movl %eax,(%_ASM_CX)
28945+
28946+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28947+ mov pax_user_shadow_base,%_ASM_BX
28948+ cmp %_ASM_BX,%_ASM_CX
28949+ jb 1234f
28950+ xor %ebx,%ebx
28951+1234:
28952+#endif
28953+
28954+#endif
28955+
28956+3: __copyuser_seg movl %eax,(_DEST)
28957 xor %eax,%eax
28958 EXIT
28959 ENDPROC(__put_user_4)
28960
28961 ENTRY(__put_user_8)
28962 ENTER
28963+
28964+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
28965+ GET_THREAD_INFO(%_ASM_BX)
28966 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
28967 sub $7,%_ASM_BX
28968 cmp %_ASM_BX,%_ASM_CX
28969 jae bad_put_user
28970 ASM_STAC
28971-4: mov %_ASM_AX,(%_ASM_CX)
28972+
28973+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
28974+ mov pax_user_shadow_base,%_ASM_BX
28975+ cmp %_ASM_BX,%_ASM_CX
28976+ jb 1234f
28977+ xor %ebx,%ebx
28978+1234:
28979+#endif
28980+
28981+#endif
28982+
28983+4: __copyuser_seg mov %_ASM_AX,(_DEST)
28984 #ifdef CONFIG_X86_32
28985-5: movl %edx,4(%_ASM_CX)
28986+5: __copyuser_seg movl %edx,4(_DEST)
28987 #endif
28988 xor %eax,%eax
28989 EXIT
28990diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
28991index 1cad221..de671ee 100644
28992--- a/arch/x86/lib/rwlock.S
28993+++ b/arch/x86/lib/rwlock.S
28994@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
28995 FRAME
28996 0: LOCK_PREFIX
28997 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
28998+
28999+#ifdef CONFIG_PAX_REFCOUNT
29000+ jno 1234f
29001+ LOCK_PREFIX
29002+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
29003+ int $4
29004+1234:
29005+ _ASM_EXTABLE(1234b, 1234b)
29006+#endif
29007+
29008 1: rep; nop
29009 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
29010 jne 1b
29011 LOCK_PREFIX
29012 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
29013+
29014+#ifdef CONFIG_PAX_REFCOUNT
29015+ jno 1234f
29016+ LOCK_PREFIX
29017+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
29018+ int $4
29019+1234:
29020+ _ASM_EXTABLE(1234b, 1234b)
29021+#endif
29022+
29023 jnz 0b
29024 ENDFRAME
29025+ pax_force_retaddr
29026 ret
29027 CFI_ENDPROC
29028 END(__write_lock_failed)
29029@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
29030 FRAME
29031 0: LOCK_PREFIX
29032 READ_LOCK_SIZE(inc) (%__lock_ptr)
29033+
29034+#ifdef CONFIG_PAX_REFCOUNT
29035+ jno 1234f
29036+ LOCK_PREFIX
29037+ READ_LOCK_SIZE(dec) (%__lock_ptr)
29038+ int $4
29039+1234:
29040+ _ASM_EXTABLE(1234b, 1234b)
29041+#endif
29042+
29043 1: rep; nop
29044 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
29045 js 1b
29046 LOCK_PREFIX
29047 READ_LOCK_SIZE(dec) (%__lock_ptr)
29048+
29049+#ifdef CONFIG_PAX_REFCOUNT
29050+ jno 1234f
29051+ LOCK_PREFIX
29052+ READ_LOCK_SIZE(inc) (%__lock_ptr)
29053+ int $4
29054+1234:
29055+ _ASM_EXTABLE(1234b, 1234b)
29056+#endif
29057+
29058 js 0b
29059 ENDFRAME
29060+ pax_force_retaddr
29061 ret
29062 CFI_ENDPROC
29063 END(__read_lock_failed)
29064diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
29065index 5dff5f0..cadebf4 100644
29066--- a/arch/x86/lib/rwsem.S
29067+++ b/arch/x86/lib/rwsem.S
29068@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
29069 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
29070 CFI_RESTORE __ASM_REG(dx)
29071 restore_common_regs
29072+ pax_force_retaddr
29073 ret
29074 CFI_ENDPROC
29075 ENDPROC(call_rwsem_down_read_failed)
29076@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
29077 movq %rax,%rdi
29078 call rwsem_down_write_failed
29079 restore_common_regs
29080+ pax_force_retaddr
29081 ret
29082 CFI_ENDPROC
29083 ENDPROC(call_rwsem_down_write_failed)
29084@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
29085 movq %rax,%rdi
29086 call rwsem_wake
29087 restore_common_regs
29088-1: ret
29089+1: pax_force_retaddr
29090+ ret
29091 CFI_ENDPROC
29092 ENDPROC(call_rwsem_wake)
29093
29094@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
29095 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
29096 CFI_RESTORE __ASM_REG(dx)
29097 restore_common_regs
29098+ pax_force_retaddr
29099 ret
29100 CFI_ENDPROC
29101 ENDPROC(call_rwsem_downgrade_wake)
29102diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
29103index a63efd6..ccecad8 100644
29104--- a/arch/x86/lib/thunk_64.S
29105+++ b/arch/x86/lib/thunk_64.S
29106@@ -8,6 +8,7 @@
29107 #include <linux/linkage.h>
29108 #include <asm/dwarf2.h>
29109 #include <asm/calling.h>
29110+#include <asm/alternative-asm.h>
29111
29112 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
29113 .macro THUNK name, func, put_ret_addr_in_rdi=0
29114@@ -41,5 +42,6 @@
29115 SAVE_ARGS
29116 restore:
29117 RESTORE_ARGS
29118+ pax_force_retaddr
29119 ret
29120 CFI_ENDPROC
29121diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
29122index 3eb18ac..6890bc3 100644
29123--- a/arch/x86/lib/usercopy_32.c
29124+++ b/arch/x86/lib/usercopy_32.c
29125@@ -42,11 +42,13 @@ do { \
29126 int __d0; \
29127 might_fault(); \
29128 __asm__ __volatile__( \
29129+ __COPYUSER_SET_ES \
29130 ASM_STAC "\n" \
29131 "0: rep; stosl\n" \
29132 " movl %2,%0\n" \
29133 "1: rep; stosb\n" \
29134 "2: " ASM_CLAC "\n" \
29135+ __COPYUSER_RESTORE_ES \
29136 ".section .fixup,\"ax\"\n" \
29137 "3: lea 0(%2,%0,4),%0\n" \
29138 " jmp 2b\n" \
29139@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
29140
29141 #ifdef CONFIG_X86_INTEL_USERCOPY
29142 static unsigned long
29143-__copy_user_intel(void __user *to, const void *from, unsigned long size)
29144+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
29145 {
29146 int d0, d1;
29147 __asm__ __volatile__(
29148@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
29149 " .align 2,0x90\n"
29150 "3: movl 0(%4), %%eax\n"
29151 "4: movl 4(%4), %%edx\n"
29152- "5: movl %%eax, 0(%3)\n"
29153- "6: movl %%edx, 4(%3)\n"
29154+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
29155+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
29156 "7: movl 8(%4), %%eax\n"
29157 "8: movl 12(%4),%%edx\n"
29158- "9: movl %%eax, 8(%3)\n"
29159- "10: movl %%edx, 12(%3)\n"
29160+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
29161+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
29162 "11: movl 16(%4), %%eax\n"
29163 "12: movl 20(%4), %%edx\n"
29164- "13: movl %%eax, 16(%3)\n"
29165- "14: movl %%edx, 20(%3)\n"
29166+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
29167+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
29168 "15: movl 24(%4), %%eax\n"
29169 "16: movl 28(%4), %%edx\n"
29170- "17: movl %%eax, 24(%3)\n"
29171- "18: movl %%edx, 28(%3)\n"
29172+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
29173+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
29174 "19: movl 32(%4), %%eax\n"
29175 "20: movl 36(%4), %%edx\n"
29176- "21: movl %%eax, 32(%3)\n"
29177- "22: movl %%edx, 36(%3)\n"
29178+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
29179+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
29180 "23: movl 40(%4), %%eax\n"
29181 "24: movl 44(%4), %%edx\n"
29182- "25: movl %%eax, 40(%3)\n"
29183- "26: movl %%edx, 44(%3)\n"
29184+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
29185+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
29186 "27: movl 48(%4), %%eax\n"
29187 "28: movl 52(%4), %%edx\n"
29188- "29: movl %%eax, 48(%3)\n"
29189- "30: movl %%edx, 52(%3)\n"
29190+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
29191+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
29192 "31: movl 56(%4), %%eax\n"
29193 "32: movl 60(%4), %%edx\n"
29194- "33: movl %%eax, 56(%3)\n"
29195- "34: movl %%edx, 60(%3)\n"
29196+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
29197+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
29198 " addl $-64, %0\n"
29199 " addl $64, %4\n"
29200 " addl $64, %3\n"
29201@@ -149,10 +151,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
29202 " shrl $2, %0\n"
29203 " andl $3, %%eax\n"
29204 " cld\n"
29205+ __COPYUSER_SET_ES
29206 "99: rep; movsl\n"
29207 "36: movl %%eax, %0\n"
29208 "37: rep; movsb\n"
29209 "100:\n"
29210+ __COPYUSER_RESTORE_ES
29211 ".section .fixup,\"ax\"\n"
29212 "101: lea 0(%%eax,%0,4),%0\n"
29213 " jmp 100b\n"
29214@@ -202,46 +206,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
29215 }
29216
29217 static unsigned long
29218+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
29219+{
29220+ int d0, d1;
29221+ __asm__ __volatile__(
29222+ " .align 2,0x90\n"
29223+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
29224+ " cmpl $67, %0\n"
29225+ " jbe 3f\n"
29226+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
29227+ " .align 2,0x90\n"
29228+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
29229+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
29230+ "5: movl %%eax, 0(%3)\n"
29231+ "6: movl %%edx, 4(%3)\n"
29232+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
29233+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
29234+ "9: movl %%eax, 8(%3)\n"
29235+ "10: movl %%edx, 12(%3)\n"
29236+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
29237+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
29238+ "13: movl %%eax, 16(%3)\n"
29239+ "14: movl %%edx, 20(%3)\n"
29240+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
29241+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
29242+ "17: movl %%eax, 24(%3)\n"
29243+ "18: movl %%edx, 28(%3)\n"
29244+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
29245+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
29246+ "21: movl %%eax, 32(%3)\n"
29247+ "22: movl %%edx, 36(%3)\n"
29248+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
29249+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
29250+ "25: movl %%eax, 40(%3)\n"
29251+ "26: movl %%edx, 44(%3)\n"
29252+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
29253+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
29254+ "29: movl %%eax, 48(%3)\n"
29255+ "30: movl %%edx, 52(%3)\n"
29256+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
29257+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
29258+ "33: movl %%eax, 56(%3)\n"
29259+ "34: movl %%edx, 60(%3)\n"
29260+ " addl $-64, %0\n"
29261+ " addl $64, %4\n"
29262+ " addl $64, %3\n"
29263+ " cmpl $63, %0\n"
29264+ " ja 1b\n"
29265+ "35: movl %0, %%eax\n"
29266+ " shrl $2, %0\n"
29267+ " andl $3, %%eax\n"
29268+ " cld\n"
29269+ "99: rep; "__copyuser_seg" movsl\n"
29270+ "36: movl %%eax, %0\n"
29271+ "37: rep; "__copyuser_seg" movsb\n"
29272+ "100:\n"
29273+ ".section .fixup,\"ax\"\n"
29274+ "101: lea 0(%%eax,%0,4),%0\n"
29275+ " jmp 100b\n"
29276+ ".previous\n"
29277+ _ASM_EXTABLE(1b,100b)
29278+ _ASM_EXTABLE(2b,100b)
29279+ _ASM_EXTABLE(3b,100b)
29280+ _ASM_EXTABLE(4b,100b)
29281+ _ASM_EXTABLE(5b,100b)
29282+ _ASM_EXTABLE(6b,100b)
29283+ _ASM_EXTABLE(7b,100b)
29284+ _ASM_EXTABLE(8b,100b)
29285+ _ASM_EXTABLE(9b,100b)
29286+ _ASM_EXTABLE(10b,100b)
29287+ _ASM_EXTABLE(11b,100b)
29288+ _ASM_EXTABLE(12b,100b)
29289+ _ASM_EXTABLE(13b,100b)
29290+ _ASM_EXTABLE(14b,100b)
29291+ _ASM_EXTABLE(15b,100b)
29292+ _ASM_EXTABLE(16b,100b)
29293+ _ASM_EXTABLE(17b,100b)
29294+ _ASM_EXTABLE(18b,100b)
29295+ _ASM_EXTABLE(19b,100b)
29296+ _ASM_EXTABLE(20b,100b)
29297+ _ASM_EXTABLE(21b,100b)
29298+ _ASM_EXTABLE(22b,100b)
29299+ _ASM_EXTABLE(23b,100b)
29300+ _ASM_EXTABLE(24b,100b)
29301+ _ASM_EXTABLE(25b,100b)
29302+ _ASM_EXTABLE(26b,100b)
29303+ _ASM_EXTABLE(27b,100b)
29304+ _ASM_EXTABLE(28b,100b)
29305+ _ASM_EXTABLE(29b,100b)
29306+ _ASM_EXTABLE(30b,100b)
29307+ _ASM_EXTABLE(31b,100b)
29308+ _ASM_EXTABLE(32b,100b)
29309+ _ASM_EXTABLE(33b,100b)
29310+ _ASM_EXTABLE(34b,100b)
29311+ _ASM_EXTABLE(35b,100b)
29312+ _ASM_EXTABLE(36b,100b)
29313+ _ASM_EXTABLE(37b,100b)
29314+ _ASM_EXTABLE(99b,101b)
29315+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
29316+ : "1"(to), "2"(from), "0"(size)
29317+ : "eax", "edx", "memory");
29318+ return size;
29319+}
29320+
29321+static unsigned long __size_overflow(3)
29322 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
29323 {
29324 int d0, d1;
29325 __asm__ __volatile__(
29326 " .align 2,0x90\n"
29327- "0: movl 32(%4), %%eax\n"
29328+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
29329 " cmpl $67, %0\n"
29330 " jbe 2f\n"
29331- "1: movl 64(%4), %%eax\n"
29332+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
29333 " .align 2,0x90\n"
29334- "2: movl 0(%4), %%eax\n"
29335- "21: movl 4(%4), %%edx\n"
29336+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
29337+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
29338 " movl %%eax, 0(%3)\n"
29339 " movl %%edx, 4(%3)\n"
29340- "3: movl 8(%4), %%eax\n"
29341- "31: movl 12(%4),%%edx\n"
29342+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
29343+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
29344 " movl %%eax, 8(%3)\n"
29345 " movl %%edx, 12(%3)\n"
29346- "4: movl 16(%4), %%eax\n"
29347- "41: movl 20(%4), %%edx\n"
29348+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
29349+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
29350 " movl %%eax, 16(%3)\n"
29351 " movl %%edx, 20(%3)\n"
29352- "10: movl 24(%4), %%eax\n"
29353- "51: movl 28(%4), %%edx\n"
29354+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
29355+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
29356 " movl %%eax, 24(%3)\n"
29357 " movl %%edx, 28(%3)\n"
29358- "11: movl 32(%4), %%eax\n"
29359- "61: movl 36(%4), %%edx\n"
29360+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
29361+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
29362 " movl %%eax, 32(%3)\n"
29363 " movl %%edx, 36(%3)\n"
29364- "12: movl 40(%4), %%eax\n"
29365- "71: movl 44(%4), %%edx\n"
29366+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
29367+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
29368 " movl %%eax, 40(%3)\n"
29369 " movl %%edx, 44(%3)\n"
29370- "13: movl 48(%4), %%eax\n"
29371- "81: movl 52(%4), %%edx\n"
29372+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
29373+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
29374 " movl %%eax, 48(%3)\n"
29375 " movl %%edx, 52(%3)\n"
29376- "14: movl 56(%4), %%eax\n"
29377- "91: movl 60(%4), %%edx\n"
29378+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
29379+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
29380 " movl %%eax, 56(%3)\n"
29381 " movl %%edx, 60(%3)\n"
29382 " addl $-64, %0\n"
29383@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
29384 " shrl $2, %0\n"
29385 " andl $3, %%eax\n"
29386 " cld\n"
29387- "6: rep; movsl\n"
29388+ "6: rep; "__copyuser_seg" movsl\n"
29389 " movl %%eax,%0\n"
29390- "7: rep; movsb\n"
29391+ "7: rep; "__copyuser_seg" movsb\n"
29392 "8:\n"
29393 ".section .fixup,\"ax\"\n"
29394 "9: lea 0(%%eax,%0,4),%0\n"
29395@@ -298,48 +406,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
29396 * hyoshiok@miraclelinux.com
29397 */
29398
29399-static unsigned long __copy_user_zeroing_intel_nocache(void *to,
29400+static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
29401 const void __user *from, unsigned long size)
29402 {
29403 int d0, d1;
29404
29405 __asm__ __volatile__(
29406 " .align 2,0x90\n"
29407- "0: movl 32(%4), %%eax\n"
29408+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
29409 " cmpl $67, %0\n"
29410 " jbe 2f\n"
29411- "1: movl 64(%4), %%eax\n"
29412+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
29413 " .align 2,0x90\n"
29414- "2: movl 0(%4), %%eax\n"
29415- "21: movl 4(%4), %%edx\n"
29416+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
29417+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
29418 " movnti %%eax, 0(%3)\n"
29419 " movnti %%edx, 4(%3)\n"
29420- "3: movl 8(%4), %%eax\n"
29421- "31: movl 12(%4),%%edx\n"
29422+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
29423+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
29424 " movnti %%eax, 8(%3)\n"
29425 " movnti %%edx, 12(%3)\n"
29426- "4: movl 16(%4), %%eax\n"
29427- "41: movl 20(%4), %%edx\n"
29428+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
29429+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
29430 " movnti %%eax, 16(%3)\n"
29431 " movnti %%edx, 20(%3)\n"
29432- "10: movl 24(%4), %%eax\n"
29433- "51: movl 28(%4), %%edx\n"
29434+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
29435+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
29436 " movnti %%eax, 24(%3)\n"
29437 " movnti %%edx, 28(%3)\n"
29438- "11: movl 32(%4), %%eax\n"
29439- "61: movl 36(%4), %%edx\n"
29440+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
29441+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
29442 " movnti %%eax, 32(%3)\n"
29443 " movnti %%edx, 36(%3)\n"
29444- "12: movl 40(%4), %%eax\n"
29445- "71: movl 44(%4), %%edx\n"
29446+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
29447+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
29448 " movnti %%eax, 40(%3)\n"
29449 " movnti %%edx, 44(%3)\n"
29450- "13: movl 48(%4), %%eax\n"
29451- "81: movl 52(%4), %%edx\n"
29452+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
29453+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
29454 " movnti %%eax, 48(%3)\n"
29455 " movnti %%edx, 52(%3)\n"
29456- "14: movl 56(%4), %%eax\n"
29457- "91: movl 60(%4), %%edx\n"
29458+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
29459+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
29460 " movnti %%eax, 56(%3)\n"
29461 " movnti %%edx, 60(%3)\n"
29462 " addl $-64, %0\n"
29463@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
29464 " shrl $2, %0\n"
29465 " andl $3, %%eax\n"
29466 " cld\n"
29467- "6: rep; movsl\n"
29468+ "6: rep; "__copyuser_seg" movsl\n"
29469 " movl %%eax,%0\n"
29470- "7: rep; movsb\n"
29471+ "7: rep; "__copyuser_seg" movsb\n"
29472 "8:\n"
29473 ".section .fixup,\"ax\"\n"
29474 "9: lea 0(%%eax,%0,4),%0\n"
29475@@ -392,48 +500,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
29476 return size;
29477 }
29478
29479-static unsigned long __copy_user_intel_nocache(void *to,
29480+static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
29481 const void __user *from, unsigned long size)
29482 {
29483 int d0, d1;
29484
29485 __asm__ __volatile__(
29486 " .align 2,0x90\n"
29487- "0: movl 32(%4), %%eax\n"
29488+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
29489 " cmpl $67, %0\n"
29490 " jbe 2f\n"
29491- "1: movl 64(%4), %%eax\n"
29492+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
29493 " .align 2,0x90\n"
29494- "2: movl 0(%4), %%eax\n"
29495- "21: movl 4(%4), %%edx\n"
29496+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
29497+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
29498 " movnti %%eax, 0(%3)\n"
29499 " movnti %%edx, 4(%3)\n"
29500- "3: movl 8(%4), %%eax\n"
29501- "31: movl 12(%4),%%edx\n"
29502+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
29503+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
29504 " movnti %%eax, 8(%3)\n"
29505 " movnti %%edx, 12(%3)\n"
29506- "4: movl 16(%4), %%eax\n"
29507- "41: movl 20(%4), %%edx\n"
29508+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
29509+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
29510 " movnti %%eax, 16(%3)\n"
29511 " movnti %%edx, 20(%3)\n"
29512- "10: movl 24(%4), %%eax\n"
29513- "51: movl 28(%4), %%edx\n"
29514+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
29515+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
29516 " movnti %%eax, 24(%3)\n"
29517 " movnti %%edx, 28(%3)\n"
29518- "11: movl 32(%4), %%eax\n"
29519- "61: movl 36(%4), %%edx\n"
29520+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
29521+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
29522 " movnti %%eax, 32(%3)\n"
29523 " movnti %%edx, 36(%3)\n"
29524- "12: movl 40(%4), %%eax\n"
29525- "71: movl 44(%4), %%edx\n"
29526+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
29527+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
29528 " movnti %%eax, 40(%3)\n"
29529 " movnti %%edx, 44(%3)\n"
29530- "13: movl 48(%4), %%eax\n"
29531- "81: movl 52(%4), %%edx\n"
29532+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
29533+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
29534 " movnti %%eax, 48(%3)\n"
29535 " movnti %%edx, 52(%3)\n"
29536- "14: movl 56(%4), %%eax\n"
29537- "91: movl 60(%4), %%edx\n"
29538+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
29539+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
29540 " movnti %%eax, 56(%3)\n"
29541 " movnti %%edx, 60(%3)\n"
29542 " addl $-64, %0\n"
29543@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
29544 " shrl $2, %0\n"
29545 " andl $3, %%eax\n"
29546 " cld\n"
29547- "6: rep; movsl\n"
29548+ "6: rep; "__copyuser_seg" movsl\n"
29549 " movl %%eax,%0\n"
29550- "7: rep; movsb\n"
29551+ "7: rep; "__copyuser_seg" movsb\n"
29552 "8:\n"
29553 ".section .fixup,\"ax\"\n"
29554 "9: lea 0(%%eax,%0,4),%0\n"
29555@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
29556 */
29557 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
29558 unsigned long size);
29559-unsigned long __copy_user_intel(void __user *to, const void *from,
29560+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
29561+ unsigned long size);
29562+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
29563 unsigned long size);
29564 unsigned long __copy_user_zeroing_intel_nocache(void *to,
29565 const void __user *from, unsigned long size);
29566 #endif /* CONFIG_X86_INTEL_USERCOPY */
29567
29568 /* Generic arbitrary sized copy. */
29569-#define __copy_user(to, from, size) \
29570+#define __copy_user(to, from, size, prefix, set, restore) \
29571 do { \
29572 int __d0, __d1, __d2; \
29573 __asm__ __volatile__( \
29574+ set \
29575 " cmp $7,%0\n" \
29576 " jbe 1f\n" \
29577 " movl %1,%0\n" \
29578 " negl %0\n" \
29579 " andl $7,%0\n" \
29580 " subl %0,%3\n" \
29581- "4: rep; movsb\n" \
29582+ "4: rep; "prefix"movsb\n" \
29583 " movl %3,%0\n" \
29584 " shrl $2,%0\n" \
29585 " andl $3,%3\n" \
29586 " .align 2,0x90\n" \
29587- "0: rep; movsl\n" \
29588+ "0: rep; "prefix"movsl\n" \
29589 " movl %3,%0\n" \
29590- "1: rep; movsb\n" \
29591+ "1: rep; "prefix"movsb\n" \
29592 "2:\n" \
29593+ restore \
29594 ".section .fixup,\"ax\"\n" \
29595 "5: addl %3,%0\n" \
29596 " jmp 2b\n" \
29597@@ -538,14 +650,14 @@ do { \
29598 " negl %0\n" \
29599 " andl $7,%0\n" \
29600 " subl %0,%3\n" \
29601- "4: rep; movsb\n" \
29602+ "4: rep; "__copyuser_seg"movsb\n" \
29603 " movl %3,%0\n" \
29604 " shrl $2,%0\n" \
29605 " andl $3,%3\n" \
29606 " .align 2,0x90\n" \
29607- "0: rep; movsl\n" \
29608+ "0: rep; "__copyuser_seg"movsl\n" \
29609 " movl %3,%0\n" \
29610- "1: rep; movsb\n" \
29611+ "1: rep; "__copyuser_seg"movsb\n" \
29612 "2:\n" \
29613 ".section .fixup,\"ax\"\n" \
29614 "5: addl %3,%0\n" \
29615@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
29616 {
29617 stac();
29618 if (movsl_is_ok(to, from, n))
29619- __copy_user(to, from, n);
29620+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
29621 else
29622- n = __copy_user_intel(to, from, n);
29623+ n = __generic_copy_to_user_intel(to, from, n);
29624 clac();
29625 return n;
29626 }
29627@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
29628 {
29629 stac();
29630 if (movsl_is_ok(to, from, n))
29631- __copy_user(to, from, n);
29632+ __copy_user(to, from, n, __copyuser_seg, "", "");
29633 else
29634- n = __copy_user_intel((void __user *)to,
29635- (const void *)from, n);
29636+ n = __generic_copy_from_user_intel(to, from, n);
29637 clac();
29638 return n;
29639 }
29640@@ -632,60 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
29641 if (n > 64 && cpu_has_xmm2)
29642 n = __copy_user_intel_nocache(to, from, n);
29643 else
29644- __copy_user(to, from, n);
29645+ __copy_user(to, from, n, __copyuser_seg, "", "");
29646 #else
29647- __copy_user(to, from, n);
29648+ __copy_user(to, from, n, __copyuser_seg, "", "");
29649 #endif
29650 clac();
29651 return n;
29652 }
29653 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
29654
29655-/**
29656- * copy_to_user: - Copy a block of data into user space.
29657- * @to: Destination address, in user space.
29658- * @from: Source address, in kernel space.
29659- * @n: Number of bytes to copy.
29660- *
29661- * Context: User context only. This function may sleep.
29662- *
29663- * Copy data from kernel space to user space.
29664- *
29665- * Returns number of bytes that could not be copied.
29666- * On success, this will be zero.
29667- */
29668-unsigned long
29669-copy_to_user(void __user *to, const void *from, unsigned long n)
29670+#ifdef CONFIG_PAX_MEMORY_UDEREF
29671+void __set_fs(mm_segment_t x)
29672 {
29673- if (access_ok(VERIFY_WRITE, to, n))
29674- n = __copy_to_user(to, from, n);
29675- return n;
29676+ switch (x.seg) {
29677+ case 0:
29678+ loadsegment(gs, 0);
29679+ break;
29680+ case TASK_SIZE_MAX:
29681+ loadsegment(gs, __USER_DS);
29682+ break;
29683+ case -1UL:
29684+ loadsegment(gs, __KERNEL_DS);
29685+ break;
29686+ default:
29687+ BUG();
29688+ }
29689 }
29690-EXPORT_SYMBOL(copy_to_user);
29691+EXPORT_SYMBOL(__set_fs);
29692
29693-/**
29694- * copy_from_user: - Copy a block of data from user space.
29695- * @to: Destination address, in kernel space.
29696- * @from: Source address, in user space.
29697- * @n: Number of bytes to copy.
29698- *
29699- * Context: User context only. This function may sleep.
29700- *
29701- * Copy data from user space to kernel space.
29702- *
29703- * Returns number of bytes that could not be copied.
29704- * On success, this will be zero.
29705- *
29706- * If some data could not be copied, this function will pad the copied
29707- * data to the requested size using zero bytes.
29708- */
29709-unsigned long
29710-_copy_from_user(void *to, const void __user *from, unsigned long n)
29711+void set_fs(mm_segment_t x)
29712 {
29713- if (access_ok(VERIFY_READ, from, n))
29714- n = __copy_from_user(to, from, n);
29715- else
29716- memset(to, 0, n);
29717- return n;
29718+ current_thread_info()->addr_limit = x;
29719+ __set_fs(x);
29720 }
29721-EXPORT_SYMBOL(_copy_from_user);
29722+EXPORT_SYMBOL(set_fs);
29723+#endif
29724diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
29725index 906fea3..0194a18 100644
29726--- a/arch/x86/lib/usercopy_64.c
29727+++ b/arch/x86/lib/usercopy_64.c
29728@@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
29729 might_fault();
29730 /* no memory constraint because it doesn't change any memory gcc knows
29731 about */
29732+ pax_open_userland();
29733 stac();
29734 asm volatile(
29735 " testq %[size8],%[size8]\n"
29736@@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
29737 _ASM_EXTABLE(0b,3b)
29738 _ASM_EXTABLE(1b,2b)
29739 : [size8] "=&c"(size), [dst] "=&D" (__d0)
29740- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
29741+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
29742 [zero] "r" (0UL), [eight] "r" (8UL));
29743 clac();
29744+ pax_close_userland();
29745 return size;
29746 }
29747 EXPORT_SYMBOL(__clear_user);
29748@@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
29749 }
29750 EXPORT_SYMBOL(clear_user);
29751
29752-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
29753+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
29754 {
29755- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
29756- return copy_user_generic((__force void *)to, (__force void *)from, len);
29757- }
29758- return len;
29759+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
29760+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
29761+ return len;
29762 }
29763 EXPORT_SYMBOL(copy_in_user);
29764
29765@@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
29766 * it is not necessary to optimize tail handling.
29767 */
29768 unsigned long
29769-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
29770+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
29771 {
29772 char c;
29773 unsigned zero_len;
29774
29775+ clac();
29776+ pax_close_userland();
29777 for (; len; --len, to++) {
29778 if (__get_user_nocheck(c, from++, sizeof(char)))
29779 break;
29780@@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
29781 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
29782 if (__put_user_nocheck(c, to++, sizeof(char)))
29783 break;
29784- clac();
29785 return len;
29786 }
29787diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
29788index 23d8e5f..9ccc13a 100644
29789--- a/arch/x86/mm/Makefile
29790+++ b/arch/x86/mm/Makefile
29791@@ -28,3 +28,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
29792 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
29793
29794 obj-$(CONFIG_MEMTEST) += memtest.o
29795+
29796+quote:="
29797+obj-$(CONFIG_X86_64) += uderef_64.o
29798+CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
29799diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
29800index 903ec1e..c4166b2 100644
29801--- a/arch/x86/mm/extable.c
29802+++ b/arch/x86/mm/extable.c
29803@@ -6,12 +6,24 @@
29804 static inline unsigned long
29805 ex_insn_addr(const struct exception_table_entry *x)
29806 {
29807- return (unsigned long)&x->insn + x->insn;
29808+ unsigned long reloc = 0;
29809+
29810+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29811+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
29812+#endif
29813+
29814+ return (unsigned long)&x->insn + x->insn + reloc;
29815 }
29816 static inline unsigned long
29817 ex_fixup_addr(const struct exception_table_entry *x)
29818 {
29819- return (unsigned long)&x->fixup + x->fixup;
29820+ unsigned long reloc = 0;
29821+
29822+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29823+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
29824+#endif
29825+
29826+ return (unsigned long)&x->fixup + x->fixup + reloc;
29827 }
29828
29829 int fixup_exception(struct pt_regs *regs)
29830@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
29831 unsigned long new_ip;
29832
29833 #ifdef CONFIG_PNPBIOS
29834- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
29835+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
29836 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
29837 extern u32 pnp_bios_is_utter_crap;
29838 pnp_bios_is_utter_crap = 1;
29839@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
29840 i += 4;
29841 p->fixup -= i;
29842 i += 4;
29843+
29844+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29845+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
29846+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
29847+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
29848+#endif
29849+
29850 }
29851 }
29852
29853diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
29854index 654be4a..a4a3da1 100644
29855--- a/arch/x86/mm/fault.c
29856+++ b/arch/x86/mm/fault.c
29857@@ -14,11 +14,18 @@
29858 #include <linux/hugetlb.h> /* hstate_index_to_shift */
29859 #include <linux/prefetch.h> /* prefetchw */
29860 #include <linux/context_tracking.h> /* exception_enter(), ... */
29861+#include <linux/unistd.h>
29862+#include <linux/compiler.h>
29863
29864 #include <asm/traps.h> /* dotraplinkage, ... */
29865 #include <asm/pgalloc.h> /* pgd_*(), ... */
29866 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
29867 #include <asm/fixmap.h> /* VSYSCALL_START */
29868+#include <asm/tlbflush.h>
29869+
29870+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29871+#include <asm/stacktrace.h>
29872+#endif
29873
29874 /*
29875 * Page fault error code bits:
29876@@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
29877 int ret = 0;
29878
29879 /* kprobe_running() needs smp_processor_id() */
29880- if (kprobes_built_in() && !user_mode_vm(regs)) {
29881+ if (kprobes_built_in() && !user_mode(regs)) {
29882 preempt_disable();
29883 if (kprobe_running() && kprobe_fault_handler(regs, 14))
29884 ret = 1;
29885@@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
29886 return !instr_lo || (instr_lo>>1) == 1;
29887 case 0x00:
29888 /* Prefetch instruction is 0x0F0D or 0x0F18 */
29889- if (probe_kernel_address(instr, opcode))
29890+ if (user_mode(regs)) {
29891+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
29892+ return 0;
29893+ } else if (probe_kernel_address(instr, opcode))
29894 return 0;
29895
29896 *prefetch = (instr_lo == 0xF) &&
29897@@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
29898 while (instr < max_instr) {
29899 unsigned char opcode;
29900
29901- if (probe_kernel_address(instr, opcode))
29902+ if (user_mode(regs)) {
29903+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
29904+ break;
29905+ } else if (probe_kernel_address(instr, opcode))
29906 break;
29907
29908 instr++;
29909@@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
29910 force_sig_info(si_signo, &info, tsk);
29911 }
29912
29913+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
29914+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
29915+#endif
29916+
29917+#ifdef CONFIG_PAX_EMUTRAMP
29918+static int pax_handle_fetch_fault(struct pt_regs *regs);
29919+#endif
29920+
29921+#ifdef CONFIG_PAX_PAGEEXEC
29922+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
29923+{
29924+ pgd_t *pgd;
29925+ pud_t *pud;
29926+ pmd_t *pmd;
29927+
29928+ pgd = pgd_offset(mm, address);
29929+ if (!pgd_present(*pgd))
29930+ return NULL;
29931+ pud = pud_offset(pgd, address);
29932+ if (!pud_present(*pud))
29933+ return NULL;
29934+ pmd = pmd_offset(pud, address);
29935+ if (!pmd_present(*pmd))
29936+ return NULL;
29937+ return pmd;
29938+}
29939+#endif
29940+
29941 DEFINE_SPINLOCK(pgd_lock);
29942 LIST_HEAD(pgd_list);
29943
29944@@ -232,10 +273,27 @@ void vmalloc_sync_all(void)
29945 for (address = VMALLOC_START & PMD_MASK;
29946 address >= TASK_SIZE && address < FIXADDR_TOP;
29947 address += PMD_SIZE) {
29948+
29949+#ifdef CONFIG_PAX_PER_CPU_PGD
29950+ unsigned long cpu;
29951+#else
29952 struct page *page;
29953+#endif
29954
29955 spin_lock(&pgd_lock);
29956+
29957+#ifdef CONFIG_PAX_PER_CPU_PGD
29958+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
29959+ pgd_t *pgd = get_cpu_pgd(cpu, user);
29960+ pmd_t *ret;
29961+
29962+ ret = vmalloc_sync_one(pgd, address);
29963+ if (!ret)
29964+ break;
29965+ pgd = get_cpu_pgd(cpu, kernel);
29966+#else
29967 list_for_each_entry(page, &pgd_list, lru) {
29968+ pgd_t *pgd;
29969 spinlock_t *pgt_lock;
29970 pmd_t *ret;
29971
29972@@ -243,8 +301,14 @@ void vmalloc_sync_all(void)
29973 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
29974
29975 spin_lock(pgt_lock);
29976- ret = vmalloc_sync_one(page_address(page), address);
29977+ pgd = page_address(page);
29978+#endif
29979+
29980+ ret = vmalloc_sync_one(pgd, address);
29981+
29982+#ifndef CONFIG_PAX_PER_CPU_PGD
29983 spin_unlock(pgt_lock);
29984+#endif
29985
29986 if (!ret)
29987 break;
29988@@ -278,6 +342,12 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
29989 * an interrupt in the middle of a task switch..
29990 */
29991 pgd_paddr = read_cr3();
29992+
29993+#ifdef CONFIG_PAX_PER_CPU_PGD
29994+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
29995+ vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
29996+#endif
29997+
29998 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
29999 if (!pmd_k)
30000 return -1;
30001@@ -373,11 +443,25 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
30002 * happen within a race in page table update. In the later
30003 * case just flush:
30004 */
30005- pgd = pgd_offset(current->active_mm, address);
30006+
30007 pgd_ref = pgd_offset_k(address);
30008 if (pgd_none(*pgd_ref))
30009 return -1;
30010
30011+#ifdef CONFIG_PAX_PER_CPU_PGD
30012+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
30013+ pgd = pgd_offset_cpu(smp_processor_id(), user, address);
30014+ if (pgd_none(*pgd)) {
30015+ set_pgd(pgd, *pgd_ref);
30016+ arch_flush_lazy_mmu_mode();
30017+ } else {
30018+ BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
30019+ }
30020+ pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
30021+#else
30022+ pgd = pgd_offset(current->active_mm, address);
30023+#endif
30024+
30025 if (pgd_none(*pgd)) {
30026 set_pgd(pgd, *pgd_ref);
30027 arch_flush_lazy_mmu_mode();
30028@@ -543,7 +627,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
30029 static int is_errata100(struct pt_regs *regs, unsigned long address)
30030 {
30031 #ifdef CONFIG_X86_64
30032- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
30033+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
30034 return 1;
30035 #endif
30036 return 0;
30037@@ -570,7 +654,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
30038 }
30039
30040 static const char nx_warning[] = KERN_CRIT
30041-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
30042+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
30043
30044 static void
30045 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
30046@@ -579,15 +663,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
30047 if (!oops_may_print())
30048 return;
30049
30050- if (error_code & PF_INSTR) {
30051+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
30052 unsigned int level;
30053
30054 pte_t *pte = lookup_address(address, &level);
30055
30056 if (pte && pte_present(*pte) && !pte_exec(*pte))
30057- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
30058+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
30059 }
30060
30061+#ifdef CONFIG_PAX_KERNEXEC
30062+ if (init_mm.start_code <= address && address < init_mm.end_code) {
30063+ if (current->signal->curr_ip)
30064+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
30065+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
30066+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
30067+ else
30068+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
30069+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
30070+ }
30071+#endif
30072+
30073 printk(KERN_ALERT "BUG: unable to handle kernel ");
30074 if (address < PAGE_SIZE)
30075 printk(KERN_CONT "NULL pointer dereference");
30076@@ -750,6 +846,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
30077 return;
30078 }
30079 #endif
30080+
30081+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30082+ if (pax_is_fetch_fault(regs, error_code, address)) {
30083+
30084+#ifdef CONFIG_PAX_EMUTRAMP
30085+ switch (pax_handle_fetch_fault(regs)) {
30086+ case 2:
30087+ return;
30088+ }
30089+#endif
30090+
30091+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
30092+ do_group_exit(SIGKILL);
30093+ }
30094+#endif
30095+
30096 /* Kernel addresses are always protection faults: */
30097 if (address >= TASK_SIZE)
30098 error_code |= PF_PROT;
30099@@ -835,7 +947,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
30100 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
30101 printk(KERN_ERR
30102 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
30103- tsk->comm, tsk->pid, address);
30104+ tsk->comm, task_pid_nr(tsk), address);
30105 code = BUS_MCEERR_AR;
30106 }
30107 #endif
30108@@ -898,6 +1010,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
30109 return 1;
30110 }
30111
30112+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
30113+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
30114+{
30115+ pte_t *pte;
30116+ pmd_t *pmd;
30117+ spinlock_t *ptl;
30118+ unsigned char pte_mask;
30119+
30120+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
30121+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
30122+ return 0;
30123+
30124+ /* PaX: it's our fault, let's handle it if we can */
30125+
30126+ /* PaX: take a look at read faults before acquiring any locks */
30127+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
30128+ /* instruction fetch attempt from a protected page in user mode */
30129+ up_read(&mm->mmap_sem);
30130+
30131+#ifdef CONFIG_PAX_EMUTRAMP
30132+ switch (pax_handle_fetch_fault(regs)) {
30133+ case 2:
30134+ return 1;
30135+ }
30136+#endif
30137+
30138+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
30139+ do_group_exit(SIGKILL);
30140+ }
30141+
30142+ pmd = pax_get_pmd(mm, address);
30143+ if (unlikely(!pmd))
30144+ return 0;
30145+
30146+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
30147+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
30148+ pte_unmap_unlock(pte, ptl);
30149+ return 0;
30150+ }
30151+
30152+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
30153+ /* write attempt to a protected page in user mode */
30154+ pte_unmap_unlock(pte, ptl);
30155+ return 0;
30156+ }
30157+
30158+#ifdef CONFIG_SMP
30159+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
30160+#else
30161+ if (likely(address > get_limit(regs->cs)))
30162+#endif
30163+ {
30164+ set_pte(pte, pte_mkread(*pte));
30165+ __flush_tlb_one(address);
30166+ pte_unmap_unlock(pte, ptl);
30167+ up_read(&mm->mmap_sem);
30168+ return 1;
30169+ }
30170+
30171+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
30172+
30173+ /*
30174+ * PaX: fill DTLB with user rights and retry
30175+ */
30176+ __asm__ __volatile__ (
30177+ "orb %2,(%1)\n"
30178+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
30179+/*
30180+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
30181+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
30182+ * page fault when examined during a TLB load attempt. this is true not only
30183+ * for PTEs holding a non-present entry but also present entries that will
30184+ * raise a page fault (such as those set up by PaX, or the copy-on-write
30185+ * mechanism). in effect it means that we do *not* need to flush the TLBs
30186+ * for our target pages since their PTEs are simply not in the TLBs at all.
30187+
30188+ * the best thing in omitting it is that we gain around 15-20% speed in the
30189+ * fast path of the page fault handler and can get rid of tracing since we
30190+ * can no longer flush unintended entries.
30191+ */
30192+ "invlpg (%0)\n"
30193+#endif
30194+ __copyuser_seg"testb $0,(%0)\n"
30195+ "xorb %3,(%1)\n"
30196+ :
30197+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
30198+ : "memory", "cc");
30199+ pte_unmap_unlock(pte, ptl);
30200+ up_read(&mm->mmap_sem);
30201+ return 1;
30202+}
30203+#endif
30204+
30205 /*
30206 * Handle a spurious fault caused by a stale TLB entry.
30207 *
30208@@ -964,6 +1169,9 @@ int show_unhandled_signals = 1;
30209 static inline int
30210 access_error(unsigned long error_code, struct vm_area_struct *vma)
30211 {
30212+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
30213+ return 1;
30214+
30215 if (error_code & PF_WRITE) {
30216 /* write, present and write, not present: */
30217 if (unlikely(!(vma->vm_flags & VM_WRITE)))
30218@@ -992,7 +1200,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
30219 if (error_code & PF_USER)
30220 return false;
30221
30222- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
30223+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
30224 return false;
30225
30226 return true;
30227@@ -1008,18 +1216,33 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
30228 {
30229 struct vm_area_struct *vma;
30230 struct task_struct *tsk;
30231- unsigned long address;
30232 struct mm_struct *mm;
30233 int fault;
30234 int write = error_code & PF_WRITE;
30235 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
30236 (write ? FAULT_FLAG_WRITE : 0);
30237
30238- tsk = current;
30239- mm = tsk->mm;
30240-
30241 /* Get the faulting address: */
30242- address = read_cr2();
30243+ unsigned long address = read_cr2();
30244+
30245+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30246+ if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
30247+ if (!search_exception_tables(regs->ip)) {
30248+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
30249+ bad_area_nosemaphore(regs, error_code, address);
30250+ return;
30251+ }
30252+ if (address < pax_user_shadow_base) {
30253+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
30254+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
30255+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
30256+ } else
30257+ address -= pax_user_shadow_base;
30258+ }
30259+#endif
30260+
30261+ tsk = current;
30262+ mm = tsk->mm;
30263
30264 /*
30265 * Detect and handle instructions that would cause a page fault for
30266@@ -1080,7 +1303,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
30267 * User-mode registers count as a user access even for any
30268 * potential system fault or CPU buglet:
30269 */
30270- if (user_mode_vm(regs)) {
30271+ if (user_mode(regs)) {
30272 local_irq_enable();
30273 error_code |= PF_USER;
30274 } else {
30275@@ -1142,6 +1365,11 @@ retry:
30276 might_sleep();
30277 }
30278
30279+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
30280+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
30281+ return;
30282+#endif
30283+
30284 vma = find_vma(mm, address);
30285 if (unlikely(!vma)) {
30286 bad_area(regs, error_code, address);
30287@@ -1153,18 +1381,24 @@ retry:
30288 bad_area(regs, error_code, address);
30289 return;
30290 }
30291- if (error_code & PF_USER) {
30292- /*
30293- * Accessing the stack below %sp is always a bug.
30294- * The large cushion allows instructions like enter
30295- * and pusha to work. ("enter $65535, $31" pushes
30296- * 32 pointers and then decrements %sp by 65535.)
30297- */
30298- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
30299- bad_area(regs, error_code, address);
30300- return;
30301- }
30302+ /*
30303+ * Accessing the stack below %sp is always a bug.
30304+ * The large cushion allows instructions like enter
30305+ * and pusha to work. ("enter $65535, $31" pushes
30306+ * 32 pointers and then decrements %sp by 65535.)
30307+ */
30308+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
30309+ bad_area(regs, error_code, address);
30310+ return;
30311 }
30312+
30313+#ifdef CONFIG_PAX_SEGMEXEC
30314+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
30315+ bad_area(regs, error_code, address);
30316+ return;
30317+ }
30318+#endif
30319+
30320 if (unlikely(expand_stack(vma, address))) {
30321 bad_area(regs, error_code, address);
30322 return;
30323@@ -1230,3 +1464,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
30324 __do_page_fault(regs, error_code);
30325 exception_exit(prev_state);
30326 }
30327+
30328+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30329+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
30330+{
30331+ struct mm_struct *mm = current->mm;
30332+ unsigned long ip = regs->ip;
30333+
30334+ if (v8086_mode(regs))
30335+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
30336+
30337+#ifdef CONFIG_PAX_PAGEEXEC
30338+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
30339+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
30340+ return true;
30341+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
30342+ return true;
30343+ return false;
30344+ }
30345+#endif
30346+
30347+#ifdef CONFIG_PAX_SEGMEXEC
30348+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
30349+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
30350+ return true;
30351+ return false;
30352+ }
30353+#endif
30354+
30355+ return false;
30356+}
30357+#endif
30358+
30359+#ifdef CONFIG_PAX_EMUTRAMP
30360+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
30361+{
30362+ int err;
30363+
30364+ do { /* PaX: libffi trampoline emulation */
30365+ unsigned char mov, jmp;
30366+ unsigned int addr1, addr2;
30367+
30368+#ifdef CONFIG_X86_64
30369+ if ((regs->ip + 9) >> 32)
30370+ break;
30371+#endif
30372+
30373+ err = get_user(mov, (unsigned char __user *)regs->ip);
30374+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
30375+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
30376+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
30377+
30378+ if (err)
30379+ break;
30380+
30381+ if (mov == 0xB8 && jmp == 0xE9) {
30382+ regs->ax = addr1;
30383+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
30384+ return 2;
30385+ }
30386+ } while (0);
30387+
30388+ do { /* PaX: gcc trampoline emulation #1 */
30389+ unsigned char mov1, mov2;
30390+ unsigned short jmp;
30391+ unsigned int addr1, addr2;
30392+
30393+#ifdef CONFIG_X86_64
30394+ if ((regs->ip + 11) >> 32)
30395+ break;
30396+#endif
30397+
30398+ err = get_user(mov1, (unsigned char __user *)regs->ip);
30399+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
30400+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
30401+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
30402+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
30403+
30404+ if (err)
30405+ break;
30406+
30407+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
30408+ regs->cx = addr1;
30409+ regs->ax = addr2;
30410+ regs->ip = addr2;
30411+ return 2;
30412+ }
30413+ } while (0);
30414+
30415+ do { /* PaX: gcc trampoline emulation #2 */
30416+ unsigned char mov, jmp;
30417+ unsigned int addr1, addr2;
30418+
30419+#ifdef CONFIG_X86_64
30420+ if ((regs->ip + 9) >> 32)
30421+ break;
30422+#endif
30423+
30424+ err = get_user(mov, (unsigned char __user *)regs->ip);
30425+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
30426+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
30427+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
30428+
30429+ if (err)
30430+ break;
30431+
30432+ if (mov == 0xB9 && jmp == 0xE9) {
30433+ regs->cx = addr1;
30434+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
30435+ return 2;
30436+ }
30437+ } while (0);
30438+
30439+ return 1; /* PaX in action */
30440+}
30441+
30442+#ifdef CONFIG_X86_64
30443+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
30444+{
30445+ int err;
30446+
30447+ do { /* PaX: libffi trampoline emulation */
30448+ unsigned short mov1, mov2, jmp1;
30449+ unsigned char stcclc, jmp2;
30450+ unsigned long addr1, addr2;
30451+
30452+ err = get_user(mov1, (unsigned short __user *)regs->ip);
30453+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
30454+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
30455+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
30456+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
30457+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
30458+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
30459+
30460+ if (err)
30461+ break;
30462+
30463+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
30464+ regs->r11 = addr1;
30465+ regs->r10 = addr2;
30466+ if (stcclc == 0xF8)
30467+ regs->flags &= ~X86_EFLAGS_CF;
30468+ else
30469+ regs->flags |= X86_EFLAGS_CF;
30470+ regs->ip = addr1;
30471+ return 2;
30472+ }
30473+ } while (0);
30474+
30475+ do { /* PaX: gcc trampoline emulation #1 */
30476+ unsigned short mov1, mov2, jmp1;
30477+ unsigned char jmp2;
30478+ unsigned int addr1;
30479+ unsigned long addr2;
30480+
30481+ err = get_user(mov1, (unsigned short __user *)regs->ip);
30482+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
30483+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
30484+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
30485+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
30486+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
30487+
30488+ if (err)
30489+ break;
30490+
30491+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
30492+ regs->r11 = addr1;
30493+ regs->r10 = addr2;
30494+ regs->ip = addr1;
30495+ return 2;
30496+ }
30497+ } while (0);
30498+
30499+ do { /* PaX: gcc trampoline emulation #2 */
30500+ unsigned short mov1, mov2, jmp1;
30501+ unsigned char jmp2;
30502+ unsigned long addr1, addr2;
30503+
30504+ err = get_user(mov1, (unsigned short __user *)regs->ip);
30505+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
30506+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
30507+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
30508+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
30509+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
30510+
30511+ if (err)
30512+ break;
30513+
30514+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
30515+ regs->r11 = addr1;
30516+ regs->r10 = addr2;
30517+ regs->ip = addr1;
30518+ return 2;
30519+ }
30520+ } while (0);
30521+
30522+ return 1; /* PaX in action */
30523+}
30524+#endif
30525+
30526+/*
30527+ * PaX: decide what to do with offenders (regs->ip = fault address)
30528+ *
30529+ * returns 1 when task should be killed
30530+ * 2 when gcc trampoline was detected
30531+ */
30532+static int pax_handle_fetch_fault(struct pt_regs *regs)
30533+{
30534+ if (v8086_mode(regs))
30535+ return 1;
30536+
30537+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
30538+ return 1;
30539+
30540+#ifdef CONFIG_X86_32
30541+ return pax_handle_fetch_fault_32(regs);
30542+#else
30543+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
30544+ return pax_handle_fetch_fault_32(regs);
30545+ else
30546+ return pax_handle_fetch_fault_64(regs);
30547+#endif
30548+}
30549+#endif
30550+
30551+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30552+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
30553+{
30554+ long i;
30555+
30556+ printk(KERN_ERR "PAX: bytes at PC: ");
30557+ for (i = 0; i < 20; i++) {
30558+ unsigned char c;
30559+ if (get_user(c, (unsigned char __force_user *)pc+i))
30560+ printk(KERN_CONT "?? ");
30561+ else
30562+ printk(KERN_CONT "%02x ", c);
30563+ }
30564+ printk("\n");
30565+
30566+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
30567+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
30568+ unsigned long c;
30569+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
30570+#ifdef CONFIG_X86_32
30571+ printk(KERN_CONT "???????? ");
30572+#else
30573+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
30574+ printk(KERN_CONT "???????? ???????? ");
30575+ else
30576+ printk(KERN_CONT "???????????????? ");
30577+#endif
30578+ } else {
30579+#ifdef CONFIG_X86_64
30580+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
30581+ printk(KERN_CONT "%08x ", (unsigned int)c);
30582+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
30583+ } else
30584+#endif
30585+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
30586+ }
30587+ }
30588+ printk("\n");
30589+}
30590+#endif
30591+
30592+/**
30593+ * probe_kernel_write(): safely attempt to write to a location
30594+ * @dst: address to write to
30595+ * @src: pointer to the data that shall be written
30596+ * @size: size of the data chunk
30597+ *
30598+ * Safely write to address @dst from the buffer at @src. If a kernel fault
30599+ * happens, handle that and return -EFAULT.
30600+ */
30601+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
30602+{
30603+ long ret;
30604+ mm_segment_t old_fs = get_fs();
30605+
30606+ set_fs(KERNEL_DS);
30607+ pagefault_disable();
30608+ pax_open_kernel();
30609+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
30610+ pax_close_kernel();
30611+ pagefault_enable();
30612+ set_fs(old_fs);
30613+
30614+ return ret ? -EFAULT : 0;
30615+}
30616diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
30617index dd74e46..7d26398 100644
30618--- a/arch/x86/mm/gup.c
30619+++ b/arch/x86/mm/gup.c
30620@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
30621 addr = start;
30622 len = (unsigned long) nr_pages << PAGE_SHIFT;
30623 end = start + len;
30624- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
30625+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
30626 (void __user *)start, len)))
30627 return 0;
30628
30629diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
30630index 4500142..53a363c 100644
30631--- a/arch/x86/mm/highmem_32.c
30632+++ b/arch/x86/mm/highmem_32.c
30633@@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
30634 idx = type + KM_TYPE_NR*smp_processor_id();
30635 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
30636 BUG_ON(!pte_none(*(kmap_pte-idx)));
30637+
30638+ pax_open_kernel();
30639 set_pte(kmap_pte-idx, mk_pte(page, prot));
30640+ pax_close_kernel();
30641+
30642 arch_flush_lazy_mmu_mode();
30643
30644 return (void *)vaddr;
30645diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
30646index 7e73e8c..11d3b86 100644
30647--- a/arch/x86/mm/hugetlbpage.c
30648+++ b/arch/x86/mm/hugetlbpage.c
30649@@ -84,23 +84,30 @@ int pud_huge(pud_t pud)
30650 #ifdef HAVE_ARCH_HUGETLB_UNMAPPED_AREA
30651 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
30652 unsigned long addr, unsigned long len,
30653- unsigned long pgoff, unsigned long flags)
30654+ unsigned long pgoff, unsigned long flags, unsigned long offset)
30655 {
30656 struct hstate *h = hstate_file(file);
30657 struct vm_unmapped_area_info info;
30658-
30659+
30660 info.flags = 0;
30661 info.length = len;
30662 info.low_limit = TASK_UNMAPPED_BASE;
30663+
30664+#ifdef CONFIG_PAX_RANDMMAP
30665+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
30666+ info.low_limit += current->mm->delta_mmap;
30667+#endif
30668+
30669 info.high_limit = TASK_SIZE;
30670 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
30671 info.align_offset = 0;
30672+ info.threadstack_offset = offset;
30673 return vm_unmapped_area(&info);
30674 }
30675
30676 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
30677 unsigned long addr0, unsigned long len,
30678- unsigned long pgoff, unsigned long flags)
30679+ unsigned long pgoff, unsigned long flags, unsigned long offset)
30680 {
30681 struct hstate *h = hstate_file(file);
30682 struct vm_unmapped_area_info info;
30683@@ -112,6 +119,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
30684 info.high_limit = current->mm->mmap_base;
30685 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
30686 info.align_offset = 0;
30687+ info.threadstack_offset = offset;
30688 addr = vm_unmapped_area(&info);
30689
30690 /*
30691@@ -124,6 +132,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
30692 VM_BUG_ON(addr != -ENOMEM);
30693 info.flags = 0;
30694 info.low_limit = TASK_UNMAPPED_BASE;
30695+
30696+#ifdef CONFIG_PAX_RANDMMAP
30697+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
30698+ info.low_limit += current->mm->delta_mmap;
30699+#endif
30700+
30701 info.high_limit = TASK_SIZE;
30702 addr = vm_unmapped_area(&info);
30703 }
30704@@ -138,10 +152,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
30705 struct hstate *h = hstate_file(file);
30706 struct mm_struct *mm = current->mm;
30707 struct vm_area_struct *vma;
30708+ unsigned long pax_task_size = TASK_SIZE;
30709+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
30710
30711 if (len & ~huge_page_mask(h))
30712 return -EINVAL;
30713- if (len > TASK_SIZE)
30714+
30715+#ifdef CONFIG_PAX_SEGMEXEC
30716+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
30717+ pax_task_size = SEGMEXEC_TASK_SIZE;
30718+#endif
30719+
30720+ pax_task_size -= PAGE_SIZE;
30721+
30722+ if (len > pax_task_size)
30723 return -ENOMEM;
30724
30725 if (flags & MAP_FIXED) {
30726@@ -150,19 +174,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
30727 return addr;
30728 }
30729
30730+#ifdef CONFIG_PAX_RANDMMAP
30731+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
30732+#endif
30733+
30734 if (addr) {
30735 addr = ALIGN(addr, huge_page_size(h));
30736 vma = find_vma(mm, addr);
30737- if (TASK_SIZE - len >= addr &&
30738- (!vma || addr + len <= vma->vm_start))
30739+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
30740 return addr;
30741 }
30742 if (mm->get_unmapped_area == arch_get_unmapped_area)
30743 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
30744- pgoff, flags);
30745+ pgoff, flags, offset);
30746 else
30747 return hugetlb_get_unmapped_area_topdown(file, addr, len,
30748- pgoff, flags);
30749+ pgoff, flags, offset);
30750 }
30751
30752 #endif /*HAVE_ARCH_HUGETLB_UNMAPPED_AREA*/
30753diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
30754index 04664cd..dae6e5d 100644
30755--- a/arch/x86/mm/init.c
30756+++ b/arch/x86/mm/init.c
30757@@ -4,6 +4,7 @@
30758 #include <linux/swap.h>
30759 #include <linux/memblock.h>
30760 #include <linux/bootmem.h> /* for max_low_pfn */
30761+#include <linux/tboot.h>
30762
30763 #include <asm/cacheflush.h>
30764 #include <asm/e820.h>
30765@@ -17,6 +18,8 @@
30766 #include <asm/proto.h>
30767 #include <asm/dma.h> /* for MAX_DMA_PFN */
30768 #include <asm/microcode.h>
30769+#include <asm/desc.h>
30770+#include <asm/bios_ebda.h>
30771
30772 #include "mm_internal.h"
30773
30774@@ -465,7 +468,18 @@ void __init init_mem_mapping(void)
30775 early_ioremap_page_table_range_init();
30776 #endif
30777
30778+#ifdef CONFIG_PAX_PER_CPU_PGD
30779+ clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
30780+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
30781+ KERNEL_PGD_PTRS);
30782+ clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
30783+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
30784+ KERNEL_PGD_PTRS);
30785+ load_cr3(get_cpu_pgd(0, kernel));
30786+#else
30787 load_cr3(swapper_pg_dir);
30788+#endif
30789+
30790 __flush_tlb_all();
30791
30792 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
30793@@ -481,10 +495,40 @@ void __init init_mem_mapping(void)
30794 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
30795 * mmio resources as well as potential bios/acpi data regions.
30796 */
30797+
30798+#ifdef CONFIG_GRKERNSEC_KMEM
30799+static unsigned int ebda_start __read_only;
30800+static unsigned int ebda_end __read_only;
30801+#endif
30802+
30803 int devmem_is_allowed(unsigned long pagenr)
30804 {
30805- if (pagenr < 256)
30806+#ifdef CONFIG_GRKERNSEC_KMEM
30807+ /* allow BDA */
30808+ if (!pagenr)
30809 return 1;
30810+ /* allow EBDA */
30811+ if (pagenr >= ebda_start && pagenr < ebda_end)
30812+ return 1;
30813+ /* if tboot is in use, allow access to its hardcoded serial log range */
30814+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
30815+ return 1;
30816+#else
30817+ if (!pagenr)
30818+ return 1;
30819+#ifdef CONFIG_VM86
30820+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
30821+ return 1;
30822+#endif
30823+#endif
30824+
30825+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
30826+ return 1;
30827+#ifdef CONFIG_GRKERNSEC_KMEM
30828+ /* throw out everything else below 1MB */
30829+ if (pagenr <= 256)
30830+ return 0;
30831+#endif
30832 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
30833 return 0;
30834 if (!page_is_ram(pagenr))
30835@@ -530,8 +574,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
30836 #endif
30837 }
30838
30839+#ifdef CONFIG_GRKERNSEC_KMEM
30840+static inline void gr_init_ebda(void)
30841+{
30842+ unsigned int ebda_addr;
30843+ unsigned int ebda_size = 0;
30844+
30845+ ebda_addr = get_bios_ebda();
30846+ if (ebda_addr) {
30847+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
30848+ ebda_size <<= 10;
30849+ }
30850+ if (ebda_addr && ebda_size) {
30851+ ebda_start = ebda_addr >> PAGE_SHIFT;
30852+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
30853+ } else {
30854+ ebda_start = 0x9f000 >> PAGE_SHIFT;
30855+ ebda_end = 0xa0000 >> PAGE_SHIFT;
30856+ }
30857+}
30858+#else
30859+static inline void gr_init_ebda(void) { }
30860+#endif
30861+
30862 void free_initmem(void)
30863 {
30864+#ifdef CONFIG_PAX_KERNEXEC
30865+#ifdef CONFIG_X86_32
30866+ /* PaX: limit KERNEL_CS to actual size */
30867+ unsigned long addr, limit;
30868+ struct desc_struct d;
30869+ int cpu;
30870+#else
30871+ pgd_t *pgd;
30872+ pud_t *pud;
30873+ pmd_t *pmd;
30874+ unsigned long addr, end;
30875+#endif
30876+#endif
30877+
30878+ gr_init_ebda();
30879+
30880+#ifdef CONFIG_PAX_KERNEXEC
30881+#ifdef CONFIG_X86_32
30882+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
30883+ limit = (limit - 1UL) >> PAGE_SHIFT;
30884+
30885+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
30886+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
30887+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
30888+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
30889+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
30890+ }
30891+
30892+ /* PaX: make KERNEL_CS read-only */
30893+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
30894+ if (!paravirt_enabled())
30895+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
30896+/*
30897+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
30898+ pgd = pgd_offset_k(addr);
30899+ pud = pud_offset(pgd, addr);
30900+ pmd = pmd_offset(pud, addr);
30901+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
30902+ }
30903+*/
30904+#ifdef CONFIG_X86_PAE
30905+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
30906+/*
30907+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
30908+ pgd = pgd_offset_k(addr);
30909+ pud = pud_offset(pgd, addr);
30910+ pmd = pmd_offset(pud, addr);
30911+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
30912+ }
30913+*/
30914+#endif
30915+
30916+#ifdef CONFIG_MODULES
30917+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
30918+#endif
30919+
30920+#else
30921+ /* PaX: make kernel code/rodata read-only, rest non-executable */
30922+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
30923+ pgd = pgd_offset_k(addr);
30924+ pud = pud_offset(pgd, addr);
30925+ pmd = pmd_offset(pud, addr);
30926+ if (!pmd_present(*pmd))
30927+ continue;
30928+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
30929+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
30930+ else
30931+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
30932+ }
30933+
30934+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
30935+ end = addr + KERNEL_IMAGE_SIZE;
30936+ for (; addr < end; addr += PMD_SIZE) {
30937+ pgd = pgd_offset_k(addr);
30938+ pud = pud_offset(pgd, addr);
30939+ pmd = pmd_offset(pud, addr);
30940+ if (!pmd_present(*pmd))
30941+ continue;
30942+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
30943+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
30944+ }
30945+#endif
30946+
30947+ flush_tlb_all();
30948+#endif
30949+
30950 free_init_pages("unused kernel",
30951 (unsigned long)(&__init_begin),
30952 (unsigned long)(&__init_end));
30953diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
30954index 4287f1f..3b99c71 100644
30955--- a/arch/x86/mm/init_32.c
30956+++ b/arch/x86/mm/init_32.c
30957@@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
30958 bool __read_mostly __vmalloc_start_set = false;
30959
30960 /*
30961- * Creates a middle page table and puts a pointer to it in the
30962- * given global directory entry. This only returns the gd entry
30963- * in non-PAE compilation mode, since the middle layer is folded.
30964- */
30965-static pmd_t * __init one_md_table_init(pgd_t *pgd)
30966-{
30967- pud_t *pud;
30968- pmd_t *pmd_table;
30969-
30970-#ifdef CONFIG_X86_PAE
30971- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
30972- pmd_table = (pmd_t *)alloc_low_page();
30973- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
30974- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
30975- pud = pud_offset(pgd, 0);
30976- BUG_ON(pmd_table != pmd_offset(pud, 0));
30977-
30978- return pmd_table;
30979- }
30980-#endif
30981- pud = pud_offset(pgd, 0);
30982- pmd_table = pmd_offset(pud, 0);
30983-
30984- return pmd_table;
30985-}
30986-
30987-/*
30988 * Create a page table and place a pointer to it in a middle page
30989 * directory entry:
30990 */
30991@@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
30992 pte_t *page_table = (pte_t *)alloc_low_page();
30993
30994 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
30995+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30996+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
30997+#else
30998 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
30999+#endif
31000 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
31001 }
31002
31003 return pte_offset_kernel(pmd, 0);
31004 }
31005
31006+static pmd_t * __init one_md_table_init(pgd_t *pgd)
31007+{
31008+ pud_t *pud;
31009+ pmd_t *pmd_table;
31010+
31011+ pud = pud_offset(pgd, 0);
31012+ pmd_table = pmd_offset(pud, 0);
31013+
31014+ return pmd_table;
31015+}
31016+
31017 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
31018 {
31019 int pgd_idx = pgd_index(vaddr);
31020@@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31021 int pgd_idx, pmd_idx;
31022 unsigned long vaddr;
31023 pgd_t *pgd;
31024+ pud_t *pud;
31025 pmd_t *pmd;
31026 pte_t *pte = NULL;
31027 unsigned long count = page_table_range_init_count(start, end);
31028@@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31029 pgd = pgd_base + pgd_idx;
31030
31031 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
31032- pmd = one_md_table_init(pgd);
31033- pmd = pmd + pmd_index(vaddr);
31034+ pud = pud_offset(pgd, vaddr);
31035+ pmd = pmd_offset(pud, vaddr);
31036+
31037+#ifdef CONFIG_X86_PAE
31038+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
31039+#endif
31040+
31041 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
31042 pmd++, pmd_idx++) {
31043 pte = page_table_kmap_check(one_page_table_init(pmd),
31044@@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31045 }
31046 }
31047
31048-static inline int is_kernel_text(unsigned long addr)
31049+static inline int is_kernel_text(unsigned long start, unsigned long end)
31050 {
31051- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
31052- return 1;
31053- return 0;
31054+ if ((start > ktla_ktva((unsigned long)_etext) ||
31055+ end <= ktla_ktva((unsigned long)_stext)) &&
31056+ (start > ktla_ktva((unsigned long)_einittext) ||
31057+ end <= ktla_ktva((unsigned long)_sinittext)) &&
31058+
31059+#ifdef CONFIG_ACPI_SLEEP
31060+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
31061+#endif
31062+
31063+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
31064+ return 0;
31065+ return 1;
31066 }
31067
31068 /*
31069@@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
31070 unsigned long last_map_addr = end;
31071 unsigned long start_pfn, end_pfn;
31072 pgd_t *pgd_base = swapper_pg_dir;
31073- int pgd_idx, pmd_idx, pte_ofs;
31074+ unsigned int pgd_idx, pmd_idx, pte_ofs;
31075 unsigned long pfn;
31076 pgd_t *pgd;
31077+ pud_t *pud;
31078 pmd_t *pmd;
31079 pte_t *pte;
31080 unsigned pages_2m, pages_4k;
31081@@ -291,8 +295,13 @@ repeat:
31082 pfn = start_pfn;
31083 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
31084 pgd = pgd_base + pgd_idx;
31085- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
31086- pmd = one_md_table_init(pgd);
31087+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
31088+ pud = pud_offset(pgd, 0);
31089+ pmd = pmd_offset(pud, 0);
31090+
31091+#ifdef CONFIG_X86_PAE
31092+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
31093+#endif
31094
31095 if (pfn >= end_pfn)
31096 continue;
31097@@ -304,14 +313,13 @@ repeat:
31098 #endif
31099 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
31100 pmd++, pmd_idx++) {
31101- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
31102+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
31103
31104 /*
31105 * Map with big pages if possible, otherwise
31106 * create normal page tables:
31107 */
31108 if (use_pse) {
31109- unsigned int addr2;
31110 pgprot_t prot = PAGE_KERNEL_LARGE;
31111 /*
31112 * first pass will use the same initial
31113@@ -322,11 +330,7 @@ repeat:
31114 _PAGE_PSE);
31115
31116 pfn &= PMD_MASK >> PAGE_SHIFT;
31117- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
31118- PAGE_OFFSET + PAGE_SIZE-1;
31119-
31120- if (is_kernel_text(addr) ||
31121- is_kernel_text(addr2))
31122+ if (is_kernel_text(address, address + PMD_SIZE))
31123 prot = PAGE_KERNEL_LARGE_EXEC;
31124
31125 pages_2m++;
31126@@ -343,7 +347,7 @@ repeat:
31127 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
31128 pte += pte_ofs;
31129 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
31130- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
31131+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
31132 pgprot_t prot = PAGE_KERNEL;
31133 /*
31134 * first pass will use the same initial
31135@@ -351,7 +355,7 @@ repeat:
31136 */
31137 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
31138
31139- if (is_kernel_text(addr))
31140+ if (is_kernel_text(address, address + PAGE_SIZE))
31141 prot = PAGE_KERNEL_EXEC;
31142
31143 pages_4k++;
31144@@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
31145
31146 pud = pud_offset(pgd, va);
31147 pmd = pmd_offset(pud, va);
31148- if (!pmd_present(*pmd))
31149+ if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
31150 break;
31151
31152 /* should not be large page here */
31153@@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
31154
31155 static void __init pagetable_init(void)
31156 {
31157- pgd_t *pgd_base = swapper_pg_dir;
31158-
31159- permanent_kmaps_init(pgd_base);
31160+ permanent_kmaps_init(swapper_pg_dir);
31161 }
31162
31163-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
31164+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
31165 EXPORT_SYMBOL_GPL(__supported_pte_mask);
31166
31167 /* user-defined highmem size */
31168@@ -787,10 +789,10 @@ void __init mem_init(void)
31169 ((unsigned long)&__init_end -
31170 (unsigned long)&__init_begin) >> 10,
31171
31172- (unsigned long)&_etext, (unsigned long)&_edata,
31173- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
31174+ (unsigned long)&_sdata, (unsigned long)&_edata,
31175+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
31176
31177- (unsigned long)&_text, (unsigned long)&_etext,
31178+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
31179 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
31180
31181 /*
31182@@ -880,6 +882,7 @@ void set_kernel_text_rw(void)
31183 if (!kernel_set_to_readonly)
31184 return;
31185
31186+ start = ktla_ktva(start);
31187 pr_debug("Set kernel text: %lx - %lx for read write\n",
31188 start, start+size);
31189
31190@@ -894,6 +897,7 @@ void set_kernel_text_ro(void)
31191 if (!kernel_set_to_readonly)
31192 return;
31193
31194+ start = ktla_ktva(start);
31195 pr_debug("Set kernel text: %lx - %lx for read only\n",
31196 start, start+size);
31197
31198@@ -922,6 +926,7 @@ void mark_rodata_ro(void)
31199 unsigned long start = PFN_ALIGN(_text);
31200 unsigned long size = PFN_ALIGN(_etext) - start;
31201
31202+ start = ktla_ktva(start);
31203 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
31204 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
31205 size >> 10);
31206diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
31207index 104d56a..62ba13f 100644
31208--- a/arch/x86/mm/init_64.c
31209+++ b/arch/x86/mm/init_64.c
31210@@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
31211 * around without checking the pgd every time.
31212 */
31213
31214-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
31215+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
31216 EXPORT_SYMBOL_GPL(__supported_pte_mask);
31217
31218 int force_personality32;
31219@@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
31220
31221 for (address = start; address <= end; address += PGDIR_SIZE) {
31222 const pgd_t *pgd_ref = pgd_offset_k(address);
31223+
31224+#ifdef CONFIG_PAX_PER_CPU_PGD
31225+ unsigned long cpu;
31226+#else
31227 struct page *page;
31228+#endif
31229
31230 if (pgd_none(*pgd_ref))
31231 continue;
31232
31233 spin_lock(&pgd_lock);
31234+
31235+#ifdef CONFIG_PAX_PER_CPU_PGD
31236+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31237+ pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
31238+
31239+ if (pgd_none(*pgd))
31240+ set_pgd(pgd, *pgd_ref);
31241+ else
31242+ BUG_ON(pgd_page_vaddr(*pgd)
31243+ != pgd_page_vaddr(*pgd_ref));
31244+ pgd = pgd_offset_cpu(cpu, kernel, address);
31245+#else
31246 list_for_each_entry(page, &pgd_list, lru) {
31247 pgd_t *pgd;
31248 spinlock_t *pgt_lock;
31249@@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
31250 /* the pgt_lock only for Xen */
31251 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
31252 spin_lock(pgt_lock);
31253+#endif
31254
31255 if (pgd_none(*pgd))
31256 set_pgd(pgd, *pgd_ref);
31257@@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
31258 BUG_ON(pgd_page_vaddr(*pgd)
31259 != pgd_page_vaddr(*pgd_ref));
31260
31261+#ifndef CONFIG_PAX_PER_CPU_PGD
31262 spin_unlock(pgt_lock);
31263+#endif
31264+
31265 }
31266 spin_unlock(&pgd_lock);
31267 }
31268@@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
31269 {
31270 if (pgd_none(*pgd)) {
31271 pud_t *pud = (pud_t *)spp_getpage();
31272- pgd_populate(&init_mm, pgd, pud);
31273+ pgd_populate_kernel(&init_mm, pgd, pud);
31274 if (pud != pud_offset(pgd, 0))
31275 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
31276 pud, pud_offset(pgd, 0));
31277@@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
31278 {
31279 if (pud_none(*pud)) {
31280 pmd_t *pmd = (pmd_t *) spp_getpage();
31281- pud_populate(&init_mm, pud, pmd);
31282+ pud_populate_kernel(&init_mm, pud, pmd);
31283 if (pmd != pmd_offset(pud, 0))
31284 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
31285 pmd, pmd_offset(pud, 0));
31286@@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
31287 pmd = fill_pmd(pud, vaddr);
31288 pte = fill_pte(pmd, vaddr);
31289
31290+ pax_open_kernel();
31291 set_pte(pte, new_pte);
31292+ pax_close_kernel();
31293
31294 /*
31295 * It's enough to flush this one mapping.
31296@@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
31297 pgd = pgd_offset_k((unsigned long)__va(phys));
31298 if (pgd_none(*pgd)) {
31299 pud = (pud_t *) spp_getpage();
31300- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
31301- _PAGE_USER));
31302+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
31303 }
31304 pud = pud_offset(pgd, (unsigned long)__va(phys));
31305 if (pud_none(*pud)) {
31306 pmd = (pmd_t *) spp_getpage();
31307- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
31308- _PAGE_USER));
31309+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
31310 }
31311 pmd = pmd_offset(pud, phys);
31312 BUG_ON(!pmd_none(*pmd));
31313@@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
31314 prot);
31315
31316 spin_lock(&init_mm.page_table_lock);
31317- pud_populate(&init_mm, pud, pmd);
31318+ pud_populate_kernel(&init_mm, pud, pmd);
31319 spin_unlock(&init_mm.page_table_lock);
31320 }
31321 __flush_tlb_all();
31322@@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
31323 page_size_mask);
31324
31325 spin_lock(&init_mm.page_table_lock);
31326- pgd_populate(&init_mm, pgd, pud);
31327+ pgd_populate_kernel(&init_mm, pgd, pud);
31328 spin_unlock(&init_mm.page_table_lock);
31329 pgd_changed = true;
31330 }
31331@@ -1188,8 +1209,8 @@ int kern_addr_valid(unsigned long addr)
31332 static struct vm_area_struct gate_vma = {
31333 .vm_start = VSYSCALL_START,
31334 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
31335- .vm_page_prot = PAGE_READONLY_EXEC,
31336- .vm_flags = VM_READ | VM_EXEC
31337+ .vm_page_prot = PAGE_READONLY,
31338+ .vm_flags = VM_READ
31339 };
31340
31341 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
31342@@ -1223,7 +1244,7 @@ int in_gate_area_no_mm(unsigned long addr)
31343
31344 const char *arch_vma_name(struct vm_area_struct *vma)
31345 {
31346- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
31347+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
31348 return "[vdso]";
31349 if (vma == &gate_vma)
31350 return "[vsyscall]";
31351diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
31352index 7b179b4..6bd17777 100644
31353--- a/arch/x86/mm/iomap_32.c
31354+++ b/arch/x86/mm/iomap_32.c
31355@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
31356 type = kmap_atomic_idx_push();
31357 idx = type + KM_TYPE_NR * smp_processor_id();
31358 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
31359+
31360+ pax_open_kernel();
31361 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
31362+ pax_close_kernel();
31363+
31364 arch_flush_lazy_mmu_mode();
31365
31366 return (void *)vaddr;
31367diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
31368index 0215e2c..1c62dab 100644
31369--- a/arch/x86/mm/ioremap.c
31370+++ b/arch/x86/mm/ioremap.c
31371@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
31372 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
31373 int is_ram = page_is_ram(pfn);
31374
31375- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
31376+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
31377 return NULL;
31378 WARN_ON_ONCE(is_ram);
31379 }
31380@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
31381 *
31382 * Caller must ensure there is only one unmapping for the same pointer.
31383 */
31384-void iounmap(volatile void __iomem *addr)
31385+void iounmap(const volatile void __iomem *addr)
31386 {
31387 struct vm_struct *p, *o;
31388
31389@@ -310,6 +310,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
31390
31391 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
31392 if (page_is_ram(start >> PAGE_SHIFT))
31393+#ifdef CONFIG_HIGHMEM
31394+ if ((start >> PAGE_SHIFT) < max_low_pfn)
31395+#endif
31396 return __va(phys);
31397
31398 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
31399@@ -322,6 +325,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
31400 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
31401 {
31402 if (page_is_ram(phys >> PAGE_SHIFT))
31403+#ifdef CONFIG_HIGHMEM
31404+ if ((phys >> PAGE_SHIFT) < max_low_pfn)
31405+#endif
31406 return;
31407
31408 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
31409@@ -339,7 +345,7 @@ static int __init early_ioremap_debug_setup(char *str)
31410 early_param("early_ioremap_debug", early_ioremap_debug_setup);
31411
31412 static __initdata int after_paging_init;
31413-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
31414+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
31415
31416 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
31417 {
31418@@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
31419 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
31420
31421 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
31422- memset(bm_pte, 0, sizeof(bm_pte));
31423- pmd_populate_kernel(&init_mm, pmd, bm_pte);
31424+ pmd_populate_user(&init_mm, pmd, bm_pte);
31425
31426 /*
31427 * The boot-ioremap range spans multiple pmds, for which
31428diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
31429index d87dd6d..bf3fa66 100644
31430--- a/arch/x86/mm/kmemcheck/kmemcheck.c
31431+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
31432@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
31433 * memory (e.g. tracked pages)? For now, we need this to avoid
31434 * invoking kmemcheck for PnP BIOS calls.
31435 */
31436- if (regs->flags & X86_VM_MASK)
31437+ if (v8086_mode(regs))
31438 return false;
31439- if (regs->cs != __KERNEL_CS)
31440+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
31441 return false;
31442
31443 pte = kmemcheck_pte_lookup(address);
31444diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
31445index 25e7e13..1964579 100644
31446--- a/arch/x86/mm/mmap.c
31447+++ b/arch/x86/mm/mmap.c
31448@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
31449 * Leave an at least ~128 MB hole with possible stack randomization.
31450 */
31451 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
31452-#define MAX_GAP (TASK_SIZE/6*5)
31453+#define MAX_GAP (pax_task_size/6*5)
31454
31455 static int mmap_is_legacy(void)
31456 {
31457@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
31458 return rnd << PAGE_SHIFT;
31459 }
31460
31461-static unsigned long mmap_base(void)
31462+static unsigned long mmap_base(struct mm_struct *mm)
31463 {
31464 unsigned long gap = rlimit(RLIMIT_STACK);
31465+ unsigned long pax_task_size = TASK_SIZE;
31466+
31467+#ifdef CONFIG_PAX_SEGMEXEC
31468+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
31469+ pax_task_size = SEGMEXEC_TASK_SIZE;
31470+#endif
31471
31472 if (gap < MIN_GAP)
31473 gap = MIN_GAP;
31474 else if (gap > MAX_GAP)
31475 gap = MAX_GAP;
31476
31477- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
31478+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
31479 }
31480
31481 /*
31482 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
31483 * does, but not when emulating X86_32
31484 */
31485-static unsigned long mmap_legacy_base(void)
31486+static unsigned long mmap_legacy_base(struct mm_struct *mm)
31487 {
31488- if (mmap_is_ia32())
31489+ if (mmap_is_ia32()) {
31490+
31491+#ifdef CONFIG_PAX_SEGMEXEC
31492+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
31493+ return SEGMEXEC_TASK_UNMAPPED_BASE;
31494+ else
31495+#endif
31496+
31497 return TASK_UNMAPPED_BASE;
31498- else
31499+ } else
31500 return TASK_UNMAPPED_BASE + mmap_rnd();
31501 }
31502
31503@@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
31504 */
31505 void arch_pick_mmap_layout(struct mm_struct *mm)
31506 {
31507- mm->mmap_legacy_base = mmap_legacy_base();
31508- mm->mmap_base = mmap_base();
31509+ mm->mmap_legacy_base = mmap_legacy_base(mm);
31510+ mm->mmap_base = mmap_base(mm);
31511+
31512+#ifdef CONFIG_PAX_RANDMMAP
31513+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
31514+ mm->mmap_legacy_base += mm->delta_mmap;
31515+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
31516+ }
31517+#endif
31518
31519 if (mmap_is_legacy()) {
31520 mm->mmap_base = mm->mmap_legacy_base;
31521diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
31522index 0057a7a..95c7edd 100644
31523--- a/arch/x86/mm/mmio-mod.c
31524+++ b/arch/x86/mm/mmio-mod.c
31525@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
31526 break;
31527 default:
31528 {
31529- unsigned char *ip = (unsigned char *)instptr;
31530+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
31531 my_trace->opcode = MMIO_UNKNOWN_OP;
31532 my_trace->width = 0;
31533 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
31534@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
31535 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
31536 void __iomem *addr)
31537 {
31538- static atomic_t next_id;
31539+ static atomic_unchecked_t next_id;
31540 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
31541 /* These are page-unaligned. */
31542 struct mmiotrace_map map = {
31543@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
31544 .private = trace
31545 },
31546 .phys = offset,
31547- .id = atomic_inc_return(&next_id)
31548+ .id = atomic_inc_return_unchecked(&next_id)
31549 };
31550 map.map_id = trace->id;
31551
31552@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
31553 ioremap_trace_core(offset, size, addr);
31554 }
31555
31556-static void iounmap_trace_core(volatile void __iomem *addr)
31557+static void iounmap_trace_core(const volatile void __iomem *addr)
31558 {
31559 struct mmiotrace_map map = {
31560 .phys = 0,
31561@@ -328,7 +328,7 @@ not_enabled:
31562 }
31563 }
31564
31565-void mmiotrace_iounmap(volatile void __iomem *addr)
31566+void mmiotrace_iounmap(const volatile void __iomem *addr)
31567 {
31568 might_sleep();
31569 if (is_enabled()) /* recheck and proper locking in *_core() */
31570diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
31571index 8bf93ba..dbcd670 100644
31572--- a/arch/x86/mm/numa.c
31573+++ b/arch/x86/mm/numa.c
31574@@ -474,7 +474,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
31575 return true;
31576 }
31577
31578-static int __init numa_register_memblks(struct numa_meminfo *mi)
31579+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
31580 {
31581 unsigned long uninitialized_var(pfn_align);
31582 int i, nid;
31583diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
31584index d0b1773..4c3327c 100644
31585--- a/arch/x86/mm/pageattr-test.c
31586+++ b/arch/x86/mm/pageattr-test.c
31587@@ -36,7 +36,7 @@ enum {
31588
31589 static int pte_testbit(pte_t pte)
31590 {
31591- return pte_flags(pte) & _PAGE_UNUSED1;
31592+ return pte_flags(pte) & _PAGE_CPA_TEST;
31593 }
31594
31595 struct split_state {
31596diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
31597index bb32480..75f2f5e 100644
31598--- a/arch/x86/mm/pageattr.c
31599+++ b/arch/x86/mm/pageattr.c
31600@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
31601 */
31602 #ifdef CONFIG_PCI_BIOS
31603 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
31604- pgprot_val(forbidden) |= _PAGE_NX;
31605+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
31606 #endif
31607
31608 /*
31609@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
31610 * Does not cover __inittext since that is gone later on. On
31611 * 64bit we do not enforce !NX on the low mapping
31612 */
31613- if (within(address, (unsigned long)_text, (unsigned long)_etext))
31614- pgprot_val(forbidden) |= _PAGE_NX;
31615+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
31616+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
31617
31618+#ifdef CONFIG_DEBUG_RODATA
31619 /*
31620 * The .rodata section needs to be read-only. Using the pfn
31621 * catches all aliases.
31622@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
31623 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
31624 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
31625 pgprot_val(forbidden) |= _PAGE_RW;
31626+#endif
31627
31628 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
31629 /*
31630@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
31631 }
31632 #endif
31633
31634+#ifdef CONFIG_PAX_KERNEXEC
31635+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
31636+ pgprot_val(forbidden) |= _PAGE_RW;
31637+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
31638+ }
31639+#endif
31640+
31641 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
31642
31643 return prot;
31644@@ -400,23 +409,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
31645 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
31646 {
31647 /* change init_mm */
31648+ pax_open_kernel();
31649 set_pte_atomic(kpte, pte);
31650+
31651 #ifdef CONFIG_X86_32
31652 if (!SHARED_KERNEL_PMD) {
31653+
31654+#ifdef CONFIG_PAX_PER_CPU_PGD
31655+ unsigned long cpu;
31656+#else
31657 struct page *page;
31658+#endif
31659
31660+#ifdef CONFIG_PAX_PER_CPU_PGD
31661+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31662+ pgd_t *pgd = get_cpu_pgd(cpu, kernel);
31663+#else
31664 list_for_each_entry(page, &pgd_list, lru) {
31665- pgd_t *pgd;
31666+ pgd_t *pgd = (pgd_t *)page_address(page);
31667+#endif
31668+
31669 pud_t *pud;
31670 pmd_t *pmd;
31671
31672- pgd = (pgd_t *)page_address(page) + pgd_index(address);
31673+ pgd += pgd_index(address);
31674 pud = pud_offset(pgd, address);
31675 pmd = pmd_offset(pud, address);
31676 set_pte_atomic((pte_t *)pmd, pte);
31677 }
31678 }
31679 #endif
31680+ pax_close_kernel();
31681 }
31682
31683 static int
31684diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
31685index 6574388..87e9bef 100644
31686--- a/arch/x86/mm/pat.c
31687+++ b/arch/x86/mm/pat.c
31688@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
31689
31690 if (!entry) {
31691 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
31692- current->comm, current->pid, start, end - 1);
31693+ current->comm, task_pid_nr(current), start, end - 1);
31694 return -EINVAL;
31695 }
31696
31697@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
31698
31699 while (cursor < to) {
31700 if (!devmem_is_allowed(pfn)) {
31701- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
31702- current->comm, from, to - 1);
31703+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
31704+ current->comm, from, to - 1, cursor);
31705 return 0;
31706 }
31707 cursor += PAGE_SIZE;
31708@@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
31709 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
31710 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
31711 "for [mem %#010Lx-%#010Lx]\n",
31712- current->comm, current->pid,
31713+ current->comm, task_pid_nr(current),
31714 cattr_name(flags),
31715 base, (unsigned long long)(base + size-1));
31716 return -EINVAL;
31717@@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
31718 flags = lookup_memtype(paddr);
31719 if (want_flags != flags) {
31720 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
31721- current->comm, current->pid,
31722+ current->comm, task_pid_nr(current),
31723 cattr_name(want_flags),
31724 (unsigned long long)paddr,
31725 (unsigned long long)(paddr + size - 1),
31726@@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
31727 free_memtype(paddr, paddr + size);
31728 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
31729 " for [mem %#010Lx-%#010Lx], got %s\n",
31730- current->comm, current->pid,
31731+ current->comm, task_pid_nr(current),
31732 cattr_name(want_flags),
31733 (unsigned long long)paddr,
31734 (unsigned long long)(paddr + size - 1),
31735diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
31736index 415f6c4..d319983 100644
31737--- a/arch/x86/mm/pat_rbtree.c
31738+++ b/arch/x86/mm/pat_rbtree.c
31739@@ -160,7 +160,7 @@ success:
31740
31741 failure:
31742 printk(KERN_INFO "%s:%d conflicting memory types "
31743- "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
31744+ "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
31745 end, cattr_name(found_type), cattr_name(match->type));
31746 return -EBUSY;
31747 }
31748diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
31749index 9f0614d..92ae64a 100644
31750--- a/arch/x86/mm/pf_in.c
31751+++ b/arch/x86/mm/pf_in.c
31752@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
31753 int i;
31754 enum reason_type rv = OTHERS;
31755
31756- p = (unsigned char *)ins_addr;
31757+ p = (unsigned char *)ktla_ktva(ins_addr);
31758 p += skip_prefix(p, &prf);
31759 p += get_opcode(p, &opcode);
31760
31761@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
31762 struct prefix_bits prf;
31763 int i;
31764
31765- p = (unsigned char *)ins_addr;
31766+ p = (unsigned char *)ktla_ktva(ins_addr);
31767 p += skip_prefix(p, &prf);
31768 p += get_opcode(p, &opcode);
31769
31770@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
31771 struct prefix_bits prf;
31772 int i;
31773
31774- p = (unsigned char *)ins_addr;
31775+ p = (unsigned char *)ktla_ktva(ins_addr);
31776 p += skip_prefix(p, &prf);
31777 p += get_opcode(p, &opcode);
31778
31779@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
31780 struct prefix_bits prf;
31781 int i;
31782
31783- p = (unsigned char *)ins_addr;
31784+ p = (unsigned char *)ktla_ktva(ins_addr);
31785 p += skip_prefix(p, &prf);
31786 p += get_opcode(p, &opcode);
31787 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
31788@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
31789 struct prefix_bits prf;
31790 int i;
31791
31792- p = (unsigned char *)ins_addr;
31793+ p = (unsigned char *)ktla_ktva(ins_addr);
31794 p += skip_prefix(p, &prf);
31795 p += get_opcode(p, &opcode);
31796 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
31797diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
31798index dfa537a..fd45c64 100644
31799--- a/arch/x86/mm/pgtable.c
31800+++ b/arch/x86/mm/pgtable.c
31801@@ -91,10 +91,67 @@ static inline void pgd_list_del(pgd_t *pgd)
31802 list_del(&page->lru);
31803 }
31804
31805-#define UNSHARED_PTRS_PER_PGD \
31806- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
31807+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31808+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
31809
31810+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
31811+{
31812+ unsigned int count = USER_PGD_PTRS;
31813
31814+ if (!pax_user_shadow_base)
31815+ return;
31816+
31817+ while (count--)
31818+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
31819+}
31820+#endif
31821+
31822+#ifdef CONFIG_PAX_PER_CPU_PGD
31823+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
31824+{
31825+ unsigned int count = USER_PGD_PTRS;
31826+
31827+ while (count--) {
31828+ pgd_t pgd;
31829+
31830+#ifdef CONFIG_X86_64
31831+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
31832+#else
31833+ pgd = *src++;
31834+#endif
31835+
31836+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31837+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
31838+#endif
31839+
31840+ *dst++ = pgd;
31841+ }
31842+
31843+}
31844+#endif
31845+
31846+#ifdef CONFIG_X86_64
31847+#define pxd_t pud_t
31848+#define pyd_t pgd_t
31849+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
31850+#define pxd_free(mm, pud) pud_free((mm), (pud))
31851+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
31852+#define pyd_offset(mm, address) pgd_offset((mm), (address))
31853+#define PYD_SIZE PGDIR_SIZE
31854+#else
31855+#define pxd_t pmd_t
31856+#define pyd_t pud_t
31857+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
31858+#define pxd_free(mm, pud) pmd_free((mm), (pud))
31859+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
31860+#define pyd_offset(mm, address) pud_offset((mm), (address))
31861+#define PYD_SIZE PUD_SIZE
31862+#endif
31863+
31864+#ifdef CONFIG_PAX_PER_CPU_PGD
31865+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
31866+static inline void pgd_dtor(pgd_t *pgd) {}
31867+#else
31868 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
31869 {
31870 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
31871@@ -135,6 +192,7 @@ static void pgd_dtor(pgd_t *pgd)
31872 pgd_list_del(pgd);
31873 spin_unlock(&pgd_lock);
31874 }
31875+#endif
31876
31877 /*
31878 * List of all pgd's needed for non-PAE so it can invalidate entries
31879@@ -147,7 +205,7 @@ static void pgd_dtor(pgd_t *pgd)
31880 * -- nyc
31881 */
31882
31883-#ifdef CONFIG_X86_PAE
31884+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
31885 /*
31886 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
31887 * updating the top-level pagetable entries to guarantee the
31888@@ -159,7 +217,7 @@ static void pgd_dtor(pgd_t *pgd)
31889 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
31890 * and initialize the kernel pmds here.
31891 */
31892-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
31893+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
31894
31895 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
31896 {
31897@@ -177,36 +235,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
31898 */
31899 flush_tlb_mm(mm);
31900 }
31901+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
31902+#define PREALLOCATED_PXDS USER_PGD_PTRS
31903 #else /* !CONFIG_X86_PAE */
31904
31905 /* No need to prepopulate any pagetable entries in non-PAE modes. */
31906-#define PREALLOCATED_PMDS 0
31907+#define PREALLOCATED_PXDS 0
31908
31909 #endif /* CONFIG_X86_PAE */
31910
31911-static void free_pmds(pmd_t *pmds[])
31912+static void free_pxds(pxd_t *pxds[])
31913 {
31914 int i;
31915
31916- for(i = 0; i < PREALLOCATED_PMDS; i++)
31917- if (pmds[i])
31918- free_page((unsigned long)pmds[i]);
31919+ for(i = 0; i < PREALLOCATED_PXDS; i++)
31920+ if (pxds[i])
31921+ free_page((unsigned long)pxds[i]);
31922 }
31923
31924-static int preallocate_pmds(pmd_t *pmds[])
31925+static int preallocate_pxds(pxd_t *pxds[])
31926 {
31927 int i;
31928 bool failed = false;
31929
31930- for(i = 0; i < PREALLOCATED_PMDS; i++) {
31931- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
31932- if (pmd == NULL)
31933+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
31934+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
31935+ if (pxd == NULL)
31936 failed = true;
31937- pmds[i] = pmd;
31938+ pxds[i] = pxd;
31939 }
31940
31941 if (failed) {
31942- free_pmds(pmds);
31943+ free_pxds(pxds);
31944 return -ENOMEM;
31945 }
31946
31947@@ -219,49 +279,52 @@ static int preallocate_pmds(pmd_t *pmds[])
31948 * preallocate which never got a corresponding vma will need to be
31949 * freed manually.
31950 */
31951-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
31952+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
31953 {
31954 int i;
31955
31956- for(i = 0; i < PREALLOCATED_PMDS; i++) {
31957+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
31958 pgd_t pgd = pgdp[i];
31959
31960 if (pgd_val(pgd) != 0) {
31961- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
31962+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
31963
31964- pgdp[i] = native_make_pgd(0);
31965+ set_pgd(pgdp + i, native_make_pgd(0));
31966
31967- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
31968- pmd_free(mm, pmd);
31969+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
31970+ pxd_free(mm, pxd);
31971 }
31972 }
31973 }
31974
31975-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
31976+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
31977 {
31978- pud_t *pud;
31979+ pyd_t *pyd;
31980 int i;
31981
31982- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
31983+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
31984 return;
31985
31986- pud = pud_offset(pgd, 0);
31987-
31988- for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
31989- pmd_t *pmd = pmds[i];
31990+#ifdef CONFIG_X86_64
31991+ pyd = pyd_offset(mm, 0L);
31992+#else
31993+ pyd = pyd_offset(pgd, 0L);
31994+#endif
31995
31996+ for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
31997+ pxd_t *pxd = pxds[i];
31998 if (i >= KERNEL_PGD_BOUNDARY)
31999- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
32000- sizeof(pmd_t) * PTRS_PER_PMD);
32001+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
32002+ sizeof(pxd_t) * PTRS_PER_PMD);
32003
32004- pud_populate(mm, pud, pmd);
32005+ pyd_populate(mm, pyd, pxd);
32006 }
32007 }
32008
32009 pgd_t *pgd_alloc(struct mm_struct *mm)
32010 {
32011 pgd_t *pgd;
32012- pmd_t *pmds[PREALLOCATED_PMDS];
32013+ pxd_t *pxds[PREALLOCATED_PXDS];
32014
32015 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
32016
32017@@ -270,11 +333,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
32018
32019 mm->pgd = pgd;
32020
32021- if (preallocate_pmds(pmds) != 0)
32022+ if (preallocate_pxds(pxds) != 0)
32023 goto out_free_pgd;
32024
32025 if (paravirt_pgd_alloc(mm) != 0)
32026- goto out_free_pmds;
32027+ goto out_free_pxds;
32028
32029 /*
32030 * Make sure that pre-populating the pmds is atomic with
32031@@ -284,14 +347,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
32032 spin_lock(&pgd_lock);
32033
32034 pgd_ctor(mm, pgd);
32035- pgd_prepopulate_pmd(mm, pgd, pmds);
32036+ pgd_prepopulate_pxd(mm, pgd, pxds);
32037
32038 spin_unlock(&pgd_lock);
32039
32040 return pgd;
32041
32042-out_free_pmds:
32043- free_pmds(pmds);
32044+out_free_pxds:
32045+ free_pxds(pxds);
32046 out_free_pgd:
32047 free_page((unsigned long)pgd);
32048 out:
32049@@ -300,7 +363,7 @@ out:
32050
32051 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
32052 {
32053- pgd_mop_up_pmds(mm, pgd);
32054+ pgd_mop_up_pxds(mm, pgd);
32055 pgd_dtor(pgd);
32056 paravirt_pgd_free(mm, pgd);
32057 free_page((unsigned long)pgd);
32058diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
32059index a69bcb8..19068ab 100644
32060--- a/arch/x86/mm/pgtable_32.c
32061+++ b/arch/x86/mm/pgtable_32.c
32062@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
32063 return;
32064 }
32065 pte = pte_offset_kernel(pmd, vaddr);
32066+
32067+ pax_open_kernel();
32068 if (pte_val(pteval))
32069 set_pte_at(&init_mm, vaddr, pte, pteval);
32070 else
32071 pte_clear(&init_mm, vaddr, pte);
32072+ pax_close_kernel();
32073
32074 /*
32075 * It's enough to flush this one mapping.
32076diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
32077index e666cbb..61788c45 100644
32078--- a/arch/x86/mm/physaddr.c
32079+++ b/arch/x86/mm/physaddr.c
32080@@ -10,7 +10,7 @@
32081 #ifdef CONFIG_X86_64
32082
32083 #ifdef CONFIG_DEBUG_VIRTUAL
32084-unsigned long __phys_addr(unsigned long x)
32085+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
32086 {
32087 unsigned long y = x - __START_KERNEL_map;
32088
32089@@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
32090 #else
32091
32092 #ifdef CONFIG_DEBUG_VIRTUAL
32093-unsigned long __phys_addr(unsigned long x)
32094+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
32095 {
32096 unsigned long phys_addr = x - PAGE_OFFSET;
32097 /* VMALLOC_* aren't constants */
32098diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
32099index 90555bf..f5f1828 100644
32100--- a/arch/x86/mm/setup_nx.c
32101+++ b/arch/x86/mm/setup_nx.c
32102@@ -5,8 +5,10 @@
32103 #include <asm/pgtable.h>
32104 #include <asm/proto.h>
32105
32106+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
32107 static int disable_nx;
32108
32109+#ifndef CONFIG_PAX_PAGEEXEC
32110 /*
32111 * noexec = on|off
32112 *
32113@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
32114 return 0;
32115 }
32116 early_param("noexec", noexec_setup);
32117+#endif
32118+
32119+#endif
32120
32121 void x86_configure_nx(void)
32122 {
32123+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
32124 if (cpu_has_nx && !disable_nx)
32125 __supported_pte_mask |= _PAGE_NX;
32126 else
32127+#endif
32128 __supported_pte_mask &= ~_PAGE_NX;
32129 }
32130
32131diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
32132index 282375f..e03a98f 100644
32133--- a/arch/x86/mm/tlb.c
32134+++ b/arch/x86/mm/tlb.c
32135@@ -48,7 +48,11 @@ void leave_mm(int cpu)
32136 BUG();
32137 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
32138 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
32139+
32140+#ifndef CONFIG_PAX_PER_CPU_PGD
32141 load_cr3(swapper_pg_dir);
32142+#endif
32143+
32144 }
32145 }
32146 EXPORT_SYMBOL_GPL(leave_mm);
32147diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
32148new file mode 100644
32149index 0000000..dace51c
32150--- /dev/null
32151+++ b/arch/x86/mm/uderef_64.c
32152@@ -0,0 +1,37 @@
32153+#include <linux/mm.h>
32154+#include <asm/pgtable.h>
32155+#include <asm/uaccess.h>
32156+
32157+#ifdef CONFIG_PAX_MEMORY_UDEREF
32158+/* PaX: due to the special call convention these functions must
32159+ * - remain leaf functions under all configurations,
32160+ * - never be called directly, only dereferenced from the wrappers.
32161+ */
32162+void __pax_open_userland(void)
32163+{
32164+ unsigned int cpu;
32165+
32166+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
32167+ return;
32168+
32169+ cpu = raw_get_cpu();
32170+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
32171+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
32172+ raw_put_cpu_no_resched();
32173+}
32174+EXPORT_SYMBOL(__pax_open_userland);
32175+
32176+void __pax_close_userland(void)
32177+{
32178+ unsigned int cpu;
32179+
32180+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
32181+ return;
32182+
32183+ cpu = raw_get_cpu();
32184+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
32185+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
32186+ raw_put_cpu_no_resched();
32187+}
32188+EXPORT_SYMBOL(__pax_close_userland);
32189+#endif
32190diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
32191index 877b9a1..a8ecf42 100644
32192--- a/arch/x86/net/bpf_jit.S
32193+++ b/arch/x86/net/bpf_jit.S
32194@@ -9,6 +9,7 @@
32195 */
32196 #include <linux/linkage.h>
32197 #include <asm/dwarf2.h>
32198+#include <asm/alternative-asm.h>
32199
32200 /*
32201 * Calling convention :
32202@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
32203 jle bpf_slow_path_word
32204 mov (SKBDATA,%rsi),%eax
32205 bswap %eax /* ntohl() */
32206+ pax_force_retaddr
32207 ret
32208
32209 sk_load_half:
32210@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
32211 jle bpf_slow_path_half
32212 movzwl (SKBDATA,%rsi),%eax
32213 rol $8,%ax # ntohs()
32214+ pax_force_retaddr
32215 ret
32216
32217 sk_load_byte:
32218@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
32219 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
32220 jle bpf_slow_path_byte
32221 movzbl (SKBDATA,%rsi),%eax
32222+ pax_force_retaddr
32223 ret
32224
32225 /**
32226@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
32227 movzbl (SKBDATA,%rsi),%ebx
32228 and $15,%bl
32229 shl $2,%bl
32230+ pax_force_retaddr
32231 ret
32232
32233 /* rsi contains offset and can be scratched */
32234@@ -109,6 +114,7 @@ bpf_slow_path_word:
32235 js bpf_error
32236 mov -12(%rbp),%eax
32237 bswap %eax
32238+ pax_force_retaddr
32239 ret
32240
32241 bpf_slow_path_half:
32242@@ -117,12 +123,14 @@ bpf_slow_path_half:
32243 mov -12(%rbp),%ax
32244 rol $8,%ax
32245 movzwl %ax,%eax
32246+ pax_force_retaddr
32247 ret
32248
32249 bpf_slow_path_byte:
32250 bpf_slow_path_common(1)
32251 js bpf_error
32252 movzbl -12(%rbp),%eax
32253+ pax_force_retaddr
32254 ret
32255
32256 bpf_slow_path_byte_msh:
32257@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
32258 and $15,%al
32259 shl $2,%al
32260 xchg %eax,%ebx
32261+ pax_force_retaddr
32262 ret
32263
32264 #define sk_negative_common(SIZE) \
32265@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
32266 sk_negative_common(4)
32267 mov (%rax), %eax
32268 bswap %eax
32269+ pax_force_retaddr
32270 ret
32271
32272 bpf_slow_path_half_neg:
32273@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
32274 mov (%rax),%ax
32275 rol $8,%ax
32276 movzwl %ax,%eax
32277+ pax_force_retaddr
32278 ret
32279
32280 bpf_slow_path_byte_neg:
32281@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
32282 .globl sk_load_byte_negative_offset
32283 sk_negative_common(1)
32284 movzbl (%rax), %eax
32285+ pax_force_retaddr
32286 ret
32287
32288 bpf_slow_path_byte_msh_neg:
32289@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
32290 and $15,%al
32291 shl $2,%al
32292 xchg %eax,%ebx
32293+ pax_force_retaddr
32294 ret
32295
32296 bpf_error:
32297@@ -197,4 +210,5 @@ bpf_error:
32298 xor %eax,%eax
32299 mov -8(%rbp),%rbx
32300 leaveq
32301+ pax_force_retaddr
32302 ret
32303diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
32304index 79c216a..08d39cc 100644
32305--- a/arch/x86/net/bpf_jit_comp.c
32306+++ b/arch/x86/net/bpf_jit_comp.c
32307@@ -50,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
32308 return ptr + len;
32309 }
32310
32311+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32312+#define MAX_INSTR_CODE_SIZE 96
32313+#else
32314+#define MAX_INSTR_CODE_SIZE 64
32315+#endif
32316+
32317 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
32318
32319 #define EMIT1(b1) EMIT(b1, 1)
32320 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
32321 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
32322 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
32323+
32324+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32325+/* original constant will appear in ecx */
32326+#define DILUTE_CONST_SEQUENCE(_off, _key) \
32327+do { \
32328+ /* mov ecx, randkey */ \
32329+ EMIT1(0xb9); \
32330+ EMIT(_key, 4); \
32331+ /* xor ecx, randkey ^ off */ \
32332+ EMIT2(0x81, 0xf1); \
32333+ EMIT((_key) ^ (_off), 4); \
32334+} while (0)
32335+
32336+#define EMIT1_off32(b1, _off) \
32337+do { \
32338+ switch (b1) { \
32339+ case 0x05: /* add eax, imm32 */ \
32340+ case 0x2d: /* sub eax, imm32 */ \
32341+ case 0x25: /* and eax, imm32 */ \
32342+ case 0x0d: /* or eax, imm32 */ \
32343+ case 0xb8: /* mov eax, imm32 */ \
32344+ case 0x35: /* xor eax, imm32 */ \
32345+ case 0x3d: /* cmp eax, imm32 */ \
32346+ case 0xa9: /* test eax, imm32 */ \
32347+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32348+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
32349+ break; \
32350+ case 0xbb: /* mov ebx, imm32 */ \
32351+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32352+ /* mov ebx, ecx */ \
32353+ EMIT2(0x89, 0xcb); \
32354+ break; \
32355+ case 0xbe: /* mov esi, imm32 */ \
32356+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32357+ /* mov esi, ecx */ \
32358+ EMIT2(0x89, 0xce); \
32359+ break; \
32360+ case 0xe8: /* call rel imm32, always to known funcs */ \
32361+ EMIT1(b1); \
32362+ EMIT(_off, 4); \
32363+ break; \
32364+ case 0xe9: /* jmp rel imm32 */ \
32365+ EMIT1(b1); \
32366+ EMIT(_off, 4); \
32367+ /* prevent fall-through, we're not called if off = 0 */ \
32368+ EMIT(0xcccccccc, 4); \
32369+ EMIT(0xcccccccc, 4); \
32370+ break; \
32371+ default: \
32372+ BUILD_BUG(); \
32373+ } \
32374+} while (0)
32375+
32376+#define EMIT2_off32(b1, b2, _off) \
32377+do { \
32378+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
32379+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
32380+ EMIT(randkey, 4); \
32381+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
32382+ EMIT((_off) - randkey, 4); \
32383+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
32384+ DILUTE_CONST_SEQUENCE(_off, randkey); \
32385+ /* imul eax, ecx */ \
32386+ EMIT3(0x0f, 0xaf, 0xc1); \
32387+ } else { \
32388+ BUILD_BUG(); \
32389+ } \
32390+} while (0)
32391+#else
32392 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
32393+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
32394+#endif
32395
32396 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
32397 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
32398@@ -91,6 +168,24 @@ do { \
32399 #define X86_JBE 0x76
32400 #define X86_JA 0x77
32401
32402+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32403+#define APPEND_FLOW_VERIFY() \
32404+do { \
32405+ /* mov ecx, randkey */ \
32406+ EMIT1(0xb9); \
32407+ EMIT(randkey, 4); \
32408+ /* cmp ecx, randkey */ \
32409+ EMIT2(0x81, 0xf9); \
32410+ EMIT(randkey, 4); \
32411+ /* jz after 8 int 3s */ \
32412+ EMIT2(0x74, 0x08); \
32413+ EMIT(0xcccccccc, 4); \
32414+ EMIT(0xcccccccc, 4); \
32415+} while (0)
32416+#else
32417+#define APPEND_FLOW_VERIFY() do { } while (0)
32418+#endif
32419+
32420 #define EMIT_COND_JMP(op, offset) \
32421 do { \
32422 if (is_near(offset)) \
32423@@ -98,6 +193,7 @@ do { \
32424 else { \
32425 EMIT2(0x0f, op + 0x10); \
32426 EMIT(offset, 4); /* jxx .+off32 */ \
32427+ APPEND_FLOW_VERIFY(); \
32428 } \
32429 } while (0)
32430
32431@@ -145,55 +241,54 @@ static int pkt_type_offset(void)
32432 return -1;
32433 }
32434
32435-struct bpf_binary_header {
32436- unsigned int pages;
32437- /* Note : for security reasons, bpf code will follow a randomly
32438- * sized amount of int3 instructions
32439- */
32440- u8 image[];
32441-};
32442-
32443-static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
32444+/* Note : for security reasons, bpf code will follow a randomly
32445+ * sized amount of int3 instructions
32446+ */
32447+static u8 *bpf_alloc_binary(unsigned int proglen,
32448 u8 **image_ptr)
32449 {
32450 unsigned int sz, hole;
32451- struct bpf_binary_header *header;
32452+ u8 *header;
32453
32454 /* Most of BPF filters are really small,
32455 * but if some of them fill a page, allow at least
32456 * 128 extra bytes to insert a random section of int3
32457 */
32458- sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
32459- header = module_alloc(sz);
32460+ sz = round_up(proglen + 128, PAGE_SIZE);
32461+ header = module_alloc_exec(sz);
32462 if (!header)
32463 return NULL;
32464
32465+ pax_open_kernel();
32466 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
32467+ pax_close_kernel();
32468
32469- header->pages = sz / PAGE_SIZE;
32470- hole = sz - (proglen + sizeof(*header));
32471+ hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
32472
32473 /* insert a random number of int3 instructions before BPF code */
32474- *image_ptr = &header->image[prandom_u32() % hole];
32475+ *image_ptr = &header[prandom_u32() % hole];
32476 return header;
32477 }
32478
32479 void bpf_jit_compile(struct sk_filter *fp)
32480 {
32481- u8 temp[64];
32482+ u8 temp[MAX_INSTR_CODE_SIZE];
32483 u8 *prog;
32484 unsigned int proglen, oldproglen = 0;
32485 int ilen, i;
32486 int t_offset, f_offset;
32487 u8 t_op, f_op, seen = 0, pass;
32488 u8 *image = NULL;
32489- struct bpf_binary_header *header = NULL;
32490+ u8 *header = NULL;
32491 u8 *func;
32492 int pc_ret0 = -1; /* bpf index of first RET #0 instruction (if any) */
32493 unsigned int cleanup_addr; /* epilogue code offset */
32494 unsigned int *addrs;
32495 const struct sock_filter *filter = fp->insns;
32496 int flen = fp->len;
32497+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32498+ unsigned int randkey;
32499+#endif
32500
32501 if (!bpf_jit_enable)
32502 return;
32503@@ -202,11 +297,15 @@ void bpf_jit_compile(struct sk_filter *fp)
32504 if (addrs == NULL)
32505 return;
32506
32507+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32508+ randkey = get_random_int();
32509+#endif
32510+
32511 /* Before first pass, make a rough estimation of addrs[]
32512- * each bpf instruction is translated to less than 64 bytes
32513+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
32514 */
32515 for (proglen = 0, i = 0; i < flen; i++) {
32516- proglen += 64;
32517+ proglen += MAX_INSTR_CODE_SIZE;
32518 addrs[i] = proglen;
32519 }
32520 cleanup_addr = proglen; /* epilogue address */
32521@@ -317,10 +416,8 @@ void bpf_jit_compile(struct sk_filter *fp)
32522 case BPF_S_ALU_MUL_K: /* A *= K */
32523 if (is_imm8(K))
32524 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
32525- else {
32526- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
32527- EMIT(K, 4);
32528- }
32529+ else
32530+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
32531 break;
32532 case BPF_S_ALU_DIV_X: /* A /= X; */
32533 seen |= SEEN_XREG;
32534@@ -360,13 +457,23 @@ void bpf_jit_compile(struct sk_filter *fp)
32535 break;
32536 case BPF_S_ALU_MOD_K: /* A %= K; */
32537 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
32538+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32539+ DILUTE_CONST_SEQUENCE(K, randkey);
32540+#else
32541 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
32542+#endif
32543 EMIT2(0xf7, 0xf1); /* div %ecx */
32544 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
32545 break;
32546 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
32547+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
32548+ DILUTE_CONST_SEQUENCE(K, randkey);
32549+ // imul rax, rcx
32550+ EMIT4(0x48, 0x0f, 0xaf, 0xc1);
32551+#else
32552 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
32553 EMIT(K, 4);
32554+#endif
32555 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
32556 break;
32557 case BPF_S_ALU_AND_X:
32558@@ -637,8 +744,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
32559 if (is_imm8(K)) {
32560 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
32561 } else {
32562- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
32563- EMIT(K, 4);
32564+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
32565 }
32566 } else {
32567 EMIT2(0x89,0xde); /* mov %ebx,%esi */
32568@@ -728,10 +834,12 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
32569 if (unlikely(proglen + ilen > oldproglen)) {
32570 pr_err("bpb_jit_compile fatal error\n");
32571 kfree(addrs);
32572- module_free(NULL, header);
32573+ module_free_exec(NULL, image);
32574 return;
32575 }
32576+ pax_open_kernel();
32577 memcpy(image + proglen, temp, ilen);
32578+ pax_close_kernel();
32579 }
32580 proglen += ilen;
32581 addrs[i] = proglen;
32582@@ -764,7 +872,6 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
32583
32584 if (image) {
32585 bpf_flush_icache(header, image + proglen);
32586- set_memory_ro((unsigned long)header, header->pages);
32587 fp->bpf_func = (void *)image;
32588 }
32589 out:
32590@@ -776,9 +883,7 @@ void bpf_jit_free(struct sk_filter *fp)
32591 {
32592 if (fp->bpf_func != sk_run_filter) {
32593 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
32594- struct bpf_binary_header *header = (void *)addr;
32595-
32596- set_memory_rw(addr, header->pages);
32597- module_free(NULL, header);
32598+ set_memory_rw(addr, 1);
32599+ module_free_exec(NULL, (void *)addr);
32600 }
32601 }
32602diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
32603index d6aa6e8..266395a 100644
32604--- a/arch/x86/oprofile/backtrace.c
32605+++ b/arch/x86/oprofile/backtrace.c
32606@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
32607 struct stack_frame_ia32 *fp;
32608 unsigned long bytes;
32609
32610- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
32611+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
32612 if (bytes != sizeof(bufhead))
32613 return NULL;
32614
32615- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
32616+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
32617
32618 oprofile_add_trace(bufhead[0].return_address);
32619
32620@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
32621 struct stack_frame bufhead[2];
32622 unsigned long bytes;
32623
32624- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
32625+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
32626 if (bytes != sizeof(bufhead))
32627 return NULL;
32628
32629@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
32630 {
32631 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
32632
32633- if (!user_mode_vm(regs)) {
32634+ if (!user_mode(regs)) {
32635 unsigned long stack = kernel_stack_pointer(regs);
32636 if (depth)
32637 dump_trace(NULL, regs, (unsigned long *)stack, 0,
32638diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
32639index 48768df..ba9143c 100644
32640--- a/arch/x86/oprofile/nmi_int.c
32641+++ b/arch/x86/oprofile/nmi_int.c
32642@@ -23,6 +23,7 @@
32643 #include <asm/nmi.h>
32644 #include <asm/msr.h>
32645 #include <asm/apic.h>
32646+#include <asm/pgtable.h>
32647
32648 #include "op_counter.h"
32649 #include "op_x86_model.h"
32650@@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
32651 if (ret)
32652 return ret;
32653
32654- if (!model->num_virt_counters)
32655- model->num_virt_counters = model->num_counters;
32656+ if (!model->num_virt_counters) {
32657+ pax_open_kernel();
32658+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
32659+ pax_close_kernel();
32660+ }
32661
32662 mux_init(ops);
32663
32664diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
32665index b2b9443..be58856 100644
32666--- a/arch/x86/oprofile/op_model_amd.c
32667+++ b/arch/x86/oprofile/op_model_amd.c
32668@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
32669 num_counters = AMD64_NUM_COUNTERS;
32670 }
32671
32672- op_amd_spec.num_counters = num_counters;
32673- op_amd_spec.num_controls = num_counters;
32674- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
32675+ pax_open_kernel();
32676+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
32677+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
32678+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
32679+ pax_close_kernel();
32680
32681 return 0;
32682 }
32683diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
32684index d90528e..0127e2b 100644
32685--- a/arch/x86/oprofile/op_model_ppro.c
32686+++ b/arch/x86/oprofile/op_model_ppro.c
32687@@ -19,6 +19,7 @@
32688 #include <asm/msr.h>
32689 #include <asm/apic.h>
32690 #include <asm/nmi.h>
32691+#include <asm/pgtable.h>
32692
32693 #include "op_x86_model.h"
32694 #include "op_counter.h"
32695@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
32696
32697 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
32698
32699- op_arch_perfmon_spec.num_counters = num_counters;
32700- op_arch_perfmon_spec.num_controls = num_counters;
32701+ pax_open_kernel();
32702+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
32703+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
32704+ pax_close_kernel();
32705 }
32706
32707 static int arch_perfmon_init(struct oprofile_operations *ignore)
32708diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
32709index 71e8a67..6a313bb 100644
32710--- a/arch/x86/oprofile/op_x86_model.h
32711+++ b/arch/x86/oprofile/op_x86_model.h
32712@@ -52,7 +52,7 @@ struct op_x86_model_spec {
32713 void (*switch_ctrl)(struct op_x86_model_spec const *model,
32714 struct op_msrs const * const msrs);
32715 #endif
32716-};
32717+} __do_const;
32718
32719 struct op_counter_config;
32720
32721diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
32722index 372e9b8..e775a6c 100644
32723--- a/arch/x86/pci/irq.c
32724+++ b/arch/x86/pci/irq.c
32725@@ -50,7 +50,7 @@ struct irq_router {
32726 struct irq_router_handler {
32727 u16 vendor;
32728 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
32729-};
32730+} __do_const;
32731
32732 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
32733 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
32734@@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
32735 return 0;
32736 }
32737
32738-static __initdata struct irq_router_handler pirq_routers[] = {
32739+static __initconst const struct irq_router_handler pirq_routers[] = {
32740 { PCI_VENDOR_ID_INTEL, intel_router_probe },
32741 { PCI_VENDOR_ID_AL, ali_router_probe },
32742 { PCI_VENDOR_ID_ITE, ite_router_probe },
32743@@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
32744 static void __init pirq_find_router(struct irq_router *r)
32745 {
32746 struct irq_routing_table *rt = pirq_table;
32747- struct irq_router_handler *h;
32748+ const struct irq_router_handler *h;
32749
32750 #ifdef CONFIG_PCI_BIOS
32751 if (!rt->signature) {
32752@@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
32753 return 0;
32754 }
32755
32756-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
32757+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
32758 {
32759 .callback = fix_broken_hp_bios_irq9,
32760 .ident = "HP Pavilion N5400 Series Laptop",
32761diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
32762index 6eb18c4..20d83de 100644
32763--- a/arch/x86/pci/mrst.c
32764+++ b/arch/x86/pci/mrst.c
32765@@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
32766 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
32767 pci_mmcfg_late_init();
32768 pcibios_enable_irq = mrst_pci_irq_enable;
32769- pci_root_ops = pci_mrst_ops;
32770+ pax_open_kernel();
32771+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
32772+ pax_close_kernel();
32773 pci_soc_mode = 1;
32774 /* Continue with standard init */
32775 return 1;
32776diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
32777index c77b24a..c979855 100644
32778--- a/arch/x86/pci/pcbios.c
32779+++ b/arch/x86/pci/pcbios.c
32780@@ -79,7 +79,7 @@ union bios32 {
32781 static struct {
32782 unsigned long address;
32783 unsigned short segment;
32784-} bios32_indirect = { 0, __KERNEL_CS };
32785+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
32786
32787 /*
32788 * Returns the entry point for the given service, NULL on error
32789@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
32790 unsigned long length; /* %ecx */
32791 unsigned long entry; /* %edx */
32792 unsigned long flags;
32793+ struct desc_struct d, *gdt;
32794
32795 local_irq_save(flags);
32796- __asm__("lcall *(%%edi); cld"
32797+
32798+ gdt = get_cpu_gdt_table(smp_processor_id());
32799+
32800+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
32801+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
32802+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
32803+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
32804+
32805+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
32806 : "=a" (return_code),
32807 "=b" (address),
32808 "=c" (length),
32809 "=d" (entry)
32810 : "0" (service),
32811 "1" (0),
32812- "D" (&bios32_indirect));
32813+ "D" (&bios32_indirect),
32814+ "r"(__PCIBIOS_DS)
32815+ : "memory");
32816+
32817+ pax_open_kernel();
32818+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
32819+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
32820+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
32821+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
32822+ pax_close_kernel();
32823+
32824 local_irq_restore(flags);
32825
32826 switch (return_code) {
32827- case 0:
32828- return address + entry;
32829- case 0x80: /* Not present */
32830- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
32831- return 0;
32832- default: /* Shouldn't happen */
32833- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
32834- service, return_code);
32835+ case 0: {
32836+ int cpu;
32837+ unsigned char flags;
32838+
32839+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
32840+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
32841+ printk(KERN_WARNING "bios32_service: not valid\n");
32842 return 0;
32843+ }
32844+ address = address + PAGE_OFFSET;
32845+ length += 16UL; /* some BIOSs underreport this... */
32846+ flags = 4;
32847+ if (length >= 64*1024*1024) {
32848+ length >>= PAGE_SHIFT;
32849+ flags |= 8;
32850+ }
32851+
32852+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
32853+ gdt = get_cpu_gdt_table(cpu);
32854+ pack_descriptor(&d, address, length, 0x9b, flags);
32855+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
32856+ pack_descriptor(&d, address, length, 0x93, flags);
32857+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
32858+ }
32859+ return entry;
32860+ }
32861+ case 0x80: /* Not present */
32862+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
32863+ return 0;
32864+ default: /* Shouldn't happen */
32865+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
32866+ service, return_code);
32867+ return 0;
32868 }
32869 }
32870
32871 static struct {
32872 unsigned long address;
32873 unsigned short segment;
32874-} pci_indirect = { 0, __KERNEL_CS };
32875+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
32876
32877-static int pci_bios_present;
32878+static int pci_bios_present __read_only;
32879
32880 static int check_pcibios(void)
32881 {
32882@@ -131,11 +174,13 @@ static int check_pcibios(void)
32883 unsigned long flags, pcibios_entry;
32884
32885 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
32886- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
32887+ pci_indirect.address = pcibios_entry;
32888
32889 local_irq_save(flags);
32890- __asm__(
32891- "lcall *(%%edi); cld\n\t"
32892+ __asm__("movw %w6, %%ds\n\t"
32893+ "lcall *%%ss:(%%edi); cld\n\t"
32894+ "push %%ss\n\t"
32895+ "pop %%ds\n\t"
32896 "jc 1f\n\t"
32897 "xor %%ah, %%ah\n"
32898 "1:"
32899@@ -144,7 +189,8 @@ static int check_pcibios(void)
32900 "=b" (ebx),
32901 "=c" (ecx)
32902 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
32903- "D" (&pci_indirect)
32904+ "D" (&pci_indirect),
32905+ "r" (__PCIBIOS_DS)
32906 : "memory");
32907 local_irq_restore(flags);
32908
32909@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32910
32911 switch (len) {
32912 case 1:
32913- __asm__("lcall *(%%esi); cld\n\t"
32914+ __asm__("movw %w6, %%ds\n\t"
32915+ "lcall *%%ss:(%%esi); cld\n\t"
32916+ "push %%ss\n\t"
32917+ "pop %%ds\n\t"
32918 "jc 1f\n\t"
32919 "xor %%ah, %%ah\n"
32920 "1:"
32921@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32922 : "1" (PCIBIOS_READ_CONFIG_BYTE),
32923 "b" (bx),
32924 "D" ((long)reg),
32925- "S" (&pci_indirect));
32926+ "S" (&pci_indirect),
32927+ "r" (__PCIBIOS_DS));
32928 /*
32929 * Zero-extend the result beyond 8 bits, do not trust the
32930 * BIOS having done it:
32931@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32932 *value &= 0xff;
32933 break;
32934 case 2:
32935- __asm__("lcall *(%%esi); cld\n\t"
32936+ __asm__("movw %w6, %%ds\n\t"
32937+ "lcall *%%ss:(%%esi); cld\n\t"
32938+ "push %%ss\n\t"
32939+ "pop %%ds\n\t"
32940 "jc 1f\n\t"
32941 "xor %%ah, %%ah\n"
32942 "1:"
32943@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32944 : "1" (PCIBIOS_READ_CONFIG_WORD),
32945 "b" (bx),
32946 "D" ((long)reg),
32947- "S" (&pci_indirect));
32948+ "S" (&pci_indirect),
32949+ "r" (__PCIBIOS_DS));
32950 /*
32951 * Zero-extend the result beyond 16 bits, do not trust the
32952 * BIOS having done it:
32953@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32954 *value &= 0xffff;
32955 break;
32956 case 4:
32957- __asm__("lcall *(%%esi); cld\n\t"
32958+ __asm__("movw %w6, %%ds\n\t"
32959+ "lcall *%%ss:(%%esi); cld\n\t"
32960+ "push %%ss\n\t"
32961+ "pop %%ds\n\t"
32962 "jc 1f\n\t"
32963 "xor %%ah, %%ah\n"
32964 "1:"
32965@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
32966 : "1" (PCIBIOS_READ_CONFIG_DWORD),
32967 "b" (bx),
32968 "D" ((long)reg),
32969- "S" (&pci_indirect));
32970+ "S" (&pci_indirect),
32971+ "r" (__PCIBIOS_DS));
32972 break;
32973 }
32974
32975@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
32976
32977 switch (len) {
32978 case 1:
32979- __asm__("lcall *(%%esi); cld\n\t"
32980+ __asm__("movw %w6, %%ds\n\t"
32981+ "lcall *%%ss:(%%esi); cld\n\t"
32982+ "push %%ss\n\t"
32983+ "pop %%ds\n\t"
32984 "jc 1f\n\t"
32985 "xor %%ah, %%ah\n"
32986 "1:"
32987@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
32988 "c" (value),
32989 "b" (bx),
32990 "D" ((long)reg),
32991- "S" (&pci_indirect));
32992+ "S" (&pci_indirect),
32993+ "r" (__PCIBIOS_DS));
32994 break;
32995 case 2:
32996- __asm__("lcall *(%%esi); cld\n\t"
32997+ __asm__("movw %w6, %%ds\n\t"
32998+ "lcall *%%ss:(%%esi); cld\n\t"
32999+ "push %%ss\n\t"
33000+ "pop %%ds\n\t"
33001 "jc 1f\n\t"
33002 "xor %%ah, %%ah\n"
33003 "1:"
33004@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33005 "c" (value),
33006 "b" (bx),
33007 "D" ((long)reg),
33008- "S" (&pci_indirect));
33009+ "S" (&pci_indirect),
33010+ "r" (__PCIBIOS_DS));
33011 break;
33012 case 4:
33013- __asm__("lcall *(%%esi); cld\n\t"
33014+ __asm__("movw %w6, %%ds\n\t"
33015+ "lcall *%%ss:(%%esi); cld\n\t"
33016+ "push %%ss\n\t"
33017+ "pop %%ds\n\t"
33018 "jc 1f\n\t"
33019 "xor %%ah, %%ah\n"
33020 "1:"
33021@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33022 "c" (value),
33023 "b" (bx),
33024 "D" ((long)reg),
33025- "S" (&pci_indirect));
33026+ "S" (&pci_indirect),
33027+ "r" (__PCIBIOS_DS));
33028 break;
33029 }
33030
33031@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
33032
33033 DBG("PCI: Fetching IRQ routing table... ");
33034 __asm__("push %%es\n\t"
33035+ "movw %w8, %%ds\n\t"
33036 "push %%ds\n\t"
33037 "pop %%es\n\t"
33038- "lcall *(%%esi); cld\n\t"
33039+ "lcall *%%ss:(%%esi); cld\n\t"
33040 "pop %%es\n\t"
33041+ "push %%ss\n\t"
33042+ "pop %%ds\n"
33043 "jc 1f\n\t"
33044 "xor %%ah, %%ah\n"
33045 "1:"
33046@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
33047 "1" (0),
33048 "D" ((long) &opt),
33049 "S" (&pci_indirect),
33050- "m" (opt)
33051+ "m" (opt),
33052+ "r" (__PCIBIOS_DS)
33053 : "memory");
33054 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
33055 if (ret & 0xff00)
33056@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
33057 {
33058 int ret;
33059
33060- __asm__("lcall *(%%esi); cld\n\t"
33061+ __asm__("movw %w5, %%ds\n\t"
33062+ "lcall *%%ss:(%%esi); cld\n\t"
33063+ "push %%ss\n\t"
33064+ "pop %%ds\n"
33065 "jc 1f\n\t"
33066 "xor %%ah, %%ah\n"
33067 "1:"
33068@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
33069 : "0" (PCIBIOS_SET_PCI_HW_INT),
33070 "b" ((dev->bus->number << 8) | dev->devfn),
33071 "c" ((irq << 8) | (pin + 10)),
33072- "S" (&pci_indirect));
33073+ "S" (&pci_indirect),
33074+ "r" (__PCIBIOS_DS));
33075 return !(ret & 0xff00);
33076 }
33077 EXPORT_SYMBOL(pcibios_set_irq_routing);
33078diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
33079index 40e4469..d915bf9 100644
33080--- a/arch/x86/platform/efi/efi_32.c
33081+++ b/arch/x86/platform/efi/efi_32.c
33082@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
33083 {
33084 struct desc_ptr gdt_descr;
33085
33086+#ifdef CONFIG_PAX_KERNEXEC
33087+ struct desc_struct d;
33088+#endif
33089+
33090 local_irq_save(efi_rt_eflags);
33091
33092 load_cr3(initial_page_table);
33093 __flush_tlb_all();
33094
33095+#ifdef CONFIG_PAX_KERNEXEC
33096+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
33097+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
33098+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
33099+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
33100+#endif
33101+
33102 gdt_descr.address = __pa(get_cpu_gdt_table(0));
33103 gdt_descr.size = GDT_SIZE - 1;
33104 load_gdt(&gdt_descr);
33105@@ -58,11 +69,24 @@ void efi_call_phys_epilog(void)
33106 {
33107 struct desc_ptr gdt_descr;
33108
33109+#ifdef CONFIG_PAX_KERNEXEC
33110+ struct desc_struct d;
33111+
33112+ memset(&d, 0, sizeof d);
33113+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
33114+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
33115+#endif
33116+
33117 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
33118 gdt_descr.size = GDT_SIZE - 1;
33119 load_gdt(&gdt_descr);
33120
33121+#ifdef CONFIG_PAX_PER_CPU_PGD
33122+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
33123+#else
33124 load_cr3(swapper_pg_dir);
33125+#endif
33126+
33127 __flush_tlb_all();
33128
33129 local_irq_restore(efi_rt_eflags);
33130diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
33131index 39a0e7f1..872396e 100644
33132--- a/arch/x86/platform/efi/efi_64.c
33133+++ b/arch/x86/platform/efi/efi_64.c
33134@@ -76,6 +76,11 @@ void __init efi_call_phys_prelog(void)
33135 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
33136 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
33137 }
33138+
33139+#ifdef CONFIG_PAX_PER_CPU_PGD
33140+ load_cr3(swapper_pg_dir);
33141+#endif
33142+
33143 __flush_tlb_all();
33144 }
33145
33146@@ -89,6 +94,11 @@ void __init efi_call_phys_epilog(void)
33147 for (pgd = 0; pgd < n_pgds; pgd++)
33148 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
33149 kfree(save_pgd);
33150+
33151+#ifdef CONFIG_PAX_PER_CPU_PGD
33152+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
33153+#endif
33154+
33155 __flush_tlb_all();
33156 local_irq_restore(efi_flags);
33157 early_code_mapping_set_exec(0);
33158diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
33159index fbe66e6..eae5e38 100644
33160--- a/arch/x86/platform/efi/efi_stub_32.S
33161+++ b/arch/x86/platform/efi/efi_stub_32.S
33162@@ -6,7 +6,9 @@
33163 */
33164
33165 #include <linux/linkage.h>
33166+#include <linux/init.h>
33167 #include <asm/page_types.h>
33168+#include <asm/segment.h>
33169
33170 /*
33171 * efi_call_phys(void *, ...) is a function with variable parameters.
33172@@ -20,7 +22,7 @@
33173 * service functions will comply with gcc calling convention, too.
33174 */
33175
33176-.text
33177+__INIT
33178 ENTRY(efi_call_phys)
33179 /*
33180 * 0. The function can only be called in Linux kernel. So CS has been
33181@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
33182 * The mapping of lower virtual memory has been created in prelog and
33183 * epilog.
33184 */
33185- movl $1f, %edx
33186- subl $__PAGE_OFFSET, %edx
33187- jmp *%edx
33188+#ifdef CONFIG_PAX_KERNEXEC
33189+ movl $(__KERNEXEC_EFI_DS), %edx
33190+ mov %edx, %ds
33191+ mov %edx, %es
33192+ mov %edx, %ss
33193+ addl $2f,(1f)
33194+ ljmp *(1f)
33195+
33196+__INITDATA
33197+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
33198+.previous
33199+
33200+2:
33201+ subl $2b,(1b)
33202+#else
33203+ jmp 1f-__PAGE_OFFSET
33204 1:
33205+#endif
33206
33207 /*
33208 * 2. Now on the top of stack is the return
33209@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
33210 * parameter 2, ..., param n. To make things easy, we save the return
33211 * address of efi_call_phys in a global variable.
33212 */
33213- popl %edx
33214- movl %edx, saved_return_addr
33215- /* get the function pointer into ECX*/
33216- popl %ecx
33217- movl %ecx, efi_rt_function_ptr
33218- movl $2f, %edx
33219- subl $__PAGE_OFFSET, %edx
33220- pushl %edx
33221+ popl (saved_return_addr)
33222+ popl (efi_rt_function_ptr)
33223
33224 /*
33225 * 3. Clear PG bit in %CR0.
33226@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
33227 /*
33228 * 5. Call the physical function.
33229 */
33230- jmp *%ecx
33231+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
33232
33233-2:
33234 /*
33235 * 6. After EFI runtime service returns, control will return to
33236 * following instruction. We'd better readjust stack pointer first.
33237@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
33238 movl %cr0, %edx
33239 orl $0x80000000, %edx
33240 movl %edx, %cr0
33241- jmp 1f
33242-1:
33243+
33244 /*
33245 * 8. Now restore the virtual mode from flat mode by
33246 * adding EIP with PAGE_OFFSET.
33247 */
33248- movl $1f, %edx
33249- jmp *%edx
33250+#ifdef CONFIG_PAX_KERNEXEC
33251+ movl $(__KERNEL_DS), %edx
33252+ mov %edx, %ds
33253+ mov %edx, %es
33254+ mov %edx, %ss
33255+ ljmp $(__KERNEL_CS),$1f
33256+#else
33257+ jmp 1f+__PAGE_OFFSET
33258+#endif
33259 1:
33260
33261 /*
33262 * 9. Balance the stack. And because EAX contain the return value,
33263 * we'd better not clobber it.
33264 */
33265- leal efi_rt_function_ptr, %edx
33266- movl (%edx), %ecx
33267- pushl %ecx
33268+ pushl (efi_rt_function_ptr)
33269
33270 /*
33271- * 10. Push the saved return address onto the stack and return.
33272+ * 10. Return to the saved return address.
33273 */
33274- leal saved_return_addr, %edx
33275- movl (%edx), %ecx
33276- pushl %ecx
33277- ret
33278+ jmpl *(saved_return_addr)
33279 ENDPROC(efi_call_phys)
33280 .previous
33281
33282-.data
33283+__INITDATA
33284 saved_return_addr:
33285 .long 0
33286 efi_rt_function_ptr:
33287diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
33288index 4c07cca..2c8427d 100644
33289--- a/arch/x86/platform/efi/efi_stub_64.S
33290+++ b/arch/x86/platform/efi/efi_stub_64.S
33291@@ -7,6 +7,7 @@
33292 */
33293
33294 #include <linux/linkage.h>
33295+#include <asm/alternative-asm.h>
33296
33297 #define SAVE_XMM \
33298 mov %rsp, %rax; \
33299@@ -40,6 +41,7 @@ ENTRY(efi_call0)
33300 call *%rdi
33301 addq $32, %rsp
33302 RESTORE_XMM
33303+ pax_force_retaddr 0, 1
33304 ret
33305 ENDPROC(efi_call0)
33306
33307@@ -50,6 +52,7 @@ ENTRY(efi_call1)
33308 call *%rdi
33309 addq $32, %rsp
33310 RESTORE_XMM
33311+ pax_force_retaddr 0, 1
33312 ret
33313 ENDPROC(efi_call1)
33314
33315@@ -60,6 +63,7 @@ ENTRY(efi_call2)
33316 call *%rdi
33317 addq $32, %rsp
33318 RESTORE_XMM
33319+ pax_force_retaddr 0, 1
33320 ret
33321 ENDPROC(efi_call2)
33322
33323@@ -71,6 +75,7 @@ ENTRY(efi_call3)
33324 call *%rdi
33325 addq $32, %rsp
33326 RESTORE_XMM
33327+ pax_force_retaddr 0, 1
33328 ret
33329 ENDPROC(efi_call3)
33330
33331@@ -83,6 +88,7 @@ ENTRY(efi_call4)
33332 call *%rdi
33333 addq $32, %rsp
33334 RESTORE_XMM
33335+ pax_force_retaddr 0, 1
33336 ret
33337 ENDPROC(efi_call4)
33338
33339@@ -96,6 +102,7 @@ ENTRY(efi_call5)
33340 call *%rdi
33341 addq $48, %rsp
33342 RESTORE_XMM
33343+ pax_force_retaddr 0, 1
33344 ret
33345 ENDPROC(efi_call5)
33346
33347@@ -112,5 +119,6 @@ ENTRY(efi_call6)
33348 call *%rdi
33349 addq $48, %rsp
33350 RESTORE_XMM
33351+ pax_force_retaddr 0, 1
33352 ret
33353 ENDPROC(efi_call6)
33354diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
33355index 47fe66f..6206449 100644
33356--- a/arch/x86/platform/mrst/mrst.c
33357+++ b/arch/x86/platform/mrst/mrst.c
33358@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
33359 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
33360 int sfi_mrtc_num;
33361
33362-static void mrst_power_off(void)
33363+static __noreturn void mrst_power_off(void)
33364 {
33365+ BUG();
33366 }
33367
33368-static void mrst_reboot(void)
33369+static __noreturn void mrst_reboot(void)
33370 {
33371 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
33372+ BUG();
33373 }
33374
33375 /* parse all the mtimer info to a static mtimer array */
33376diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
33377index d6ee929..3637cb5 100644
33378--- a/arch/x86/platform/olpc/olpc_dt.c
33379+++ b/arch/x86/platform/olpc/olpc_dt.c
33380@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
33381 return res;
33382 }
33383
33384-static struct of_pdt_ops prom_olpc_ops __initdata = {
33385+static struct of_pdt_ops prom_olpc_ops __initconst = {
33386 .nextprop = olpc_dt_nextprop,
33387 .getproplen = olpc_dt_getproplen,
33388 .getproperty = olpc_dt_getproperty,
33389diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
33390index 1cf5b30..fd45732 100644
33391--- a/arch/x86/power/cpu.c
33392+++ b/arch/x86/power/cpu.c
33393@@ -137,11 +137,8 @@ static void do_fpu_end(void)
33394 static void fix_processor_context(void)
33395 {
33396 int cpu = smp_processor_id();
33397- struct tss_struct *t = &per_cpu(init_tss, cpu);
33398-#ifdef CONFIG_X86_64
33399- struct desc_struct *desc = get_cpu_gdt_table(cpu);
33400- tss_desc tss;
33401-#endif
33402+ struct tss_struct *t = init_tss + cpu;
33403+
33404 set_tss_desc(cpu, t); /*
33405 * This just modifies memory; should not be
33406 * necessary. But... This is necessary, because
33407@@ -150,10 +147,6 @@ static void fix_processor_context(void)
33408 */
33409
33410 #ifdef CONFIG_X86_64
33411- memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
33412- tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
33413- write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
33414-
33415 syscall_init(); /* This sets MSR_*STAR and related */
33416 #endif
33417 load_TR_desc(); /* This does ltr */
33418diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
33419index a44f457..9140171 100644
33420--- a/arch/x86/realmode/init.c
33421+++ b/arch/x86/realmode/init.c
33422@@ -70,7 +70,13 @@ void __init setup_real_mode(void)
33423 __va(real_mode_header->trampoline_header);
33424
33425 #ifdef CONFIG_X86_32
33426- trampoline_header->start = __pa_symbol(startup_32_smp);
33427+ trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
33428+
33429+#ifdef CONFIG_PAX_KERNEXEC
33430+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
33431+#endif
33432+
33433+ trampoline_header->boot_cs = __BOOT_CS;
33434 trampoline_header->gdt_limit = __BOOT_DS + 7;
33435 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
33436 #else
33437@@ -86,7 +92,7 @@ void __init setup_real_mode(void)
33438 *trampoline_cr4_features = read_cr4();
33439
33440 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
33441- trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
33442+ trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
33443 trampoline_pgd[511] = init_level4_pgt[511].pgd;
33444 #endif
33445 }
33446diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
33447index 8869287..d577672 100644
33448--- a/arch/x86/realmode/rm/Makefile
33449+++ b/arch/x86/realmode/rm/Makefile
33450@@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
33451 $(call cc-option, -fno-unit-at-a-time)) \
33452 $(call cc-option, -fno-stack-protector) \
33453 $(call cc-option, -mpreferred-stack-boundary=2)
33454+ifdef CONSTIFY_PLUGIN
33455+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
33456+endif
33457 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
33458 GCOV_PROFILE := n
33459diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
33460index a28221d..93c40f1 100644
33461--- a/arch/x86/realmode/rm/header.S
33462+++ b/arch/x86/realmode/rm/header.S
33463@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
33464 #endif
33465 /* APM/BIOS reboot */
33466 .long pa_machine_real_restart_asm
33467-#ifdef CONFIG_X86_64
33468+#ifdef CONFIG_X86_32
33469+ .long __KERNEL_CS
33470+#else
33471 .long __KERNEL32_CS
33472 #endif
33473 END(real_mode_header)
33474diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
33475index c1b2791..f9e31c7 100644
33476--- a/arch/x86/realmode/rm/trampoline_32.S
33477+++ b/arch/x86/realmode/rm/trampoline_32.S
33478@@ -25,6 +25,12 @@
33479 #include <asm/page_types.h>
33480 #include "realmode.h"
33481
33482+#ifdef CONFIG_PAX_KERNEXEC
33483+#define ta(X) (X)
33484+#else
33485+#define ta(X) (pa_ ## X)
33486+#endif
33487+
33488 .text
33489 .code16
33490
33491@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
33492
33493 cli # We should be safe anyway
33494
33495- movl tr_start, %eax # where we need to go
33496-
33497 movl $0xA5A5A5A5, trampoline_status
33498 # write marker for master knows we're running
33499
33500@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
33501 movw $1, %dx # protected mode (PE) bit
33502 lmsw %dx # into protected mode
33503
33504- ljmpl $__BOOT_CS, $pa_startup_32
33505+ ljmpl *(trampoline_header)
33506
33507 .section ".text32","ax"
33508 .code32
33509@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
33510 .balign 8
33511 GLOBAL(trampoline_header)
33512 tr_start: .space 4
33513- tr_gdt_pad: .space 2
33514+ tr_boot_cs: .space 2
33515 tr_gdt: .space 6
33516 END(trampoline_header)
33517
33518diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
33519index bb360dc..d0fd8f8 100644
33520--- a/arch/x86/realmode/rm/trampoline_64.S
33521+++ b/arch/x86/realmode/rm/trampoline_64.S
33522@@ -94,6 +94,7 @@ ENTRY(startup_32)
33523 movl %edx, %gs
33524
33525 movl pa_tr_cr4, %eax
33526+ andl $~X86_CR4_PCIDE, %eax
33527 movl %eax, %cr4 # Enable PAE mode
33528
33529 # Setup trampoline 4 level pagetables
33530@@ -107,7 +108,7 @@ ENTRY(startup_32)
33531 wrmsr
33532
33533 # Enable paging and in turn activate Long Mode
33534- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
33535+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
33536 movl %eax, %cr0
33537
33538 /*
33539diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
33540index e812034..c747134 100644
33541--- a/arch/x86/tools/Makefile
33542+++ b/arch/x86/tools/Makefile
33543@@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
33544
33545 $(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
33546
33547-HOST_EXTRACFLAGS += -I$(srctree)/tools/include
33548+HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
33549 hostprogs-y += relocs
33550 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
33551 relocs: $(obj)/relocs
33552diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
33553index f7bab68..b6d9886 100644
33554--- a/arch/x86/tools/relocs.c
33555+++ b/arch/x86/tools/relocs.c
33556@@ -1,5 +1,7 @@
33557 /* This is included from relocs_32/64.c */
33558
33559+#include "../../../include/generated/autoconf.h"
33560+
33561 #define ElfW(type) _ElfW(ELF_BITS, type)
33562 #define _ElfW(bits, type) __ElfW(bits, type)
33563 #define __ElfW(bits, type) Elf##bits##_##type
33564@@ -11,6 +13,7 @@
33565 #define Elf_Sym ElfW(Sym)
33566
33567 static Elf_Ehdr ehdr;
33568+static Elf_Phdr *phdr;
33569
33570 struct relocs {
33571 uint32_t *offset;
33572@@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
33573 }
33574 }
33575
33576+static void read_phdrs(FILE *fp)
33577+{
33578+ unsigned int i;
33579+
33580+ phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
33581+ if (!phdr) {
33582+ die("Unable to allocate %d program headers\n",
33583+ ehdr.e_phnum);
33584+ }
33585+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
33586+ die("Seek to %d failed: %s\n",
33587+ ehdr.e_phoff, strerror(errno));
33588+ }
33589+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
33590+ die("Cannot read ELF program headers: %s\n",
33591+ strerror(errno));
33592+ }
33593+ for(i = 0; i < ehdr.e_phnum; i++) {
33594+ phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
33595+ phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
33596+ phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
33597+ phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
33598+ phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
33599+ phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
33600+ phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
33601+ phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
33602+ }
33603+
33604+}
33605+
33606 static void read_shdrs(FILE *fp)
33607 {
33608- int i;
33609+ unsigned int i;
33610 Elf_Shdr shdr;
33611
33612 secs = calloc(ehdr.e_shnum, sizeof(struct section));
33613@@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
33614
33615 static void read_strtabs(FILE *fp)
33616 {
33617- int i;
33618+ unsigned int i;
33619 for (i = 0; i < ehdr.e_shnum; i++) {
33620 struct section *sec = &secs[i];
33621 if (sec->shdr.sh_type != SHT_STRTAB) {
33622@@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
33623
33624 static void read_symtabs(FILE *fp)
33625 {
33626- int i,j;
33627+ unsigned int i,j;
33628 for (i = 0; i < ehdr.e_shnum; i++) {
33629 struct section *sec = &secs[i];
33630 if (sec->shdr.sh_type != SHT_SYMTAB) {
33631@@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
33632 }
33633
33634
33635-static void read_relocs(FILE *fp)
33636+static void read_relocs(FILE *fp, int use_real_mode)
33637 {
33638- int i,j;
33639+ unsigned int i,j;
33640+ uint32_t base;
33641+
33642 for (i = 0; i < ehdr.e_shnum; i++) {
33643 struct section *sec = &secs[i];
33644 if (sec->shdr.sh_type != SHT_REL_TYPE) {
33645@@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
33646 die("Cannot read symbol table: %s\n",
33647 strerror(errno));
33648 }
33649+ base = 0;
33650+
33651+#ifdef CONFIG_X86_32
33652+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
33653+ if (phdr[j].p_type != PT_LOAD )
33654+ continue;
33655+ 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)
33656+ continue;
33657+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
33658+ break;
33659+ }
33660+#endif
33661+
33662 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
33663 Elf_Rel *rel = &sec->reltab[j];
33664- rel->r_offset = elf_addr_to_cpu(rel->r_offset);
33665+ rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
33666 rel->r_info = elf_xword_to_cpu(rel->r_info);
33667 #if (SHT_REL_TYPE == SHT_RELA)
33668 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
33669@@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
33670
33671 static void print_absolute_symbols(void)
33672 {
33673- int i;
33674+ unsigned int i;
33675 const char *format;
33676
33677 if (ELF_BITS == 64)
33678@@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
33679 for (i = 0; i < ehdr.e_shnum; i++) {
33680 struct section *sec = &secs[i];
33681 char *sym_strtab;
33682- int j;
33683+ unsigned int j;
33684
33685 if (sec->shdr.sh_type != SHT_SYMTAB) {
33686 continue;
33687@@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
33688
33689 static void print_absolute_relocs(void)
33690 {
33691- int i, printed = 0;
33692+ unsigned int i, printed = 0;
33693 const char *format;
33694
33695 if (ELF_BITS == 64)
33696@@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
33697 struct section *sec_applies, *sec_symtab;
33698 char *sym_strtab;
33699 Elf_Sym *sh_symtab;
33700- int j;
33701+ unsigned int j;
33702 if (sec->shdr.sh_type != SHT_REL_TYPE) {
33703 continue;
33704 }
33705@@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
33706 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
33707 Elf_Sym *sym, const char *symname))
33708 {
33709- int i;
33710+ unsigned int i;
33711 /* Walk through the relocations */
33712 for (i = 0; i < ehdr.e_shnum; i++) {
33713 char *sym_strtab;
33714 Elf_Sym *sh_symtab;
33715 struct section *sec_applies, *sec_symtab;
33716- int j;
33717+ unsigned int j;
33718 struct section *sec = &secs[i];
33719
33720 if (sec->shdr.sh_type != SHT_REL_TYPE) {
33721@@ -812,6 +860,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
33722 {
33723 unsigned r_type = ELF32_R_TYPE(rel->r_info);
33724 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
33725+ char *sym_strtab = sec->link->link->strtab;
33726+
33727+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
33728+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
33729+ return 0;
33730+
33731+#ifdef CONFIG_PAX_KERNEXEC
33732+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
33733+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
33734+ return 0;
33735+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
33736+ return 0;
33737+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
33738+ return 0;
33739+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
33740+ return 0;
33741+#endif
33742
33743 switch (r_type) {
33744 case R_386_NONE:
33745@@ -950,7 +1015,7 @@ static int write32_as_text(uint32_t v, FILE *f)
33746
33747 static void emit_relocs(int as_text, int use_real_mode)
33748 {
33749- int i;
33750+ unsigned int i;
33751 int (*write_reloc)(uint32_t, FILE *) = write32;
33752 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
33753 const char *symname);
33754@@ -1026,10 +1091,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
33755 {
33756 regex_init(use_real_mode);
33757 read_ehdr(fp);
33758+ read_phdrs(fp);
33759 read_shdrs(fp);
33760 read_strtabs(fp);
33761 read_symtabs(fp);
33762- read_relocs(fp);
33763+ read_relocs(fp, use_real_mode);
33764 if (ELF_BITS == 64)
33765 percpu_init();
33766 if (show_absolute_syms) {
33767diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
33768index 80ffa5b..a33bd15 100644
33769--- a/arch/x86/um/tls_32.c
33770+++ b/arch/x86/um/tls_32.c
33771@@ -260,7 +260,7 @@ out:
33772 if (unlikely(task == current &&
33773 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
33774 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
33775- "without flushed TLS.", current->pid);
33776+ "without flushed TLS.", task_pid_nr(current));
33777 }
33778
33779 return 0;
33780diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
33781index fd14be1..e3c79c0 100644
33782--- a/arch/x86/vdso/Makefile
33783+++ b/arch/x86/vdso/Makefile
33784@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
33785 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
33786 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
33787
33788-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
33789+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
33790 GCOV_PROFILE := n
33791
33792 #
33793diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
33794index d6bfb87..876ee18 100644
33795--- a/arch/x86/vdso/vdso32-setup.c
33796+++ b/arch/x86/vdso/vdso32-setup.c
33797@@ -25,6 +25,7 @@
33798 #include <asm/tlbflush.h>
33799 #include <asm/vdso.h>
33800 #include <asm/proto.h>
33801+#include <asm/mman.h>
33802
33803 enum {
33804 VDSO_DISABLED = 0,
33805@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
33806 void enable_sep_cpu(void)
33807 {
33808 int cpu = get_cpu();
33809- struct tss_struct *tss = &per_cpu(init_tss, cpu);
33810+ struct tss_struct *tss = init_tss + cpu;
33811
33812 if (!boot_cpu_has(X86_FEATURE_SEP)) {
33813 put_cpu();
33814@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
33815 gate_vma.vm_start = FIXADDR_USER_START;
33816 gate_vma.vm_end = FIXADDR_USER_END;
33817 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
33818- gate_vma.vm_page_prot = __P101;
33819+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
33820
33821 return 0;
33822 }
33823@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
33824 if (compat)
33825 addr = VDSO_HIGH_BASE;
33826 else {
33827- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
33828+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
33829 if (IS_ERR_VALUE(addr)) {
33830 ret = addr;
33831 goto up_fail;
33832 }
33833 }
33834
33835- current->mm->context.vdso = (void *)addr;
33836+ current->mm->context.vdso = addr;
33837
33838 if (compat_uses_vma || !compat) {
33839 /*
33840@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
33841 }
33842
33843 current_thread_info()->sysenter_return =
33844- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
33845+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
33846
33847 up_fail:
33848 if (ret)
33849- current->mm->context.vdso = NULL;
33850+ current->mm->context.vdso = 0;
33851
33852 up_write(&mm->mmap_sem);
33853
33854@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
33855
33856 const char *arch_vma_name(struct vm_area_struct *vma)
33857 {
33858- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
33859+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
33860 return "[vdso]";
33861+
33862+#ifdef CONFIG_PAX_SEGMEXEC
33863+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
33864+ return "[vdso]";
33865+#endif
33866+
33867 return NULL;
33868 }
33869
33870@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
33871 * Check to see if the corresponding task was created in compat vdso
33872 * mode.
33873 */
33874- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
33875+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
33876 return &gate_vma;
33877 return NULL;
33878 }
33879diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
33880index 431e875..cbb23f3 100644
33881--- a/arch/x86/vdso/vma.c
33882+++ b/arch/x86/vdso/vma.c
33883@@ -16,8 +16,6 @@
33884 #include <asm/vdso.h>
33885 #include <asm/page.h>
33886
33887-unsigned int __read_mostly vdso_enabled = 1;
33888-
33889 extern char vdso_start[], vdso_end[];
33890 extern unsigned short vdso_sync_cpuid;
33891
33892@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
33893 * unaligned here as a result of stack start randomization.
33894 */
33895 addr = PAGE_ALIGN(addr);
33896- addr = align_vdso_addr(addr);
33897
33898 return addr;
33899 }
33900@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
33901 unsigned size)
33902 {
33903 struct mm_struct *mm = current->mm;
33904- unsigned long addr;
33905+ unsigned long addr = 0;
33906 int ret;
33907
33908- if (!vdso_enabled)
33909- return 0;
33910-
33911 down_write(&mm->mmap_sem);
33912+
33913+#ifdef CONFIG_PAX_RANDMMAP
33914+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
33915+#endif
33916+
33917 addr = vdso_addr(mm->start_stack, size);
33918+ addr = align_vdso_addr(addr);
33919 addr = get_unmapped_area(NULL, addr, size, 0, 0);
33920 if (IS_ERR_VALUE(addr)) {
33921 ret = addr;
33922 goto up_fail;
33923 }
33924
33925- current->mm->context.vdso = (void *)addr;
33926+ mm->context.vdso = addr;
33927
33928 ret = install_special_mapping(mm, addr, size,
33929 VM_READ|VM_EXEC|
33930 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
33931 pages);
33932- if (ret) {
33933- current->mm->context.vdso = NULL;
33934- goto up_fail;
33935- }
33936+ if (ret)
33937+ mm->context.vdso = 0;
33938
33939 up_fail:
33940 up_write(&mm->mmap_sem);
33941@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
33942 vdsox32_size);
33943 }
33944 #endif
33945-
33946-static __init int vdso_setup(char *s)
33947-{
33948- vdso_enabled = simple_strtoul(s, NULL, 0);
33949- return 0;
33950-}
33951-__setup("vdso=", vdso_setup);
33952diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
33953index 193097e..7590269 100644
33954--- a/arch/x86/xen/enlighten.c
33955+++ b/arch/x86/xen/enlighten.c
33956@@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
33957
33958 struct shared_info xen_dummy_shared_info;
33959
33960-void *xen_initial_gdt;
33961-
33962 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
33963 __read_mostly int xen_have_vector_callback;
33964 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
33965@@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
33966 {
33967 unsigned long va = dtr->address;
33968 unsigned int size = dtr->size + 1;
33969- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
33970- unsigned long frames[pages];
33971+ unsigned long frames[65536 / PAGE_SIZE];
33972 int f;
33973
33974 /*
33975@@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
33976 {
33977 unsigned long va = dtr->address;
33978 unsigned int size = dtr->size + 1;
33979- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
33980- unsigned long frames[pages];
33981+ unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
33982 int f;
33983
33984 /*
33985@@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
33986 * 8-byte entries, or 16 4k pages..
33987 */
33988
33989- BUG_ON(size > 65536);
33990+ BUG_ON(size > GDT_SIZE);
33991 BUG_ON(va & ~PAGE_MASK);
33992
33993 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
33994@@ -985,7 +981,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
33995 return 0;
33996 }
33997
33998-static void set_xen_basic_apic_ops(void)
33999+static void __init set_xen_basic_apic_ops(void)
34000 {
34001 apic->read = xen_apic_read;
34002 apic->write = xen_apic_write;
34003@@ -1290,30 +1286,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
34004 #endif
34005 };
34006
34007-static void xen_reboot(int reason)
34008+static __noreturn void xen_reboot(int reason)
34009 {
34010 struct sched_shutdown r = { .reason = reason };
34011
34012- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
34013- BUG();
34014+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
34015+ BUG();
34016 }
34017
34018-static void xen_restart(char *msg)
34019+static __noreturn void xen_restart(char *msg)
34020 {
34021 xen_reboot(SHUTDOWN_reboot);
34022 }
34023
34024-static void xen_emergency_restart(void)
34025+static __noreturn void xen_emergency_restart(void)
34026 {
34027 xen_reboot(SHUTDOWN_reboot);
34028 }
34029
34030-static void xen_machine_halt(void)
34031+static __noreturn void xen_machine_halt(void)
34032 {
34033 xen_reboot(SHUTDOWN_poweroff);
34034 }
34035
34036-static void xen_machine_power_off(void)
34037+static __noreturn void xen_machine_power_off(void)
34038 {
34039 if (pm_power_off)
34040 pm_power_off();
34041@@ -1464,7 +1460,17 @@ asmlinkage void __init xen_start_kernel(void)
34042 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
34043
34044 /* Work out if we support NX */
34045- x86_configure_nx();
34046+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34047+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
34048+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
34049+ unsigned l, h;
34050+
34051+ __supported_pte_mask |= _PAGE_NX;
34052+ rdmsr(MSR_EFER, l, h);
34053+ l |= EFER_NX;
34054+ wrmsr(MSR_EFER, l, h);
34055+ }
34056+#endif
34057
34058 xen_setup_features();
34059
34060@@ -1495,13 +1501,6 @@ asmlinkage void __init xen_start_kernel(void)
34061
34062 machine_ops = xen_machine_ops;
34063
34064- /*
34065- * The only reliable way to retain the initial address of the
34066- * percpu gdt_page is to remember it here, so we can go and
34067- * mark it RW later, when the initial percpu area is freed.
34068- */
34069- xen_initial_gdt = &per_cpu(gdt_page, 0);
34070-
34071 xen_smp_init();
34072
34073 #ifdef CONFIG_ACPI_NUMA
34074diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
34075index fdc3ba2..3daee39 100644
34076--- a/arch/x86/xen/mmu.c
34077+++ b/arch/x86/xen/mmu.c
34078@@ -1894,6 +1894,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
34079 /* L3_k[510] -> level2_kernel_pgt
34080 * L3_i[511] -> level2_fixmap_pgt */
34081 convert_pfn_mfn(level3_kernel_pgt);
34082+ convert_pfn_mfn(level3_vmalloc_start_pgt);
34083+ convert_pfn_mfn(level3_vmalloc_end_pgt);
34084+ convert_pfn_mfn(level3_vmemmap_pgt);
34085
34086 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
34087 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
34088@@ -1923,8 +1926,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
34089 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
34090 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
34091 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
34092+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
34093+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
34094+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
34095 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
34096 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
34097+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
34098 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
34099 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
34100
34101@@ -2108,6 +2115,7 @@ static void __init xen_post_allocator_init(void)
34102 pv_mmu_ops.set_pud = xen_set_pud;
34103 #if PAGETABLE_LEVELS == 4
34104 pv_mmu_ops.set_pgd = xen_set_pgd;
34105+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
34106 #endif
34107
34108 /* This will work as long as patching hasn't happened yet
34109@@ -2186,6 +2194,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
34110 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
34111 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
34112 .set_pgd = xen_set_pgd_hyper,
34113+ .set_pgd_batched = xen_set_pgd_hyper,
34114
34115 .alloc_pud = xen_alloc_pmd_init,
34116 .release_pud = xen_release_pmd_init,
34117diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
34118index b81c88e..2cbe7b8 100644
34119--- a/arch/x86/xen/smp.c
34120+++ b/arch/x86/xen/smp.c
34121@@ -272,11 +272,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
34122 {
34123 BUG_ON(smp_processor_id() != 0);
34124 native_smp_prepare_boot_cpu();
34125-
34126- /* We've switched to the "real" per-cpu gdt, so make sure the
34127- old memory can be recycled */
34128- make_lowmem_page_readwrite(xen_initial_gdt);
34129-
34130 xen_filter_cpu_maps();
34131 xen_setup_vcpu_info_placement();
34132 }
34133@@ -346,7 +341,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
34134 ctxt->user_regs.ss = __KERNEL_DS;
34135 #ifdef CONFIG_X86_32
34136 ctxt->user_regs.fs = __KERNEL_PERCPU;
34137- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
34138+ savesegment(gs, ctxt->user_regs.gs);
34139 #else
34140 ctxt->gs_base_kernel = per_cpu_offset(cpu);
34141 #endif
34142@@ -356,8 +351,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
34143
34144 {
34145 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
34146- ctxt->user_regs.ds = __USER_DS;
34147- ctxt->user_regs.es = __USER_DS;
34148+ ctxt->user_regs.ds = __KERNEL_DS;
34149+ ctxt->user_regs.es = __KERNEL_DS;
34150
34151 xen_copy_trap_info(ctxt->trap_ctxt);
34152
34153@@ -402,13 +397,12 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
34154 int rc;
34155
34156 per_cpu(current_task, cpu) = idle;
34157+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
34158 #ifdef CONFIG_X86_32
34159 irq_ctx_init(cpu);
34160 #else
34161 clear_tsk_thread_flag(idle, TIF_FORK);
34162- per_cpu(kernel_stack, cpu) =
34163- (unsigned long)task_stack_page(idle) -
34164- KERNEL_STACK_OFFSET + THREAD_SIZE;
34165+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
34166 #endif
34167 xen_setup_runstate_info(cpu);
34168 xen_setup_timer(cpu);
34169@@ -678,7 +672,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
34170
34171 void __init xen_smp_init(void)
34172 {
34173- smp_ops = xen_smp_ops;
34174+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
34175 xen_fill_possible_map();
34176 xen_init_spinlocks();
34177 }
34178diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
34179index 33ca6e4..0ded929 100644
34180--- a/arch/x86/xen/xen-asm_32.S
34181+++ b/arch/x86/xen/xen-asm_32.S
34182@@ -84,14 +84,14 @@ ENTRY(xen_iret)
34183 ESP_OFFSET=4 # bytes pushed onto stack
34184
34185 /*
34186- * Store vcpu_info pointer for easy access. Do it this way to
34187- * avoid having to reload %fs
34188+ * Store vcpu_info pointer for easy access.
34189 */
34190 #ifdef CONFIG_SMP
34191- GET_THREAD_INFO(%eax)
34192- movl %ss:TI_cpu(%eax), %eax
34193- movl %ss:__per_cpu_offset(,%eax,4), %eax
34194- mov %ss:xen_vcpu(%eax), %eax
34195+ push %fs
34196+ mov $(__KERNEL_PERCPU), %eax
34197+ mov %eax, %fs
34198+ mov PER_CPU_VAR(xen_vcpu), %eax
34199+ pop %fs
34200 #else
34201 movl %ss:xen_vcpu, %eax
34202 #endif
34203diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
34204index 7faed58..ba4427c 100644
34205--- a/arch/x86/xen/xen-head.S
34206+++ b/arch/x86/xen/xen-head.S
34207@@ -19,6 +19,17 @@ ENTRY(startup_xen)
34208 #ifdef CONFIG_X86_32
34209 mov %esi,xen_start_info
34210 mov $init_thread_union+THREAD_SIZE,%esp
34211+#ifdef CONFIG_SMP
34212+ movl $cpu_gdt_table,%edi
34213+ movl $__per_cpu_load,%eax
34214+ movw %ax,__KERNEL_PERCPU + 2(%edi)
34215+ rorl $16,%eax
34216+ movb %al,__KERNEL_PERCPU + 4(%edi)
34217+ movb %ah,__KERNEL_PERCPU + 7(%edi)
34218+ movl $__per_cpu_end - 1,%eax
34219+ subl $__per_cpu_start,%eax
34220+ movw %ax,__KERNEL_PERCPU + 0(%edi)
34221+#endif
34222 #else
34223 mov %rsi,xen_start_info
34224 mov $init_thread_union+THREAD_SIZE,%rsp
34225diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
34226index 86782c5..fa272c8 100644
34227--- a/arch/x86/xen/xen-ops.h
34228+++ b/arch/x86/xen/xen-ops.h
34229@@ -10,8 +10,6 @@
34230 extern const char xen_hypervisor_callback[];
34231 extern const char xen_failsafe_callback[];
34232
34233-extern void *xen_initial_gdt;
34234-
34235 struct trap_info;
34236 void xen_copy_trap_info(struct trap_info *traps);
34237
34238diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
34239index 525bd3d..ef888b1 100644
34240--- a/arch/xtensa/variants/dc232b/include/variant/core.h
34241+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
34242@@ -119,9 +119,9 @@
34243 ----------------------------------------------------------------------*/
34244
34245 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
34246-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
34247 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
34248 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
34249+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
34250
34251 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
34252 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
34253diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
34254index 2f33760..835e50a 100644
34255--- a/arch/xtensa/variants/fsf/include/variant/core.h
34256+++ b/arch/xtensa/variants/fsf/include/variant/core.h
34257@@ -11,6 +11,7 @@
34258 #ifndef _XTENSA_CORE_H
34259 #define _XTENSA_CORE_H
34260
34261+#include <linux/const.h>
34262
34263 /****************************************************************************
34264 Parameters Useful for Any Code, USER or PRIVILEGED
34265@@ -112,9 +113,9 @@
34266 ----------------------------------------------------------------------*/
34267
34268 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
34269-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
34270 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
34271 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
34272+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
34273
34274 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
34275 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
34276diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
34277index af00795..2bb8105 100644
34278--- a/arch/xtensa/variants/s6000/include/variant/core.h
34279+++ b/arch/xtensa/variants/s6000/include/variant/core.h
34280@@ -11,6 +11,7 @@
34281 #ifndef _XTENSA_CORE_CONFIGURATION_H
34282 #define _XTENSA_CORE_CONFIGURATION_H
34283
34284+#include <linux/const.h>
34285
34286 /****************************************************************************
34287 Parameters Useful for Any Code, USER or PRIVILEGED
34288@@ -118,9 +119,9 @@
34289 ----------------------------------------------------------------------*/
34290
34291 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
34292-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
34293 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
34294 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
34295+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
34296
34297 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
34298 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
34299diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
34300index 290792a..416f287 100644
34301--- a/block/blk-cgroup.c
34302+++ b/block/blk-cgroup.c
34303@@ -808,7 +808,7 @@ static void blkcg_css_free(struct cgroup *cgroup)
34304
34305 static struct cgroup_subsys_state *blkcg_css_alloc(struct cgroup *cgroup)
34306 {
34307- static atomic64_t id_seq = ATOMIC64_INIT(0);
34308+ static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
34309 struct blkcg *blkcg;
34310 struct cgroup *parent = cgroup->parent;
34311
34312@@ -823,7 +823,7 @@ static struct cgroup_subsys_state *blkcg_css_alloc(struct cgroup *cgroup)
34313
34314 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
34315 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
34316- blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
34317+ blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
34318 done:
34319 spin_lock_init(&blkcg->lock);
34320 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
34321diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
34322index 4b8d9b54..ff76220 100644
34323--- a/block/blk-iopoll.c
34324+++ b/block/blk-iopoll.c
34325@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
34326 }
34327 EXPORT_SYMBOL(blk_iopoll_complete);
34328
34329-static void blk_iopoll_softirq(struct softirq_action *h)
34330+static void blk_iopoll_softirq(void)
34331 {
34332 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
34333 int rearm = 0, budget = blk_iopoll_budget;
34334diff --git a/block/blk-map.c b/block/blk-map.c
34335index 623e1cd..ca1e109 100644
34336--- a/block/blk-map.c
34337+++ b/block/blk-map.c
34338@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
34339 if (!len || !kbuf)
34340 return -EINVAL;
34341
34342- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
34343+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
34344 if (do_copy)
34345 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
34346 else
34347diff --git a/block/blk-softirq.c b/block/blk-softirq.c
34348index ec9e606..2244d4e 100644
34349--- a/block/blk-softirq.c
34350+++ b/block/blk-softirq.c
34351@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
34352 * Softirq action handler - move entries to local list and loop over them
34353 * while passing them to the queue registered handler.
34354 */
34355-static void blk_done_softirq(struct softirq_action *h)
34356+static void blk_done_softirq(void)
34357 {
34358 struct list_head *cpu_list, local_list;
34359
34360diff --git a/block/bsg.c b/block/bsg.c
34361index 420a5a9..23834aa 100644
34362--- a/block/bsg.c
34363+++ b/block/bsg.c
34364@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
34365 struct sg_io_v4 *hdr, struct bsg_device *bd,
34366 fmode_t has_write_perm)
34367 {
34368+ unsigned char tmpcmd[sizeof(rq->__cmd)];
34369+ unsigned char *cmdptr;
34370+
34371 if (hdr->request_len > BLK_MAX_CDB) {
34372 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
34373 if (!rq->cmd)
34374 return -ENOMEM;
34375- }
34376+ cmdptr = rq->cmd;
34377+ } else
34378+ cmdptr = tmpcmd;
34379
34380- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
34381+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
34382 hdr->request_len))
34383 return -EFAULT;
34384
34385+ if (cmdptr != rq->cmd)
34386+ memcpy(rq->cmd, cmdptr, hdr->request_len);
34387+
34388 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
34389 if (blk_verify_command(rq->cmd, has_write_perm))
34390 return -EPERM;
34391diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
34392index 7e5d474..0cf0017 100644
34393--- a/block/compat_ioctl.c
34394+++ b/block/compat_ioctl.c
34395@@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
34396 err |= __get_user(f->spec1, &uf->spec1);
34397 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
34398 err |= __get_user(name, &uf->name);
34399- f->name = compat_ptr(name);
34400+ f->name = (void __force_kernel *)compat_ptr(name);
34401 if (err) {
34402 err = -EFAULT;
34403 goto out;
34404diff --git a/block/genhd.c b/block/genhd.c
34405index dadf42b..48dc887 100644
34406--- a/block/genhd.c
34407+++ b/block/genhd.c
34408@@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
34409
34410 /*
34411 * Register device numbers dev..(dev+range-1)
34412- * range must be nonzero
34413+ * Noop if @range is zero.
34414 * The hash chain is sorted on range, so that subranges can override.
34415 */
34416 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
34417 struct kobject *(*probe)(dev_t, int *, void *),
34418 int (*lock)(dev_t, void *), void *data)
34419 {
34420- kobj_map(bdev_map, devt, range, module, probe, lock, data);
34421+ if (range)
34422+ kobj_map(bdev_map, devt, range, module, probe, lock, data);
34423 }
34424
34425 EXPORT_SYMBOL(blk_register_region);
34426
34427+/* undo blk_register_region(), noop if @range is zero */
34428 void blk_unregister_region(dev_t devt, unsigned long range)
34429 {
34430- kobj_unmap(bdev_map, devt, range);
34431+ if (range)
34432+ kobj_unmap(bdev_map, devt, range);
34433 }
34434
34435 EXPORT_SYMBOL(blk_unregister_region);
34436diff --git a/block/partitions/efi.c b/block/partitions/efi.c
34437index c85fc89..51e690b 100644
34438--- a/block/partitions/efi.c
34439+++ b/block/partitions/efi.c
34440@@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
34441 if (!gpt)
34442 return NULL;
34443
34444+ if (!le32_to_cpu(gpt->num_partition_entries))
34445+ return NULL;
34446+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
34447+ if (!pte)
34448+ return NULL;
34449+
34450 count = le32_to_cpu(gpt->num_partition_entries) *
34451 le32_to_cpu(gpt->sizeof_partition_entry);
34452- if (!count)
34453- return NULL;
34454- pte = kmalloc(count, GFP_KERNEL);
34455- if (!pte)
34456- return NULL;
34457-
34458 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
34459 (u8 *) pte,
34460 count) < count) {
34461diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
34462index a5ffcc9..3cedc9c 100644
34463--- a/block/scsi_ioctl.c
34464+++ b/block/scsi_ioctl.c
34465@@ -224,8 +224,20 @@ EXPORT_SYMBOL(blk_verify_command);
34466 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
34467 struct sg_io_hdr *hdr, fmode_t mode)
34468 {
34469- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
34470+ unsigned char tmpcmd[sizeof(rq->__cmd)];
34471+ unsigned char *cmdptr;
34472+
34473+ if (rq->cmd != rq->__cmd)
34474+ cmdptr = rq->cmd;
34475+ else
34476+ cmdptr = tmpcmd;
34477+
34478+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
34479 return -EFAULT;
34480+
34481+ if (cmdptr != rq->cmd)
34482+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
34483+
34484 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
34485 return -EPERM;
34486
34487@@ -434,6 +446,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
34488 int err;
34489 unsigned int in_len, out_len, bytes, opcode, cmdlen;
34490 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
34491+ unsigned char tmpcmd[sizeof(rq->__cmd)];
34492+ unsigned char *cmdptr;
34493
34494 if (!sic)
34495 return -EINVAL;
34496@@ -467,9 +481,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
34497 */
34498 err = -EFAULT;
34499 rq->cmd_len = cmdlen;
34500- if (copy_from_user(rq->cmd, sic->data, cmdlen))
34501+
34502+ if (rq->cmd != rq->__cmd)
34503+ cmdptr = rq->cmd;
34504+ else
34505+ cmdptr = tmpcmd;
34506+
34507+ if (copy_from_user(cmdptr, sic->data, cmdlen))
34508 goto error;
34509
34510+ if (rq->cmd != cmdptr)
34511+ memcpy(rq->cmd, cmdptr, cmdlen);
34512+
34513 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
34514 goto error;
34515
34516diff --git a/crypto/api.c b/crypto/api.c
34517index 3b61803..37c4c72 100644
34518--- a/crypto/api.c
34519+++ b/crypto/api.c
34520@@ -34,6 +34,8 @@ EXPORT_SYMBOL_GPL(crypto_alg_sem);
34521 BLOCKING_NOTIFIER_HEAD(crypto_chain);
34522 EXPORT_SYMBOL_GPL(crypto_chain);
34523
34524+static struct crypto_alg *crypto_larval_wait(struct crypto_alg *alg);
34525+
34526 struct crypto_alg *crypto_mod_get(struct crypto_alg *alg)
34527 {
34528 return try_module_get(alg->cra_module) ? crypto_alg_get(alg) : NULL;
34529@@ -144,8 +146,11 @@ static struct crypto_alg *crypto_larval_add(const char *name, u32 type,
34530 }
34531 up_write(&crypto_alg_sem);
34532
34533- if (alg != &larval->alg)
34534+ if (alg != &larval->alg) {
34535 kfree(larval);
34536+ if (crypto_is_larval(alg))
34537+ alg = crypto_larval_wait(alg);
34538+ }
34539
34540 return alg;
34541 }
34542diff --git a/crypto/cryptd.c b/crypto/cryptd.c
34543index 7bdd61b..afec999 100644
34544--- a/crypto/cryptd.c
34545+++ b/crypto/cryptd.c
34546@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
34547
34548 struct cryptd_blkcipher_request_ctx {
34549 crypto_completion_t complete;
34550-};
34551+} __no_const;
34552
34553 struct cryptd_hash_ctx {
34554 struct crypto_shash *child;
34555@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
34556
34557 struct cryptd_aead_request_ctx {
34558 crypto_completion_t complete;
34559-};
34560+} __no_const;
34561
34562 static void cryptd_queue_worker(struct work_struct *work);
34563
34564diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
34565index f8c920c..ab2cb5a 100644
34566--- a/crypto/pcrypt.c
34567+++ b/crypto/pcrypt.c
34568@@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
34569 int ret;
34570
34571 pinst->kobj.kset = pcrypt_kset;
34572- ret = kobject_add(&pinst->kobj, NULL, name);
34573+ ret = kobject_add(&pinst->kobj, NULL, "%s", name);
34574 if (!ret)
34575 kobject_uevent(&pinst->kobj, KOBJ_ADD);
34576
34577diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
34578index f220d64..d359ad6 100644
34579--- a/drivers/acpi/apei/apei-internal.h
34580+++ b/drivers/acpi/apei/apei-internal.h
34581@@ -20,7 +20,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
34582 struct apei_exec_ins_type {
34583 u32 flags;
34584 apei_exec_ins_func_t run;
34585-};
34586+} __do_const;
34587
34588 struct apei_exec_context {
34589 u32 ip;
34590diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
34591index 33dc6a0..4b24b47 100644
34592--- a/drivers/acpi/apei/cper.c
34593+++ b/drivers/acpi/apei/cper.c
34594@@ -39,12 +39,12 @@
34595 */
34596 u64 cper_next_record_id(void)
34597 {
34598- static atomic64_t seq;
34599+ static atomic64_unchecked_t seq;
34600
34601- if (!atomic64_read(&seq))
34602- atomic64_set(&seq, ((u64)get_seconds()) << 32);
34603+ if (!atomic64_read_unchecked(&seq))
34604+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
34605
34606- return atomic64_inc_return(&seq);
34607+ return atomic64_inc_return_unchecked(&seq);
34608 }
34609 EXPORT_SYMBOL_GPL(cper_next_record_id);
34610
34611diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
34612index ec9b57d..9682b3a 100644
34613--- a/drivers/acpi/apei/ghes.c
34614+++ b/drivers/acpi/apei/ghes.c
34615@@ -478,7 +478,7 @@ static void __ghes_print_estatus(const char *pfx,
34616 const struct acpi_hest_generic *generic,
34617 const struct acpi_hest_generic_status *estatus)
34618 {
34619- static atomic_t seqno;
34620+ static atomic_unchecked_t seqno;
34621 unsigned int curr_seqno;
34622 char pfx_seq[64];
34623
34624@@ -489,7 +489,7 @@ static void __ghes_print_estatus(const char *pfx,
34625 else
34626 pfx = KERN_ERR;
34627 }
34628- curr_seqno = atomic_inc_return(&seqno);
34629+ curr_seqno = atomic_inc_return_unchecked(&seqno);
34630 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
34631 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
34632 pfx_seq, generic->header.source_id);
34633diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
34634index be60399..778b33e8 100644
34635--- a/drivers/acpi/bgrt.c
34636+++ b/drivers/acpi/bgrt.c
34637@@ -87,8 +87,10 @@ static int __init bgrt_init(void)
34638 return -ENODEV;
34639
34640 sysfs_bin_attr_init(&image_attr);
34641- image_attr.private = bgrt_image;
34642- image_attr.size = bgrt_image_size;
34643+ pax_open_kernel();
34644+ *(void **)&image_attr.private = bgrt_image;
34645+ *(size_t *)&image_attr.size = bgrt_image_size;
34646+ pax_close_kernel();
34647
34648 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
34649 if (!bgrt_kobj)
34650diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
34651index cb96296..b81293b 100644
34652--- a/drivers/acpi/blacklist.c
34653+++ b/drivers/acpi/blacklist.c
34654@@ -52,7 +52,7 @@ struct acpi_blacklist_item {
34655 u32 is_critical_error;
34656 };
34657
34658-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
34659+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
34660
34661 /*
34662 * POLICY: If *anything* doesn't work, put it on the blacklist.
34663@@ -193,7 +193,7 @@ static int __init dmi_disable_osi_win7(const struct dmi_system_id *d)
34664 return 0;
34665 }
34666
34667-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
34668+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
34669 {
34670 .callback = dmi_disable_osi_vista,
34671 .ident = "Fujitsu Siemens",
34672diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
34673index f98dd00..7b69865 100644
34674--- a/drivers/acpi/processor_idle.c
34675+++ b/drivers/acpi/processor_idle.c
34676@@ -992,7 +992,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
34677 {
34678 int i, count = CPUIDLE_DRIVER_STATE_START;
34679 struct acpi_processor_cx *cx;
34680- struct cpuidle_state *state;
34681+ cpuidle_state_no_const *state;
34682 struct cpuidle_driver *drv = &acpi_idle_driver;
34683
34684 if (!pr->flags.power_setup_done)
34685diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
34686index 05306a5..733d1f0 100644
34687--- a/drivers/acpi/sysfs.c
34688+++ b/drivers/acpi/sysfs.c
34689@@ -423,11 +423,11 @@ static u32 num_counters;
34690 static struct attribute **all_attrs;
34691 static u32 acpi_gpe_count;
34692
34693-static struct attribute_group interrupt_stats_attr_group = {
34694+static attribute_group_no_const interrupt_stats_attr_group = {
34695 .name = "interrupts",
34696 };
34697
34698-static struct kobj_attribute *counter_attrs;
34699+static kobj_attribute_no_const *counter_attrs;
34700
34701 static void delete_gpe_attr_array(void)
34702 {
34703diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
34704index acfd0f7..e5acb08 100644
34705--- a/drivers/ata/libahci.c
34706+++ b/drivers/ata/libahci.c
34707@@ -1231,7 +1231,7 @@ int ahci_kick_engine(struct ata_port *ap)
34708 }
34709 EXPORT_SYMBOL_GPL(ahci_kick_engine);
34710
34711-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
34712+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
34713 struct ata_taskfile *tf, int is_cmd, u16 flags,
34714 unsigned long timeout_msec)
34715 {
34716diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
34717index c24354d..335c975 100644
34718--- a/drivers/ata/libata-core.c
34719+++ b/drivers/ata/libata-core.c
34720@@ -98,7 +98,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
34721 static void ata_dev_xfermask(struct ata_device *dev);
34722 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
34723
34724-atomic_t ata_print_id = ATOMIC_INIT(0);
34725+atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
34726
34727 struct ata_force_param {
34728 const char *name;
34729@@ -4792,7 +4792,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
34730 struct ata_port *ap;
34731 unsigned int tag;
34732
34733- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
34734+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
34735 ap = qc->ap;
34736
34737 qc->flags = 0;
34738@@ -4808,7 +4808,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
34739 struct ata_port *ap;
34740 struct ata_link *link;
34741
34742- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
34743+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
34744 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
34745 ap = qc->ap;
34746 link = qc->dev->link;
34747@@ -5927,6 +5927,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
34748 return;
34749
34750 spin_lock(&lock);
34751+ pax_open_kernel();
34752
34753 for (cur = ops->inherits; cur; cur = cur->inherits) {
34754 void **inherit = (void **)cur;
34755@@ -5940,8 +5941,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
34756 if (IS_ERR(*pp))
34757 *pp = NULL;
34758
34759- ops->inherits = NULL;
34760+ *(struct ata_port_operations **)&ops->inherits = NULL;
34761
34762+ pax_close_kernel();
34763 spin_unlock(&lock);
34764 }
34765
34766@@ -6134,7 +6136,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
34767
34768 /* give ports names and add SCSI hosts */
34769 for (i = 0; i < host->n_ports; i++) {
34770- host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
34771+ host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
34772 host->ports[i]->local_port_no = i + 1;
34773 }
34774
34775diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
34776index b1e880a..8cf82e1 100644
34777--- a/drivers/ata/libata-scsi.c
34778+++ b/drivers/ata/libata-scsi.c
34779@@ -4104,7 +4104,7 @@ int ata_sas_port_init(struct ata_port *ap)
34780
34781 if (rc)
34782 return rc;
34783- ap->print_id = atomic_inc_return(&ata_print_id);
34784+ ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
34785 return 0;
34786 }
34787 EXPORT_SYMBOL_GPL(ata_sas_port_init);
34788diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
34789index 577d902b..cb4781e 100644
34790--- a/drivers/ata/libata.h
34791+++ b/drivers/ata/libata.h
34792@@ -53,7 +53,7 @@ enum {
34793 ATA_DNXFER_QUIET = (1 << 31),
34794 };
34795
34796-extern atomic_t ata_print_id;
34797+extern atomic_unchecked_t ata_print_id;
34798 extern int atapi_passthru16;
34799 extern int libata_fua;
34800 extern int libata_noacpi;
34801diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
34802index 848ed32..132f39d 100644
34803--- a/drivers/ata/pata_arasan_cf.c
34804+++ b/drivers/ata/pata_arasan_cf.c
34805@@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
34806 /* Handle platform specific quirks */
34807 if (quirk) {
34808 if (quirk & CF_BROKEN_PIO) {
34809- ap->ops->set_piomode = NULL;
34810+ pax_open_kernel();
34811+ *(void **)&ap->ops->set_piomode = NULL;
34812+ pax_close_kernel();
34813 ap->pio_mask = 0;
34814 }
34815 if (quirk & CF_BROKEN_MWDMA)
34816diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
34817index f9b983a..887b9d8 100644
34818--- a/drivers/atm/adummy.c
34819+++ b/drivers/atm/adummy.c
34820@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
34821 vcc->pop(vcc, skb);
34822 else
34823 dev_kfree_skb_any(skb);
34824- atomic_inc(&vcc->stats->tx);
34825+ atomic_inc_unchecked(&vcc->stats->tx);
34826
34827 return 0;
34828 }
34829diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
34830index 62a7607..cc4be104 100644
34831--- a/drivers/atm/ambassador.c
34832+++ b/drivers/atm/ambassador.c
34833@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
34834 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
34835
34836 // VC layer stats
34837- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
34838+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
34839
34840 // free the descriptor
34841 kfree (tx_descr);
34842@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
34843 dump_skb ("<<<", vc, skb);
34844
34845 // VC layer stats
34846- atomic_inc(&atm_vcc->stats->rx);
34847+ atomic_inc_unchecked(&atm_vcc->stats->rx);
34848 __net_timestamp(skb);
34849 // end of our responsibility
34850 atm_vcc->push (atm_vcc, skb);
34851@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
34852 } else {
34853 PRINTK (KERN_INFO, "dropped over-size frame");
34854 // should we count this?
34855- atomic_inc(&atm_vcc->stats->rx_drop);
34856+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
34857 }
34858
34859 } else {
34860@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
34861 }
34862
34863 if (check_area (skb->data, skb->len)) {
34864- atomic_inc(&atm_vcc->stats->tx_err);
34865+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
34866 return -ENOMEM; // ?
34867 }
34868
34869diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
34870index 0e3f8f9..765a7a5 100644
34871--- a/drivers/atm/atmtcp.c
34872+++ b/drivers/atm/atmtcp.c
34873@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
34874 if (vcc->pop) vcc->pop(vcc,skb);
34875 else dev_kfree_skb(skb);
34876 if (dev_data) return 0;
34877- atomic_inc(&vcc->stats->tx_err);
34878+ atomic_inc_unchecked(&vcc->stats->tx_err);
34879 return -ENOLINK;
34880 }
34881 size = skb->len+sizeof(struct atmtcp_hdr);
34882@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
34883 if (!new_skb) {
34884 if (vcc->pop) vcc->pop(vcc,skb);
34885 else dev_kfree_skb(skb);
34886- atomic_inc(&vcc->stats->tx_err);
34887+ atomic_inc_unchecked(&vcc->stats->tx_err);
34888 return -ENOBUFS;
34889 }
34890 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
34891@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
34892 if (vcc->pop) vcc->pop(vcc,skb);
34893 else dev_kfree_skb(skb);
34894 out_vcc->push(out_vcc,new_skb);
34895- atomic_inc(&vcc->stats->tx);
34896- atomic_inc(&out_vcc->stats->rx);
34897+ atomic_inc_unchecked(&vcc->stats->tx);
34898+ atomic_inc_unchecked(&out_vcc->stats->rx);
34899 return 0;
34900 }
34901
34902@@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
34903 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
34904 read_unlock(&vcc_sklist_lock);
34905 if (!out_vcc) {
34906- atomic_inc(&vcc->stats->tx_err);
34907+ atomic_inc_unchecked(&vcc->stats->tx_err);
34908 goto done;
34909 }
34910 skb_pull(skb,sizeof(struct atmtcp_hdr));
34911@@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
34912 __net_timestamp(new_skb);
34913 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
34914 out_vcc->push(out_vcc,new_skb);
34915- atomic_inc(&vcc->stats->tx);
34916- atomic_inc(&out_vcc->stats->rx);
34917+ atomic_inc_unchecked(&vcc->stats->tx);
34918+ atomic_inc_unchecked(&out_vcc->stats->rx);
34919 done:
34920 if (vcc->pop) vcc->pop(vcc,skb);
34921 else dev_kfree_skb(skb);
34922diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
34923index b1955ba..b179940 100644
34924--- a/drivers/atm/eni.c
34925+++ b/drivers/atm/eni.c
34926@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
34927 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
34928 vcc->dev->number);
34929 length = 0;
34930- atomic_inc(&vcc->stats->rx_err);
34931+ atomic_inc_unchecked(&vcc->stats->rx_err);
34932 }
34933 else {
34934 length = ATM_CELL_SIZE-1; /* no HEC */
34935@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
34936 size);
34937 }
34938 eff = length = 0;
34939- atomic_inc(&vcc->stats->rx_err);
34940+ atomic_inc_unchecked(&vcc->stats->rx_err);
34941 }
34942 else {
34943 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
34944@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
34945 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
34946 vcc->dev->number,vcc->vci,length,size << 2,descr);
34947 length = eff = 0;
34948- atomic_inc(&vcc->stats->rx_err);
34949+ atomic_inc_unchecked(&vcc->stats->rx_err);
34950 }
34951 }
34952 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
34953@@ -767,7 +767,7 @@ rx_dequeued++;
34954 vcc->push(vcc,skb);
34955 pushed++;
34956 }
34957- atomic_inc(&vcc->stats->rx);
34958+ atomic_inc_unchecked(&vcc->stats->rx);
34959 }
34960 wake_up(&eni_dev->rx_wait);
34961 }
34962@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
34963 PCI_DMA_TODEVICE);
34964 if (vcc->pop) vcc->pop(vcc,skb);
34965 else dev_kfree_skb_irq(skb);
34966- atomic_inc(&vcc->stats->tx);
34967+ atomic_inc_unchecked(&vcc->stats->tx);
34968 wake_up(&eni_dev->tx_wait);
34969 dma_complete++;
34970 }
34971diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
34972index b41c948..a002b17 100644
34973--- a/drivers/atm/firestream.c
34974+++ b/drivers/atm/firestream.c
34975@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
34976 }
34977 }
34978
34979- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
34980+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
34981
34982 fs_dprintk (FS_DEBUG_TXMEM, "i");
34983 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
34984@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
34985 #endif
34986 skb_put (skb, qe->p1 & 0xffff);
34987 ATM_SKB(skb)->vcc = atm_vcc;
34988- atomic_inc(&atm_vcc->stats->rx);
34989+ atomic_inc_unchecked(&atm_vcc->stats->rx);
34990 __net_timestamp(skb);
34991 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
34992 atm_vcc->push (atm_vcc, skb);
34993@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
34994 kfree (pe);
34995 }
34996 if (atm_vcc)
34997- atomic_inc(&atm_vcc->stats->rx_drop);
34998+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
34999 break;
35000 case 0x1f: /* Reassembly abort: no buffers. */
35001 /* Silently increment error counter. */
35002 if (atm_vcc)
35003- atomic_inc(&atm_vcc->stats->rx_drop);
35004+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
35005 break;
35006 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
35007 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
35008diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
35009index 204814e..cede831 100644
35010--- a/drivers/atm/fore200e.c
35011+++ b/drivers/atm/fore200e.c
35012@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
35013 #endif
35014 /* check error condition */
35015 if (*entry->status & STATUS_ERROR)
35016- atomic_inc(&vcc->stats->tx_err);
35017+ atomic_inc_unchecked(&vcc->stats->tx_err);
35018 else
35019- atomic_inc(&vcc->stats->tx);
35020+ atomic_inc_unchecked(&vcc->stats->tx);
35021 }
35022 }
35023
35024@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
35025 if (skb == NULL) {
35026 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
35027
35028- atomic_inc(&vcc->stats->rx_drop);
35029+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35030 return -ENOMEM;
35031 }
35032
35033@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
35034
35035 dev_kfree_skb_any(skb);
35036
35037- atomic_inc(&vcc->stats->rx_drop);
35038+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35039 return -ENOMEM;
35040 }
35041
35042 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
35043
35044 vcc->push(vcc, skb);
35045- atomic_inc(&vcc->stats->rx);
35046+ atomic_inc_unchecked(&vcc->stats->rx);
35047
35048 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
35049
35050@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
35051 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
35052 fore200e->atm_dev->number,
35053 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
35054- atomic_inc(&vcc->stats->rx_err);
35055+ atomic_inc_unchecked(&vcc->stats->rx_err);
35056 }
35057 }
35058
35059@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
35060 goto retry_here;
35061 }
35062
35063- atomic_inc(&vcc->stats->tx_err);
35064+ atomic_inc_unchecked(&vcc->stats->tx_err);
35065
35066 fore200e->tx_sat++;
35067 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
35068diff --git a/drivers/atm/he.c b/drivers/atm/he.c
35069index 507362a..a845e57 100644
35070--- a/drivers/atm/he.c
35071+++ b/drivers/atm/he.c
35072@@ -1698,7 +1698,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35073
35074 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
35075 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
35076- atomic_inc(&vcc->stats->rx_drop);
35077+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35078 goto return_host_buffers;
35079 }
35080
35081@@ -1725,7 +1725,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35082 RBRQ_LEN_ERR(he_dev->rbrq_head)
35083 ? "LEN_ERR" : "",
35084 vcc->vpi, vcc->vci);
35085- atomic_inc(&vcc->stats->rx_err);
35086+ atomic_inc_unchecked(&vcc->stats->rx_err);
35087 goto return_host_buffers;
35088 }
35089
35090@@ -1777,7 +1777,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35091 vcc->push(vcc, skb);
35092 spin_lock(&he_dev->global_lock);
35093
35094- atomic_inc(&vcc->stats->rx);
35095+ atomic_inc_unchecked(&vcc->stats->rx);
35096
35097 return_host_buffers:
35098 ++pdus_assembled;
35099@@ -2103,7 +2103,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
35100 tpd->vcc->pop(tpd->vcc, tpd->skb);
35101 else
35102 dev_kfree_skb_any(tpd->skb);
35103- atomic_inc(&tpd->vcc->stats->tx_err);
35104+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
35105 }
35106 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
35107 return;
35108@@ -2515,7 +2515,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35109 vcc->pop(vcc, skb);
35110 else
35111 dev_kfree_skb_any(skb);
35112- atomic_inc(&vcc->stats->tx_err);
35113+ atomic_inc_unchecked(&vcc->stats->tx_err);
35114 return -EINVAL;
35115 }
35116
35117@@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35118 vcc->pop(vcc, skb);
35119 else
35120 dev_kfree_skb_any(skb);
35121- atomic_inc(&vcc->stats->tx_err);
35122+ atomic_inc_unchecked(&vcc->stats->tx_err);
35123 return -EINVAL;
35124 }
35125 #endif
35126@@ -2538,7 +2538,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35127 vcc->pop(vcc, skb);
35128 else
35129 dev_kfree_skb_any(skb);
35130- atomic_inc(&vcc->stats->tx_err);
35131+ atomic_inc_unchecked(&vcc->stats->tx_err);
35132 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35133 return -ENOMEM;
35134 }
35135@@ -2580,7 +2580,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35136 vcc->pop(vcc, skb);
35137 else
35138 dev_kfree_skb_any(skb);
35139- atomic_inc(&vcc->stats->tx_err);
35140+ atomic_inc_unchecked(&vcc->stats->tx_err);
35141 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35142 return -ENOMEM;
35143 }
35144@@ -2611,7 +2611,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35145 __enqueue_tpd(he_dev, tpd, cid);
35146 spin_unlock_irqrestore(&he_dev->global_lock, flags);
35147
35148- atomic_inc(&vcc->stats->tx);
35149+ atomic_inc_unchecked(&vcc->stats->tx);
35150
35151 return 0;
35152 }
35153diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
35154index 1dc0519..1aadaf7 100644
35155--- a/drivers/atm/horizon.c
35156+++ b/drivers/atm/horizon.c
35157@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
35158 {
35159 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
35160 // VC layer stats
35161- atomic_inc(&vcc->stats->rx);
35162+ atomic_inc_unchecked(&vcc->stats->rx);
35163 __net_timestamp(skb);
35164 // end of our responsibility
35165 vcc->push (vcc, skb);
35166@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
35167 dev->tx_iovec = NULL;
35168
35169 // VC layer stats
35170- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
35171+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
35172
35173 // free the skb
35174 hrz_kfree_skb (skb);
35175diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
35176index 272f009..a18ba55 100644
35177--- a/drivers/atm/idt77252.c
35178+++ b/drivers/atm/idt77252.c
35179@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
35180 else
35181 dev_kfree_skb(skb);
35182
35183- atomic_inc(&vcc->stats->tx);
35184+ atomic_inc_unchecked(&vcc->stats->tx);
35185 }
35186
35187 atomic_dec(&scq->used);
35188@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35189 if ((sb = dev_alloc_skb(64)) == NULL) {
35190 printk("%s: Can't allocate buffers for aal0.\n",
35191 card->name);
35192- atomic_add(i, &vcc->stats->rx_drop);
35193+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
35194 break;
35195 }
35196 if (!atm_charge(vcc, sb->truesize)) {
35197 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
35198 card->name);
35199- atomic_add(i - 1, &vcc->stats->rx_drop);
35200+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
35201 dev_kfree_skb(sb);
35202 break;
35203 }
35204@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35205 ATM_SKB(sb)->vcc = vcc;
35206 __net_timestamp(sb);
35207 vcc->push(vcc, sb);
35208- atomic_inc(&vcc->stats->rx);
35209+ atomic_inc_unchecked(&vcc->stats->rx);
35210
35211 cell += ATM_CELL_PAYLOAD;
35212 }
35213@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35214 "(CDC: %08x)\n",
35215 card->name, len, rpp->len, readl(SAR_REG_CDC));
35216 recycle_rx_pool_skb(card, rpp);
35217- atomic_inc(&vcc->stats->rx_err);
35218+ atomic_inc_unchecked(&vcc->stats->rx_err);
35219 return;
35220 }
35221 if (stat & SAR_RSQE_CRC) {
35222 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
35223 recycle_rx_pool_skb(card, rpp);
35224- atomic_inc(&vcc->stats->rx_err);
35225+ atomic_inc_unchecked(&vcc->stats->rx_err);
35226 return;
35227 }
35228 if (skb_queue_len(&rpp->queue) > 1) {
35229@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35230 RXPRINTK("%s: Can't alloc RX skb.\n",
35231 card->name);
35232 recycle_rx_pool_skb(card, rpp);
35233- atomic_inc(&vcc->stats->rx_err);
35234+ atomic_inc_unchecked(&vcc->stats->rx_err);
35235 return;
35236 }
35237 if (!atm_charge(vcc, skb->truesize)) {
35238@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35239 __net_timestamp(skb);
35240
35241 vcc->push(vcc, skb);
35242- atomic_inc(&vcc->stats->rx);
35243+ atomic_inc_unchecked(&vcc->stats->rx);
35244
35245 return;
35246 }
35247@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
35248 __net_timestamp(skb);
35249
35250 vcc->push(vcc, skb);
35251- atomic_inc(&vcc->stats->rx);
35252+ atomic_inc_unchecked(&vcc->stats->rx);
35253
35254 if (skb->truesize > SAR_FB_SIZE_3)
35255 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
35256@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
35257 if (vcc->qos.aal != ATM_AAL0) {
35258 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
35259 card->name, vpi, vci);
35260- atomic_inc(&vcc->stats->rx_drop);
35261+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35262 goto drop;
35263 }
35264
35265 if ((sb = dev_alloc_skb(64)) == NULL) {
35266 printk("%s: Can't allocate buffers for AAL0.\n",
35267 card->name);
35268- atomic_inc(&vcc->stats->rx_err);
35269+ atomic_inc_unchecked(&vcc->stats->rx_err);
35270 goto drop;
35271 }
35272
35273@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
35274 ATM_SKB(sb)->vcc = vcc;
35275 __net_timestamp(sb);
35276 vcc->push(vcc, sb);
35277- atomic_inc(&vcc->stats->rx);
35278+ atomic_inc_unchecked(&vcc->stats->rx);
35279
35280 drop:
35281 skb_pull(queue, 64);
35282@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
35283
35284 if (vc == NULL) {
35285 printk("%s: NULL connection in send().\n", card->name);
35286- atomic_inc(&vcc->stats->tx_err);
35287+ atomic_inc_unchecked(&vcc->stats->tx_err);
35288 dev_kfree_skb(skb);
35289 return -EINVAL;
35290 }
35291 if (!test_bit(VCF_TX, &vc->flags)) {
35292 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
35293- atomic_inc(&vcc->stats->tx_err);
35294+ atomic_inc_unchecked(&vcc->stats->tx_err);
35295 dev_kfree_skb(skb);
35296 return -EINVAL;
35297 }
35298@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
35299 break;
35300 default:
35301 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
35302- atomic_inc(&vcc->stats->tx_err);
35303+ atomic_inc_unchecked(&vcc->stats->tx_err);
35304 dev_kfree_skb(skb);
35305 return -EINVAL;
35306 }
35307
35308 if (skb_shinfo(skb)->nr_frags != 0) {
35309 printk("%s: No scatter-gather yet.\n", card->name);
35310- atomic_inc(&vcc->stats->tx_err);
35311+ atomic_inc_unchecked(&vcc->stats->tx_err);
35312 dev_kfree_skb(skb);
35313 return -EINVAL;
35314 }
35315@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
35316
35317 err = queue_skb(card, vc, skb, oam);
35318 if (err) {
35319- atomic_inc(&vcc->stats->tx_err);
35320+ atomic_inc_unchecked(&vcc->stats->tx_err);
35321 dev_kfree_skb(skb);
35322 return err;
35323 }
35324@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
35325 skb = dev_alloc_skb(64);
35326 if (!skb) {
35327 printk("%s: Out of memory in send_oam().\n", card->name);
35328- atomic_inc(&vcc->stats->tx_err);
35329+ atomic_inc_unchecked(&vcc->stats->tx_err);
35330 return -ENOMEM;
35331 }
35332 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
35333diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
35334index 4217f29..88f547a 100644
35335--- a/drivers/atm/iphase.c
35336+++ b/drivers/atm/iphase.c
35337@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
35338 status = (u_short) (buf_desc_ptr->desc_mode);
35339 if (status & (RX_CER | RX_PTE | RX_OFL))
35340 {
35341- atomic_inc(&vcc->stats->rx_err);
35342+ atomic_inc_unchecked(&vcc->stats->rx_err);
35343 IF_ERR(printk("IA: bad packet, dropping it");)
35344 if (status & RX_CER) {
35345 IF_ERR(printk(" cause: packet CRC error\n");)
35346@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
35347 len = dma_addr - buf_addr;
35348 if (len > iadev->rx_buf_sz) {
35349 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
35350- atomic_inc(&vcc->stats->rx_err);
35351+ atomic_inc_unchecked(&vcc->stats->rx_err);
35352 goto out_free_desc;
35353 }
35354
35355@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
35356 ia_vcc = INPH_IA_VCC(vcc);
35357 if (ia_vcc == NULL)
35358 {
35359- atomic_inc(&vcc->stats->rx_err);
35360+ atomic_inc_unchecked(&vcc->stats->rx_err);
35361 atm_return(vcc, skb->truesize);
35362 dev_kfree_skb_any(skb);
35363 goto INCR_DLE;
35364@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
35365 if ((length > iadev->rx_buf_sz) || (length >
35366 (skb->len - sizeof(struct cpcs_trailer))))
35367 {
35368- atomic_inc(&vcc->stats->rx_err);
35369+ atomic_inc_unchecked(&vcc->stats->rx_err);
35370 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
35371 length, skb->len);)
35372 atm_return(vcc, skb->truesize);
35373@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
35374
35375 IF_RX(printk("rx_dle_intr: skb push");)
35376 vcc->push(vcc,skb);
35377- atomic_inc(&vcc->stats->rx);
35378+ atomic_inc_unchecked(&vcc->stats->rx);
35379 iadev->rx_pkt_cnt++;
35380 }
35381 INCR_DLE:
35382@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
35383 {
35384 struct k_sonet_stats *stats;
35385 stats = &PRIV(_ia_dev[board])->sonet_stats;
35386- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
35387- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
35388- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
35389- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
35390- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
35391- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
35392- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
35393- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
35394- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
35395+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
35396+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
35397+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
35398+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
35399+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
35400+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
35401+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
35402+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
35403+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
35404 }
35405 ia_cmds.status = 0;
35406 break;
35407@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
35408 if ((desc == 0) || (desc > iadev->num_tx_desc))
35409 {
35410 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
35411- atomic_inc(&vcc->stats->tx);
35412+ atomic_inc_unchecked(&vcc->stats->tx);
35413 if (vcc->pop)
35414 vcc->pop(vcc, skb);
35415 else
35416@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
35417 ATM_DESC(skb) = vcc->vci;
35418 skb_queue_tail(&iadev->tx_dma_q, skb);
35419
35420- atomic_inc(&vcc->stats->tx);
35421+ atomic_inc_unchecked(&vcc->stats->tx);
35422 iadev->tx_pkt_cnt++;
35423 /* Increment transaction counter */
35424 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
35425
35426 #if 0
35427 /* add flow control logic */
35428- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
35429+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
35430 if (iavcc->vc_desc_cnt > 10) {
35431 vcc->tx_quota = vcc->tx_quota * 3 / 4;
35432 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
35433diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
35434index fa7d701..1e404c7 100644
35435--- a/drivers/atm/lanai.c
35436+++ b/drivers/atm/lanai.c
35437@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
35438 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
35439 lanai_endtx(lanai, lvcc);
35440 lanai_free_skb(lvcc->tx.atmvcc, skb);
35441- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
35442+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
35443 }
35444
35445 /* Try to fill the buffer - don't call unless there is backlog */
35446@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
35447 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
35448 __net_timestamp(skb);
35449 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
35450- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
35451+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
35452 out:
35453 lvcc->rx.buf.ptr = end;
35454 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
35455@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
35456 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
35457 "vcc %d\n", lanai->number, (unsigned int) s, vci);
35458 lanai->stats.service_rxnotaal5++;
35459- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
35460+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
35461 return 0;
35462 }
35463 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
35464@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
35465 int bytes;
35466 read_unlock(&vcc_sklist_lock);
35467 DPRINTK("got trashed rx pdu on vci %d\n", vci);
35468- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
35469+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
35470 lvcc->stats.x.aal5.service_trash++;
35471 bytes = (SERVICE_GET_END(s) * 16) -
35472 (((unsigned long) lvcc->rx.buf.ptr) -
35473@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
35474 }
35475 if (s & SERVICE_STREAM) {
35476 read_unlock(&vcc_sklist_lock);
35477- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
35478+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
35479 lvcc->stats.x.aal5.service_stream++;
35480 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
35481 "PDU on VCI %d!\n", lanai->number, vci);
35482@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
35483 return 0;
35484 }
35485 DPRINTK("got rx crc error on vci %d\n", vci);
35486- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
35487+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
35488 lvcc->stats.x.aal5.service_rxcrc++;
35489 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
35490 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
35491diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
35492index 6587dc2..149833d 100644
35493--- a/drivers/atm/nicstar.c
35494+++ b/drivers/atm/nicstar.c
35495@@ -1641,7 +1641,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
35496 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
35497 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
35498 card->index);
35499- atomic_inc(&vcc->stats->tx_err);
35500+ atomic_inc_unchecked(&vcc->stats->tx_err);
35501 dev_kfree_skb_any(skb);
35502 return -EINVAL;
35503 }
35504@@ -1649,7 +1649,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
35505 if (!vc->tx) {
35506 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
35507 card->index);
35508- atomic_inc(&vcc->stats->tx_err);
35509+ atomic_inc_unchecked(&vcc->stats->tx_err);
35510 dev_kfree_skb_any(skb);
35511 return -EINVAL;
35512 }
35513@@ -1657,14 +1657,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
35514 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
35515 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
35516 card->index);
35517- atomic_inc(&vcc->stats->tx_err);
35518+ atomic_inc_unchecked(&vcc->stats->tx_err);
35519 dev_kfree_skb_any(skb);
35520 return -EINVAL;
35521 }
35522
35523 if (skb_shinfo(skb)->nr_frags != 0) {
35524 printk("nicstar%d: No scatter-gather yet.\n", card->index);
35525- atomic_inc(&vcc->stats->tx_err);
35526+ atomic_inc_unchecked(&vcc->stats->tx_err);
35527 dev_kfree_skb_any(skb);
35528 return -EINVAL;
35529 }
35530@@ -1712,11 +1712,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
35531 }
35532
35533 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
35534- atomic_inc(&vcc->stats->tx_err);
35535+ atomic_inc_unchecked(&vcc->stats->tx_err);
35536 dev_kfree_skb_any(skb);
35537 return -EIO;
35538 }
35539- atomic_inc(&vcc->stats->tx);
35540+ atomic_inc_unchecked(&vcc->stats->tx);
35541
35542 return 0;
35543 }
35544@@ -2033,14 +2033,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35545 printk
35546 ("nicstar%d: Can't allocate buffers for aal0.\n",
35547 card->index);
35548- atomic_add(i, &vcc->stats->rx_drop);
35549+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
35550 break;
35551 }
35552 if (!atm_charge(vcc, sb->truesize)) {
35553 RXPRINTK
35554 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
35555 card->index);
35556- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
35557+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
35558 dev_kfree_skb_any(sb);
35559 break;
35560 }
35561@@ -2055,7 +2055,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35562 ATM_SKB(sb)->vcc = vcc;
35563 __net_timestamp(sb);
35564 vcc->push(vcc, sb);
35565- atomic_inc(&vcc->stats->rx);
35566+ atomic_inc_unchecked(&vcc->stats->rx);
35567 cell += ATM_CELL_PAYLOAD;
35568 }
35569
35570@@ -2072,7 +2072,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35571 if (iovb == NULL) {
35572 printk("nicstar%d: Out of iovec buffers.\n",
35573 card->index);
35574- atomic_inc(&vcc->stats->rx_drop);
35575+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35576 recycle_rx_buf(card, skb);
35577 return;
35578 }
35579@@ -2096,7 +2096,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35580 small or large buffer itself. */
35581 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
35582 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
35583- atomic_inc(&vcc->stats->rx_err);
35584+ atomic_inc_unchecked(&vcc->stats->rx_err);
35585 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
35586 NS_MAX_IOVECS);
35587 NS_PRV_IOVCNT(iovb) = 0;
35588@@ -2116,7 +2116,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35589 ("nicstar%d: Expected a small buffer, and this is not one.\n",
35590 card->index);
35591 which_list(card, skb);
35592- atomic_inc(&vcc->stats->rx_err);
35593+ atomic_inc_unchecked(&vcc->stats->rx_err);
35594 recycle_rx_buf(card, skb);
35595 vc->rx_iov = NULL;
35596 recycle_iov_buf(card, iovb);
35597@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35598 ("nicstar%d: Expected a large buffer, and this is not one.\n",
35599 card->index);
35600 which_list(card, skb);
35601- atomic_inc(&vcc->stats->rx_err);
35602+ atomic_inc_unchecked(&vcc->stats->rx_err);
35603 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
35604 NS_PRV_IOVCNT(iovb));
35605 vc->rx_iov = NULL;
35606@@ -2152,7 +2152,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35607 printk(" - PDU size mismatch.\n");
35608 else
35609 printk(".\n");
35610- atomic_inc(&vcc->stats->rx_err);
35611+ atomic_inc_unchecked(&vcc->stats->rx_err);
35612 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
35613 NS_PRV_IOVCNT(iovb));
35614 vc->rx_iov = NULL;
35615@@ -2166,7 +2166,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35616 /* skb points to a small buffer */
35617 if (!atm_charge(vcc, skb->truesize)) {
35618 push_rxbufs(card, skb);
35619- atomic_inc(&vcc->stats->rx_drop);
35620+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35621 } else {
35622 skb_put(skb, len);
35623 dequeue_sm_buf(card, skb);
35624@@ -2176,7 +2176,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35625 ATM_SKB(skb)->vcc = vcc;
35626 __net_timestamp(skb);
35627 vcc->push(vcc, skb);
35628- atomic_inc(&vcc->stats->rx);
35629+ atomic_inc_unchecked(&vcc->stats->rx);
35630 }
35631 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
35632 struct sk_buff *sb;
35633@@ -2187,7 +2187,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35634 if (len <= NS_SMBUFSIZE) {
35635 if (!atm_charge(vcc, sb->truesize)) {
35636 push_rxbufs(card, sb);
35637- atomic_inc(&vcc->stats->rx_drop);
35638+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35639 } else {
35640 skb_put(sb, len);
35641 dequeue_sm_buf(card, sb);
35642@@ -2197,7 +2197,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35643 ATM_SKB(sb)->vcc = vcc;
35644 __net_timestamp(sb);
35645 vcc->push(vcc, sb);
35646- atomic_inc(&vcc->stats->rx);
35647+ atomic_inc_unchecked(&vcc->stats->rx);
35648 }
35649
35650 push_rxbufs(card, skb);
35651@@ -2206,7 +2206,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35652
35653 if (!atm_charge(vcc, skb->truesize)) {
35654 push_rxbufs(card, skb);
35655- atomic_inc(&vcc->stats->rx_drop);
35656+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35657 } else {
35658 dequeue_lg_buf(card, skb);
35659 #ifdef NS_USE_DESTRUCTORS
35660@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35661 ATM_SKB(skb)->vcc = vcc;
35662 __net_timestamp(skb);
35663 vcc->push(vcc, skb);
35664- atomic_inc(&vcc->stats->rx);
35665+ atomic_inc_unchecked(&vcc->stats->rx);
35666 }
35667
35668 push_rxbufs(card, sb);
35669@@ -2240,7 +2240,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35670 printk
35671 ("nicstar%d: Out of huge buffers.\n",
35672 card->index);
35673- atomic_inc(&vcc->stats->rx_drop);
35674+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35675 recycle_iovec_rx_bufs(card,
35676 (struct iovec *)
35677 iovb->data,
35678@@ -2291,7 +2291,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35679 card->hbpool.count++;
35680 } else
35681 dev_kfree_skb_any(hb);
35682- atomic_inc(&vcc->stats->rx_drop);
35683+ atomic_inc_unchecked(&vcc->stats->rx_drop);
35684 } else {
35685 /* Copy the small buffer to the huge buffer */
35686 sb = (struct sk_buff *)iov->iov_base;
35687@@ -2328,7 +2328,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
35688 #endif /* NS_USE_DESTRUCTORS */
35689 __net_timestamp(hb);
35690 vcc->push(vcc, hb);
35691- atomic_inc(&vcc->stats->rx);
35692+ atomic_inc_unchecked(&vcc->stats->rx);
35693 }
35694 }
35695
35696diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
35697index 32784d1..4a8434a 100644
35698--- a/drivers/atm/solos-pci.c
35699+++ b/drivers/atm/solos-pci.c
35700@@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
35701 }
35702 atm_charge(vcc, skb->truesize);
35703 vcc->push(vcc, skb);
35704- atomic_inc(&vcc->stats->rx);
35705+ atomic_inc_unchecked(&vcc->stats->rx);
35706 break;
35707
35708 case PKT_STATUS:
35709@@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
35710 vcc = SKB_CB(oldskb)->vcc;
35711
35712 if (vcc) {
35713- atomic_inc(&vcc->stats->tx);
35714+ atomic_inc_unchecked(&vcc->stats->tx);
35715 solos_pop(vcc, oldskb);
35716 } else {
35717 dev_kfree_skb_irq(oldskb);
35718diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
35719index 0215934..ce9f5b1 100644
35720--- a/drivers/atm/suni.c
35721+++ b/drivers/atm/suni.c
35722@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
35723
35724
35725 #define ADD_LIMITED(s,v) \
35726- atomic_add((v),&stats->s); \
35727- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
35728+ atomic_add_unchecked((v),&stats->s); \
35729+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
35730
35731
35732 static void suni_hz(unsigned long from_timer)
35733diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
35734index 5120a96..e2572bd 100644
35735--- a/drivers/atm/uPD98402.c
35736+++ b/drivers/atm/uPD98402.c
35737@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
35738 struct sonet_stats tmp;
35739 int error = 0;
35740
35741- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
35742+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
35743 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
35744 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
35745 if (zero && !error) {
35746@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
35747
35748
35749 #define ADD_LIMITED(s,v) \
35750- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
35751- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
35752- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
35753+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
35754+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
35755+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
35756
35757
35758 static void stat_event(struct atm_dev *dev)
35759@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
35760 if (reason & uPD98402_INT_PFM) stat_event(dev);
35761 if (reason & uPD98402_INT_PCO) {
35762 (void) GET(PCOCR); /* clear interrupt cause */
35763- atomic_add(GET(HECCT),
35764+ atomic_add_unchecked(GET(HECCT),
35765 &PRIV(dev)->sonet_stats.uncorr_hcs);
35766 }
35767 if ((reason & uPD98402_INT_RFO) &&
35768@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
35769 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
35770 uPD98402_INT_LOS),PIMR); /* enable them */
35771 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
35772- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
35773- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
35774- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
35775+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
35776+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
35777+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
35778 return 0;
35779 }
35780
35781diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
35782index 969c3c2..9b72956 100644
35783--- a/drivers/atm/zatm.c
35784+++ b/drivers/atm/zatm.c
35785@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
35786 }
35787 if (!size) {
35788 dev_kfree_skb_irq(skb);
35789- if (vcc) atomic_inc(&vcc->stats->rx_err);
35790+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
35791 continue;
35792 }
35793 if (!atm_charge(vcc,skb->truesize)) {
35794@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
35795 skb->len = size;
35796 ATM_SKB(skb)->vcc = vcc;
35797 vcc->push(vcc,skb);
35798- atomic_inc(&vcc->stats->rx);
35799+ atomic_inc_unchecked(&vcc->stats->rx);
35800 }
35801 zout(pos & 0xffff,MTA(mbx));
35802 #if 0 /* probably a stupid idea */
35803@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
35804 skb_queue_head(&zatm_vcc->backlog,skb);
35805 break;
35806 }
35807- atomic_inc(&vcc->stats->tx);
35808+ atomic_inc_unchecked(&vcc->stats->tx);
35809 wake_up(&zatm_vcc->tx_wait);
35810 }
35811
35812diff --git a/drivers/base/bus.c b/drivers/base/bus.c
35813index d414331..b4dd4ba 100644
35814--- a/drivers/base/bus.c
35815+++ b/drivers/base/bus.c
35816@@ -1163,7 +1163,7 @@ int subsys_interface_register(struct subsys_interface *sif)
35817 return -EINVAL;
35818
35819 mutex_lock(&subsys->p->mutex);
35820- list_add_tail(&sif->node, &subsys->p->interfaces);
35821+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
35822 if (sif->add_dev) {
35823 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
35824 while ((dev = subsys_dev_iter_next(&iter)))
35825@@ -1188,7 +1188,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
35826 subsys = sif->subsys;
35827
35828 mutex_lock(&subsys->p->mutex);
35829- list_del_init(&sif->node);
35830+ pax_list_del_init((struct list_head *)&sif->node);
35831 if (sif->remove_dev) {
35832 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
35833 while ((dev = subsys_dev_iter_next(&iter)))
35834diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
35835index 7413d06..79155fa 100644
35836--- a/drivers/base/devtmpfs.c
35837+++ b/drivers/base/devtmpfs.c
35838@@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
35839 if (!thread)
35840 return 0;
35841
35842- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
35843+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
35844 if (err)
35845 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
35846 else
35847@@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
35848 *err = sys_unshare(CLONE_NEWNS);
35849 if (*err)
35850 goto out;
35851- *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
35852+ *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
35853 if (*err)
35854 goto out;
35855- sys_chdir("/.."); /* will traverse into overmounted root */
35856- sys_chroot(".");
35857+ sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
35858+ sys_chroot((char __force_user *)".");
35859 complete(&setup_done);
35860 while (1) {
35861 spin_lock(&req_lock);
35862diff --git a/drivers/base/node.c b/drivers/base/node.c
35863index 7616a77c..8f57f51 100644
35864--- a/drivers/base/node.c
35865+++ b/drivers/base/node.c
35866@@ -626,7 +626,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
35867 struct node_attr {
35868 struct device_attribute attr;
35869 enum node_states state;
35870-};
35871+} __do_const;
35872
35873 static ssize_t show_node_state(struct device *dev,
35874 struct device_attribute *attr, char *buf)
35875diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
35876index bfb8955..42c9b9a 100644
35877--- a/drivers/base/power/domain.c
35878+++ b/drivers/base/power/domain.c
35879@@ -1850,7 +1850,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
35880 {
35881 struct cpuidle_driver *cpuidle_drv;
35882 struct gpd_cpu_data *cpu_data;
35883- struct cpuidle_state *idle_state;
35884+ cpuidle_state_no_const *idle_state;
35885 int ret = 0;
35886
35887 if (IS_ERR_OR_NULL(genpd) || state < 0)
35888@@ -1918,7 +1918,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
35889 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
35890 {
35891 struct gpd_cpu_data *cpu_data;
35892- struct cpuidle_state *idle_state;
35893+ cpuidle_state_no_const *idle_state;
35894 int ret = 0;
35895
35896 if (IS_ERR_OR_NULL(genpd))
35897diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
35898index a53ebd2..8f73eeb 100644
35899--- a/drivers/base/power/sysfs.c
35900+++ b/drivers/base/power/sysfs.c
35901@@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
35902 return -EIO;
35903 }
35904 }
35905- return sprintf(buf, p);
35906+ return sprintf(buf, "%s", p);
35907 }
35908
35909 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
35910diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
35911index 2d56f41..8830f19 100644
35912--- a/drivers/base/power/wakeup.c
35913+++ b/drivers/base/power/wakeup.c
35914@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
35915 * They need to be modified together atomically, so it's better to use one
35916 * atomic variable to hold them both.
35917 */
35918-static atomic_t combined_event_count = ATOMIC_INIT(0);
35919+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
35920
35921 #define IN_PROGRESS_BITS (sizeof(int) * 4)
35922 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
35923
35924 static void split_counters(unsigned int *cnt, unsigned int *inpr)
35925 {
35926- unsigned int comb = atomic_read(&combined_event_count);
35927+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
35928
35929 *cnt = (comb >> IN_PROGRESS_BITS);
35930 *inpr = comb & MAX_IN_PROGRESS;
35931@@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
35932 ws->start_prevent_time = ws->last_time;
35933
35934 /* Increment the counter of events in progress. */
35935- cec = atomic_inc_return(&combined_event_count);
35936+ cec = atomic_inc_return_unchecked(&combined_event_count);
35937
35938 trace_wakeup_source_activate(ws->name, cec);
35939 }
35940@@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
35941 * Increment the counter of registered wakeup events and decrement the
35942 * couter of wakeup events in progress simultaneously.
35943 */
35944- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
35945+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
35946 trace_wakeup_source_deactivate(ws->name, cec);
35947
35948 split_counters(&cnt, &inpr);
35949diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
35950index e8d11b6..7b1b36f 100644
35951--- a/drivers/base/syscore.c
35952+++ b/drivers/base/syscore.c
35953@@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
35954 void register_syscore_ops(struct syscore_ops *ops)
35955 {
35956 mutex_lock(&syscore_ops_lock);
35957- list_add_tail(&ops->node, &syscore_ops_list);
35958+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
35959 mutex_unlock(&syscore_ops_lock);
35960 }
35961 EXPORT_SYMBOL_GPL(register_syscore_ops);
35962@@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
35963 void unregister_syscore_ops(struct syscore_ops *ops)
35964 {
35965 mutex_lock(&syscore_ops_lock);
35966- list_del(&ops->node);
35967+ pax_list_del((struct list_head *)&ops->node);
35968 mutex_unlock(&syscore_ops_lock);
35969 }
35970 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
35971diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
35972index 62b6c2c..4a11354 100644
35973--- a/drivers/block/cciss.c
35974+++ b/drivers/block/cciss.c
35975@@ -1189,6 +1189,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
35976 int err;
35977 u32 cp;
35978
35979+ memset(&arg64, 0, sizeof(arg64));
35980+
35981 err = 0;
35982 err |=
35983 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
35984@@ -3010,7 +3012,7 @@ static void start_io(ctlr_info_t *h)
35985 while (!list_empty(&h->reqQ)) {
35986 c = list_entry(h->reqQ.next, CommandList_struct, list);
35987 /* can't do anything if fifo is full */
35988- if ((h->access.fifo_full(h))) {
35989+ if ((h->access->fifo_full(h))) {
35990 dev_warn(&h->pdev->dev, "fifo full\n");
35991 break;
35992 }
35993@@ -3020,7 +3022,7 @@ static void start_io(ctlr_info_t *h)
35994 h->Qdepth--;
35995
35996 /* Tell the controller execute command */
35997- h->access.submit_command(h, c);
35998+ h->access->submit_command(h, c);
35999
36000 /* Put job onto the completed Q */
36001 addQ(&h->cmpQ, c);
36002@@ -3446,17 +3448,17 @@ startio:
36003
36004 static inline unsigned long get_next_completion(ctlr_info_t *h)
36005 {
36006- return h->access.command_completed(h);
36007+ return h->access->command_completed(h);
36008 }
36009
36010 static inline int interrupt_pending(ctlr_info_t *h)
36011 {
36012- return h->access.intr_pending(h);
36013+ return h->access->intr_pending(h);
36014 }
36015
36016 static inline long interrupt_not_for_us(ctlr_info_t *h)
36017 {
36018- return ((h->access.intr_pending(h) == 0) ||
36019+ return ((h->access->intr_pending(h) == 0) ||
36020 (h->interrupts_enabled == 0));
36021 }
36022
36023@@ -3489,7 +3491,7 @@ static inline u32 next_command(ctlr_info_t *h)
36024 u32 a;
36025
36026 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36027- return h->access.command_completed(h);
36028+ return h->access->command_completed(h);
36029
36030 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
36031 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
36032@@ -4046,7 +4048,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
36033 trans_support & CFGTBL_Trans_use_short_tags);
36034
36035 /* Change the access methods to the performant access methods */
36036- h->access = SA5_performant_access;
36037+ h->access = &SA5_performant_access;
36038 h->transMethod = CFGTBL_Trans_Performant;
36039
36040 return;
36041@@ -4319,7 +4321,7 @@ static int cciss_pci_init(ctlr_info_t *h)
36042 if (prod_index < 0)
36043 return -ENODEV;
36044 h->product_name = products[prod_index].product_name;
36045- h->access = *(products[prod_index].access);
36046+ h->access = products[prod_index].access;
36047
36048 if (cciss_board_disabled(h)) {
36049 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
36050@@ -5051,7 +5053,7 @@ reinit_after_soft_reset:
36051 }
36052
36053 /* make sure the board interrupts are off */
36054- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36055+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36056 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
36057 if (rc)
36058 goto clean2;
36059@@ -5101,7 +5103,7 @@ reinit_after_soft_reset:
36060 * fake ones to scoop up any residual completions.
36061 */
36062 spin_lock_irqsave(&h->lock, flags);
36063- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36064+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36065 spin_unlock_irqrestore(&h->lock, flags);
36066 free_irq(h->intr[h->intr_mode], h);
36067 rc = cciss_request_irq(h, cciss_msix_discard_completions,
36068@@ -5121,9 +5123,9 @@ reinit_after_soft_reset:
36069 dev_info(&h->pdev->dev, "Board READY.\n");
36070 dev_info(&h->pdev->dev,
36071 "Waiting for stale completions to drain.\n");
36072- h->access.set_intr_mask(h, CCISS_INTR_ON);
36073+ h->access->set_intr_mask(h, CCISS_INTR_ON);
36074 msleep(10000);
36075- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36076+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36077
36078 rc = controller_reset_failed(h->cfgtable);
36079 if (rc)
36080@@ -5146,7 +5148,7 @@ reinit_after_soft_reset:
36081 cciss_scsi_setup(h);
36082
36083 /* Turn the interrupts on so we can service requests */
36084- h->access.set_intr_mask(h, CCISS_INTR_ON);
36085+ h->access->set_intr_mask(h, CCISS_INTR_ON);
36086
36087 /* Get the firmware version */
36088 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
36089@@ -5218,7 +5220,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
36090 kfree(flush_buf);
36091 if (return_code != IO_OK)
36092 dev_warn(&h->pdev->dev, "Error flushing cache\n");
36093- h->access.set_intr_mask(h, CCISS_INTR_OFF);
36094+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
36095 free_irq(h->intr[h->intr_mode], h);
36096 }
36097
36098diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
36099index 7fda30e..eb5dfe0 100644
36100--- a/drivers/block/cciss.h
36101+++ b/drivers/block/cciss.h
36102@@ -101,7 +101,7 @@ struct ctlr_info
36103 /* information about each logical volume */
36104 drive_info_struct *drv[CISS_MAX_LUN];
36105
36106- struct access_method access;
36107+ struct access_method *access;
36108
36109 /* queue and queue Info */
36110 struct list_head reqQ;
36111diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
36112index 639d26b..fd6ad1f 100644
36113--- a/drivers/block/cpqarray.c
36114+++ b/drivers/block/cpqarray.c
36115@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
36116 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
36117 goto Enomem4;
36118 }
36119- hba[i]->access.set_intr_mask(hba[i], 0);
36120+ hba[i]->access->set_intr_mask(hba[i], 0);
36121 if (request_irq(hba[i]->intr, do_ida_intr,
36122 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
36123 {
36124@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
36125 add_timer(&hba[i]->timer);
36126
36127 /* Enable IRQ now that spinlock and rate limit timer are set up */
36128- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
36129+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
36130
36131 for(j=0; j<NWD; j++) {
36132 struct gendisk *disk = ida_gendisk[i][j];
36133@@ -694,7 +694,7 @@ DBGINFO(
36134 for(i=0; i<NR_PRODUCTS; i++) {
36135 if (board_id == products[i].board_id) {
36136 c->product_name = products[i].product_name;
36137- c->access = *(products[i].access);
36138+ c->access = products[i].access;
36139 break;
36140 }
36141 }
36142@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
36143 hba[ctlr]->intr = intr;
36144 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
36145 hba[ctlr]->product_name = products[j].product_name;
36146- hba[ctlr]->access = *(products[j].access);
36147+ hba[ctlr]->access = products[j].access;
36148 hba[ctlr]->ctlr = ctlr;
36149 hba[ctlr]->board_id = board_id;
36150 hba[ctlr]->pci_dev = NULL; /* not PCI */
36151@@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
36152
36153 while((c = h->reqQ) != NULL) {
36154 /* Can't do anything if we're busy */
36155- if (h->access.fifo_full(h) == 0)
36156+ if (h->access->fifo_full(h) == 0)
36157 return;
36158
36159 /* Get the first entry from the request Q */
36160@@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
36161 h->Qdepth--;
36162
36163 /* Tell the controller to do our bidding */
36164- h->access.submit_command(h, c);
36165+ h->access->submit_command(h, c);
36166
36167 /* Get onto the completion Q */
36168 addQ(&h->cmpQ, c);
36169@@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
36170 unsigned long flags;
36171 __u32 a,a1;
36172
36173- istat = h->access.intr_pending(h);
36174+ istat = h->access->intr_pending(h);
36175 /* Is this interrupt for us? */
36176 if (istat == 0)
36177 return IRQ_NONE;
36178@@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
36179 */
36180 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
36181 if (istat & FIFO_NOT_EMPTY) {
36182- while((a = h->access.command_completed(h))) {
36183+ while((a = h->access->command_completed(h))) {
36184 a1 = a; a &= ~3;
36185 if ((c = h->cmpQ) == NULL)
36186 {
36187@@ -1193,6 +1193,7 @@ out_passthru:
36188 ida_pci_info_struct pciinfo;
36189
36190 if (!arg) return -EINVAL;
36191+ memset(&pciinfo, 0, sizeof(pciinfo));
36192 pciinfo.bus = host->pci_dev->bus->number;
36193 pciinfo.dev_fn = host->pci_dev->devfn;
36194 pciinfo.board_id = host->board_id;
36195@@ -1447,11 +1448,11 @@ static int sendcmd(
36196 /*
36197 * Disable interrupt
36198 */
36199- info_p->access.set_intr_mask(info_p, 0);
36200+ info_p->access->set_intr_mask(info_p, 0);
36201 /* Make sure there is room in the command FIFO */
36202 /* Actually it should be completely empty at this time. */
36203 for (i = 200000; i > 0; i--) {
36204- temp = info_p->access.fifo_full(info_p);
36205+ temp = info_p->access->fifo_full(info_p);
36206 if (temp != 0) {
36207 break;
36208 }
36209@@ -1464,7 +1465,7 @@ DBG(
36210 /*
36211 * Send the cmd
36212 */
36213- info_p->access.submit_command(info_p, c);
36214+ info_p->access->submit_command(info_p, c);
36215 complete = pollcomplete(ctlr);
36216
36217 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
36218@@ -1547,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
36219 * we check the new geometry. Then turn interrupts back on when
36220 * we're done.
36221 */
36222- host->access.set_intr_mask(host, 0);
36223+ host->access->set_intr_mask(host, 0);
36224 getgeometry(ctlr);
36225- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
36226+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
36227
36228 for(i=0; i<NWD; i++) {
36229 struct gendisk *disk = ida_gendisk[ctlr][i];
36230@@ -1589,7 +1590,7 @@ static int pollcomplete(int ctlr)
36231 /* Wait (up to 2 seconds) for a command to complete */
36232
36233 for (i = 200000; i > 0; i--) {
36234- done = hba[ctlr]->access.command_completed(hba[ctlr]);
36235+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
36236 if (done == 0) {
36237 udelay(10); /* a short fixed delay */
36238 } else
36239diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
36240index be73e9d..7fbf140 100644
36241--- a/drivers/block/cpqarray.h
36242+++ b/drivers/block/cpqarray.h
36243@@ -99,7 +99,7 @@ struct ctlr_info {
36244 drv_info_t drv[NWD];
36245 struct proc_dir_entry *proc;
36246
36247- struct access_method access;
36248+ struct access_method *access;
36249
36250 cmdlist_t *reqQ;
36251 cmdlist_t *cmpQ;
36252diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
36253index 2d7f608..11245fe 100644
36254--- a/drivers/block/drbd/drbd_int.h
36255+++ b/drivers/block/drbd/drbd_int.h
36256@@ -582,7 +582,7 @@ struct drbd_epoch {
36257 struct drbd_tconn *tconn;
36258 struct list_head list;
36259 unsigned int barrier_nr;
36260- atomic_t epoch_size; /* increased on every request added. */
36261+ atomic_unchecked_t epoch_size; /* increased on every request added. */
36262 atomic_t active; /* increased on every req. added, and dec on every finished. */
36263 unsigned long flags;
36264 };
36265@@ -1022,7 +1022,7 @@ struct drbd_conf {
36266 unsigned int al_tr_number;
36267 int al_tr_cycle;
36268 wait_queue_head_t seq_wait;
36269- atomic_t packet_seq;
36270+ atomic_unchecked_t packet_seq;
36271 unsigned int peer_seq;
36272 spinlock_t peer_seq_lock;
36273 unsigned int minor;
36274@@ -1572,7 +1572,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
36275 char __user *uoptval;
36276 int err;
36277
36278- uoptval = (char __user __force *)optval;
36279+ uoptval = (char __force_user *)optval;
36280
36281 set_fs(KERNEL_DS);
36282 if (level == SOL_SOCKET)
36283diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
36284index 55635ed..40e837c 100644
36285--- a/drivers/block/drbd/drbd_main.c
36286+++ b/drivers/block/drbd/drbd_main.c
36287@@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
36288 p->sector = sector;
36289 p->block_id = block_id;
36290 p->blksize = blksize;
36291- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
36292+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
36293 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
36294 }
36295
36296@@ -1619,7 +1619,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
36297 return -EIO;
36298 p->sector = cpu_to_be64(req->i.sector);
36299 p->block_id = (unsigned long)req;
36300- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
36301+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
36302 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
36303 if (mdev->state.conn >= C_SYNC_SOURCE &&
36304 mdev->state.conn <= C_PAUSED_SYNC_T)
36305@@ -2574,8 +2574,8 @@ void conn_destroy(struct kref *kref)
36306 {
36307 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
36308
36309- if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
36310- conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
36311+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
36312+ conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
36313 kfree(tconn->current_epoch);
36314
36315 idr_destroy(&tconn->volumes);
36316diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
36317index 8cc1e64..ba7ffa9 100644
36318--- a/drivers/block/drbd/drbd_nl.c
36319+++ b/drivers/block/drbd/drbd_nl.c
36320@@ -3440,7 +3440,7 @@ out:
36321
36322 void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
36323 {
36324- static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
36325+ static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
36326 struct sk_buff *msg;
36327 struct drbd_genlmsghdr *d_out;
36328 unsigned seq;
36329@@ -3453,7 +3453,7 @@ void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
36330 return;
36331 }
36332
36333- seq = atomic_inc_return(&drbd_genl_seq);
36334+ seq = atomic_inc_return_unchecked(&drbd_genl_seq);
36335 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
36336 if (!msg)
36337 goto failed;
36338diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
36339index cc29cd3..d4b058b 100644
36340--- a/drivers/block/drbd/drbd_receiver.c
36341+++ b/drivers/block/drbd/drbd_receiver.c
36342@@ -834,7 +834,7 @@ int drbd_connected(struct drbd_conf *mdev)
36343 {
36344 int err;
36345
36346- atomic_set(&mdev->packet_seq, 0);
36347+ atomic_set_unchecked(&mdev->packet_seq, 0);
36348 mdev->peer_seq = 0;
36349
36350 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
36351@@ -1193,7 +1193,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
36352 do {
36353 next_epoch = NULL;
36354
36355- epoch_size = atomic_read(&epoch->epoch_size);
36356+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
36357
36358 switch (ev & ~EV_CLEANUP) {
36359 case EV_PUT:
36360@@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
36361 rv = FE_DESTROYED;
36362 } else {
36363 epoch->flags = 0;
36364- atomic_set(&epoch->epoch_size, 0);
36365+ atomic_set_unchecked(&epoch->epoch_size, 0);
36366 /* atomic_set(&epoch->active, 0); is already zero */
36367 if (rv == FE_STILL_LIVE)
36368 rv = FE_RECYCLED;
36369@@ -1451,7 +1451,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
36370 conn_wait_active_ee_empty(tconn);
36371 drbd_flush(tconn);
36372
36373- if (atomic_read(&tconn->current_epoch->epoch_size)) {
36374+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
36375 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
36376 if (epoch)
36377 break;
36378@@ -1464,11 +1464,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
36379 }
36380
36381 epoch->flags = 0;
36382- atomic_set(&epoch->epoch_size, 0);
36383+ atomic_set_unchecked(&epoch->epoch_size, 0);
36384 atomic_set(&epoch->active, 0);
36385
36386 spin_lock(&tconn->epoch_lock);
36387- if (atomic_read(&tconn->current_epoch->epoch_size)) {
36388+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
36389 list_add(&epoch->list, &tconn->current_epoch->list);
36390 tconn->current_epoch = epoch;
36391 tconn->epochs++;
36392@@ -2172,7 +2172,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
36393
36394 err = wait_for_and_update_peer_seq(mdev, peer_seq);
36395 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
36396- atomic_inc(&tconn->current_epoch->epoch_size);
36397+ atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
36398 err2 = drbd_drain_block(mdev, pi->size);
36399 if (!err)
36400 err = err2;
36401@@ -2206,7 +2206,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
36402
36403 spin_lock(&tconn->epoch_lock);
36404 peer_req->epoch = tconn->current_epoch;
36405- atomic_inc(&peer_req->epoch->epoch_size);
36406+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
36407 atomic_inc(&peer_req->epoch->active);
36408 spin_unlock(&tconn->epoch_lock);
36409
36410@@ -4347,7 +4347,7 @@ struct data_cmd {
36411 int expect_payload;
36412 size_t pkt_size;
36413 int (*fn)(struct drbd_tconn *, struct packet_info *);
36414-};
36415+} __do_const;
36416
36417 static struct data_cmd drbd_cmd_handler[] = {
36418 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
36419@@ -4467,7 +4467,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
36420 if (!list_empty(&tconn->current_epoch->list))
36421 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
36422 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
36423- atomic_set(&tconn->current_epoch->epoch_size, 0);
36424+ atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
36425 tconn->send.seen_any_write_yet = false;
36426
36427 conn_info(tconn, "Connection closed\n");
36428@@ -5223,7 +5223,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
36429 struct asender_cmd {
36430 size_t pkt_size;
36431 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
36432-};
36433+} __do_const;
36434
36435 static struct asender_cmd asender_tbl[] = {
36436 [P_PING] = { 0, got_Ping },
36437diff --git a/drivers/block/loop.c b/drivers/block/loop.c
36438index 40e7155..df5c79a 100644
36439--- a/drivers/block/loop.c
36440+++ b/drivers/block/loop.c
36441@@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
36442
36443 file_start_write(file);
36444 set_fs(get_ds());
36445- bw = file->f_op->write(file, buf, len, &pos);
36446+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
36447 set_fs(old_fs);
36448 file_end_write(file);
36449 if (likely(bw == len))
36450diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
36451index f5d0ea1..c62380a 100644
36452--- a/drivers/block/pktcdvd.c
36453+++ b/drivers/block/pktcdvd.c
36454@@ -84,7 +84,7 @@
36455 #define MAX_SPEED 0xffff
36456
36457 #define ZONE(sector, pd) (((sector) + (pd)->offset) & \
36458- ~(sector_t)((pd)->settings.size - 1))
36459+ ~(sector_t)((pd)->settings.size - 1UL))
36460
36461 static DEFINE_MUTEX(pktcdvd_mutex);
36462 static struct pktcdvd_device *pkt_devs[MAX_WRITERS];
36463diff --git a/drivers/bus/arm-cci.c b/drivers/bus/arm-cci.c
36464index 7332889..9ece19e 100644
36465--- a/drivers/bus/arm-cci.c
36466+++ b/drivers/bus/arm-cci.c
36467@@ -419,7 +419,7 @@ static int __init cci_probe(void)
36468
36469 nb_cci_ports = cci_config->nb_ace + cci_config->nb_ace_lite;
36470
36471- ports = kcalloc(sizeof(*ports), nb_cci_ports, GFP_KERNEL);
36472+ ports = kcalloc(nb_cci_ports, sizeof(*ports), GFP_KERNEL);
36473 if (!ports)
36474 return -ENOMEM;
36475
36476diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
36477index 8a3aff7..d7538c2 100644
36478--- a/drivers/cdrom/cdrom.c
36479+++ b/drivers/cdrom/cdrom.c
36480@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
36481 ENSURE(reset, CDC_RESET);
36482 ENSURE(generic_packet, CDC_GENERIC_PACKET);
36483 cdi->mc_flags = 0;
36484- cdo->n_minors = 0;
36485 cdi->options = CDO_USE_FFLAGS;
36486
36487 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
36488@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
36489 else
36490 cdi->cdda_method = CDDA_OLD;
36491
36492- if (!cdo->generic_packet)
36493- cdo->generic_packet = cdrom_dummy_generic_packet;
36494+ if (!cdo->generic_packet) {
36495+ pax_open_kernel();
36496+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
36497+ pax_close_kernel();
36498+ }
36499
36500 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
36501 mutex_lock(&cdrom_mutex);
36502@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
36503 if (cdi->exit)
36504 cdi->exit(cdi);
36505
36506- cdi->ops->n_minors--;
36507 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
36508 }
36509
36510@@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
36511 */
36512 nr = nframes;
36513 do {
36514- cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
36515+ cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
36516 if (cgc.buffer)
36517 break;
36518
36519@@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
36520 struct cdrom_device_info *cdi;
36521 int ret;
36522
36523- ret = scnprintf(info + *pos, max_size - *pos, header);
36524+ ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
36525 if (!ret)
36526 return 1;
36527
36528diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
36529index 5980cb9..6d7bd7e 100644
36530--- a/drivers/cdrom/gdrom.c
36531+++ b/drivers/cdrom/gdrom.c
36532@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
36533 .audio_ioctl = gdrom_audio_ioctl,
36534 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
36535 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
36536- .n_minors = 1,
36537 };
36538
36539 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
36540diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
36541index 1421997..33f5d6d 100644
36542--- a/drivers/char/Kconfig
36543+++ b/drivers/char/Kconfig
36544@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
36545
36546 config DEVKMEM
36547 bool "/dev/kmem virtual device support"
36548- default y
36549+ default n
36550+ depends on !GRKERNSEC_KMEM
36551 help
36552 Say Y here if you want to support the /dev/kmem device. The
36553 /dev/kmem device is rarely used, but can be used for certain
36554@@ -570,6 +571,7 @@ config DEVPORT
36555 bool
36556 depends on !M68K
36557 depends on ISA || PCI
36558+ depends on !GRKERNSEC_KMEM
36559 default y
36560
36561 source "drivers/s390/char/Kconfig"
36562diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
36563index a48e05b..6bac831 100644
36564--- a/drivers/char/agp/compat_ioctl.c
36565+++ b/drivers/char/agp/compat_ioctl.c
36566@@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
36567 return -ENOMEM;
36568 }
36569
36570- if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
36571+ if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
36572 sizeof(*usegment) * ureserve.seg_count)) {
36573 kfree(usegment);
36574 kfree(ksegment);
36575diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
36576index 1b19239..b87b143 100644
36577--- a/drivers/char/agp/frontend.c
36578+++ b/drivers/char/agp/frontend.c
36579@@ -819,7 +819,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
36580 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
36581 return -EFAULT;
36582
36583- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
36584+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
36585 return -EFAULT;
36586
36587 client = agp_find_client_by_pid(reserve.pid);
36588@@ -849,7 +849,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
36589 if (segment == NULL)
36590 return -ENOMEM;
36591
36592- if (copy_from_user(segment, (void __user *) reserve.seg_list,
36593+ if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
36594 sizeof(struct agp_segment) * reserve.seg_count)) {
36595 kfree(segment);
36596 return -EFAULT;
36597diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
36598index 4f94375..413694e 100644
36599--- a/drivers/char/genrtc.c
36600+++ b/drivers/char/genrtc.c
36601@@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
36602 switch (cmd) {
36603
36604 case RTC_PLL_GET:
36605+ memset(&pll, 0, sizeof(pll));
36606 if (get_rtc_pll(&pll))
36607 return -EINVAL;
36608 else
36609diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
36610index 448ce5e..3a76625 100644
36611--- a/drivers/char/hpet.c
36612+++ b/drivers/char/hpet.c
36613@@ -559,7 +559,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
36614 }
36615
36616 static int
36617-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
36618+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
36619 struct hpet_info *info)
36620 {
36621 struct hpet_timer __iomem *timer;
36622diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
36623index 86fe45c..c0ea948 100644
36624--- a/drivers/char/hw_random/intel-rng.c
36625+++ b/drivers/char/hw_random/intel-rng.c
36626@@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
36627
36628 if (no_fwh_detect)
36629 return -ENODEV;
36630- printk(warning);
36631+ printk("%s", warning);
36632 return -EBUSY;
36633 }
36634
36635diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
36636index 4445fa1..7c6de37 100644
36637--- a/drivers/char/ipmi/ipmi_msghandler.c
36638+++ b/drivers/char/ipmi/ipmi_msghandler.c
36639@@ -420,7 +420,7 @@ struct ipmi_smi {
36640 struct proc_dir_entry *proc_dir;
36641 char proc_dir_name[10];
36642
36643- atomic_t stats[IPMI_NUM_STATS];
36644+ atomic_unchecked_t stats[IPMI_NUM_STATS];
36645
36646 /*
36647 * run_to_completion duplicate of smb_info, smi_info
36648@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
36649
36650
36651 #define ipmi_inc_stat(intf, stat) \
36652- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
36653+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
36654 #define ipmi_get_stat(intf, stat) \
36655- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
36656+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
36657
36658 static int is_lan_addr(struct ipmi_addr *addr)
36659 {
36660@@ -2883,7 +2883,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
36661 INIT_LIST_HEAD(&intf->cmd_rcvrs);
36662 init_waitqueue_head(&intf->waitq);
36663 for (i = 0; i < IPMI_NUM_STATS; i++)
36664- atomic_set(&intf->stats[i], 0);
36665+ atomic_set_unchecked(&intf->stats[i], 0);
36666
36667 intf->proc_dir = NULL;
36668
36669diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
36670index af4b23f..79806fc 100644
36671--- a/drivers/char/ipmi/ipmi_si_intf.c
36672+++ b/drivers/char/ipmi/ipmi_si_intf.c
36673@@ -275,7 +275,7 @@ struct smi_info {
36674 unsigned char slave_addr;
36675
36676 /* Counters and things for the proc filesystem. */
36677- atomic_t stats[SI_NUM_STATS];
36678+ atomic_unchecked_t stats[SI_NUM_STATS];
36679
36680 struct task_struct *thread;
36681
36682@@ -284,9 +284,9 @@ struct smi_info {
36683 };
36684
36685 #define smi_inc_stat(smi, stat) \
36686- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
36687+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
36688 #define smi_get_stat(smi, stat) \
36689- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
36690+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
36691
36692 #define SI_MAX_PARMS 4
36693
36694@@ -3258,7 +3258,7 @@ static int try_smi_init(struct smi_info *new_smi)
36695 atomic_set(&new_smi->req_events, 0);
36696 new_smi->run_to_completion = 0;
36697 for (i = 0; i < SI_NUM_STATS; i++)
36698- atomic_set(&new_smi->stats[i], 0);
36699+ atomic_set_unchecked(&new_smi->stats[i], 0);
36700
36701 new_smi->interrupt_disabled = 1;
36702 atomic_set(&new_smi->stop_operation, 0);
36703diff --git a/drivers/char/mem.c b/drivers/char/mem.c
36704index f895a8c..2bc9147 100644
36705--- a/drivers/char/mem.c
36706+++ b/drivers/char/mem.c
36707@@ -18,6 +18,7 @@
36708 #include <linux/raw.h>
36709 #include <linux/tty.h>
36710 #include <linux/capability.h>
36711+#include <linux/security.h>
36712 #include <linux/ptrace.h>
36713 #include <linux/device.h>
36714 #include <linux/highmem.h>
36715@@ -37,6 +38,10 @@
36716
36717 #define DEVPORT_MINOR 4
36718
36719+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
36720+extern const struct file_operations grsec_fops;
36721+#endif
36722+
36723 static inline unsigned long size_inside_page(unsigned long start,
36724 unsigned long size)
36725 {
36726@@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
36727
36728 while (cursor < to) {
36729 if (!devmem_is_allowed(pfn)) {
36730+#ifdef CONFIG_GRKERNSEC_KMEM
36731+ gr_handle_mem_readwrite(from, to);
36732+#else
36733 printk(KERN_INFO
36734 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
36735 current->comm, from, to);
36736+#endif
36737 return 0;
36738 }
36739 cursor += PAGE_SIZE;
36740@@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
36741 }
36742 return 1;
36743 }
36744+#elif defined(CONFIG_GRKERNSEC_KMEM)
36745+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
36746+{
36747+ return 0;
36748+}
36749 #else
36750 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
36751 {
36752@@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
36753
36754 while (count > 0) {
36755 unsigned long remaining;
36756+ char *temp;
36757
36758 sz = size_inside_page(p, count);
36759
36760@@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
36761 if (!ptr)
36762 return -EFAULT;
36763
36764- remaining = copy_to_user(buf, ptr, sz);
36765+#ifdef CONFIG_PAX_USERCOPY
36766+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
36767+ if (!temp) {
36768+ unxlate_dev_mem_ptr(p, ptr);
36769+ return -ENOMEM;
36770+ }
36771+ memcpy(temp, ptr, sz);
36772+#else
36773+ temp = ptr;
36774+#endif
36775+
36776+ remaining = copy_to_user(buf, temp, sz);
36777+
36778+#ifdef CONFIG_PAX_USERCOPY
36779+ kfree(temp);
36780+#endif
36781+
36782 unxlate_dev_mem_ptr(p, ptr);
36783 if (remaining)
36784 return -EFAULT;
36785@@ -364,9 +395,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
36786 size_t count, loff_t *ppos)
36787 {
36788 unsigned long p = *ppos;
36789- ssize_t low_count, read, sz;
36790+ ssize_t low_count, read, sz, err = 0;
36791 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
36792- int err = 0;
36793
36794 read = 0;
36795 if (p < (unsigned long) high_memory) {
36796@@ -388,6 +418,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
36797 }
36798 #endif
36799 while (low_count > 0) {
36800+ char *temp;
36801+
36802 sz = size_inside_page(p, low_count);
36803
36804 /*
36805@@ -397,7 +429,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
36806 */
36807 kbuf = xlate_dev_kmem_ptr((char *)p);
36808
36809- if (copy_to_user(buf, kbuf, sz))
36810+#ifdef CONFIG_PAX_USERCOPY
36811+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
36812+ if (!temp)
36813+ return -ENOMEM;
36814+ memcpy(temp, kbuf, sz);
36815+#else
36816+ temp = kbuf;
36817+#endif
36818+
36819+ err = copy_to_user(buf, temp, sz);
36820+
36821+#ifdef CONFIG_PAX_USERCOPY
36822+ kfree(temp);
36823+#endif
36824+
36825+ if (err)
36826 return -EFAULT;
36827 buf += sz;
36828 p += sz;
36829@@ -822,6 +869,9 @@ static const struct memdev {
36830 #ifdef CONFIG_PRINTK
36831 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
36832 #endif
36833+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
36834+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
36835+#endif
36836 };
36837
36838 static int memory_open(struct inode *inode, struct file *filp)
36839@@ -893,7 +943,7 @@ static int __init chr_dev_init(void)
36840 continue;
36841
36842 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
36843- NULL, devlist[minor].name);
36844+ NULL, "%s", devlist[minor].name);
36845 }
36846
36847 return tty_init();
36848diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
36849index 9df78e2..01ba9ae 100644
36850--- a/drivers/char/nvram.c
36851+++ b/drivers/char/nvram.c
36852@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
36853
36854 spin_unlock_irq(&rtc_lock);
36855
36856- if (copy_to_user(buf, contents, tmp - contents))
36857+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
36858 return -EFAULT;
36859
36860 *ppos = i;
36861diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
36862index 5c5cc00..ac9edb7 100644
36863--- a/drivers/char/pcmcia/synclink_cs.c
36864+++ b/drivers/char/pcmcia/synclink_cs.c
36865@@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
36866
36867 if (debug_level >= DEBUG_LEVEL_INFO)
36868 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
36869- __FILE__, __LINE__, info->device_name, port->count);
36870+ __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
36871
36872- WARN_ON(!port->count);
36873+ WARN_ON(!atomic_read(&port->count));
36874
36875 if (tty_port_close_start(port, tty, filp) == 0)
36876 goto cleanup;
36877@@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
36878 cleanup:
36879 if (debug_level >= DEBUG_LEVEL_INFO)
36880 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
36881- tty->driver->name, port->count);
36882+ tty->driver->name, atomic_read(&port->count));
36883 }
36884
36885 /* Wait until the transmitter is empty.
36886@@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
36887
36888 if (debug_level >= DEBUG_LEVEL_INFO)
36889 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
36890- __FILE__, __LINE__, tty->driver->name, port->count);
36891+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
36892
36893 /* If port is closing, signal caller to try again */
36894 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
36895@@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
36896 goto cleanup;
36897 }
36898 spin_lock(&port->lock);
36899- port->count++;
36900+ atomic_inc(&port->count);
36901 spin_unlock(&port->lock);
36902 spin_unlock_irqrestore(&info->netlock, flags);
36903
36904- if (port->count == 1) {
36905+ if (atomic_read(&port->count) == 1) {
36906 /* 1st open on this device, init hardware */
36907 retval = startup(info, tty);
36908 if (retval < 0)
36909@@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
36910 unsigned short new_crctype;
36911
36912 /* return error if TTY interface open */
36913- if (info->port.count)
36914+ if (atomic_read(&info->port.count))
36915 return -EBUSY;
36916
36917 switch (encoding)
36918@@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
36919
36920 /* arbitrate between network and tty opens */
36921 spin_lock_irqsave(&info->netlock, flags);
36922- if (info->port.count != 0 || info->netcount != 0) {
36923+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
36924 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
36925 spin_unlock_irqrestore(&info->netlock, flags);
36926 return -EBUSY;
36927@@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
36928 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
36929
36930 /* return error if TTY interface open */
36931- if (info->port.count)
36932+ if (atomic_read(&info->port.count))
36933 return -EBUSY;
36934
36935 if (cmd != SIOCWANDEV)
36936diff --git a/drivers/char/random.c b/drivers/char/random.c
36937index 0d91fe5..f8e37b0 100644
36938--- a/drivers/char/random.c
36939+++ b/drivers/char/random.c
36940@@ -272,8 +272,13 @@
36941 /*
36942 * Configuration information
36943 */
36944+#ifdef CONFIG_GRKERNSEC_RANDNET
36945+#define INPUT_POOL_WORDS 512
36946+#define OUTPUT_POOL_WORDS 128
36947+#else
36948 #define INPUT_POOL_WORDS 128
36949 #define OUTPUT_POOL_WORDS 32
36950+#endif
36951 #define SEC_XFER_SIZE 512
36952 #define EXTRACT_SIZE 10
36953
36954@@ -313,10 +318,17 @@ static struct poolinfo {
36955 int poolwords;
36956 int tap1, tap2, tap3, tap4, tap5;
36957 } poolinfo_table[] = {
36958+#ifdef CONFIG_GRKERNSEC_RANDNET
36959+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
36960+ { 512, 411, 308, 208, 104, 1 },
36961+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
36962+ { 128, 103, 76, 51, 25, 1 },
36963+#else
36964 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
36965 { 128, 103, 76, 51, 25, 1 },
36966 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
36967 { 32, 26, 20, 14, 7, 1 },
36968+#endif
36969 #if 0
36970 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
36971 { 2048, 1638, 1231, 819, 411, 1 },
36972@@ -524,8 +536,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
36973 input_rotate += i ? 7 : 14;
36974 }
36975
36976- ACCESS_ONCE(r->input_rotate) = input_rotate;
36977- ACCESS_ONCE(r->add_ptr) = i;
36978+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
36979+ ACCESS_ONCE_RW(r->add_ptr) = i;
36980 smp_wmb();
36981
36982 if (out)
36983@@ -1032,7 +1044,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
36984
36985 extract_buf(r, tmp);
36986 i = min_t(int, nbytes, EXTRACT_SIZE);
36987- if (copy_to_user(buf, tmp, i)) {
36988+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
36989 ret = -EFAULT;
36990 break;
36991 }
36992@@ -1368,7 +1380,7 @@ EXPORT_SYMBOL(generate_random_uuid);
36993 #include <linux/sysctl.h>
36994
36995 static int min_read_thresh = 8, min_write_thresh;
36996-static int max_read_thresh = INPUT_POOL_WORDS * 32;
36997+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
36998 static int max_write_thresh = INPUT_POOL_WORDS * 32;
36999 static char sysctl_bootid[16];
37000
37001@@ -1384,7 +1396,7 @@ static char sysctl_bootid[16];
37002 static int proc_do_uuid(struct ctl_table *table, int write,
37003 void __user *buffer, size_t *lenp, loff_t *ppos)
37004 {
37005- struct ctl_table fake_table;
37006+ ctl_table_no_const fake_table;
37007 unsigned char buf[64], tmp_uuid[16], *uuid;
37008
37009 uuid = table->data;
37010diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
37011index bf2349db..5456d53 100644
37012--- a/drivers/char/sonypi.c
37013+++ b/drivers/char/sonypi.c
37014@@ -54,6 +54,7 @@
37015
37016 #include <asm/uaccess.h>
37017 #include <asm/io.h>
37018+#include <asm/local.h>
37019
37020 #include <linux/sonypi.h>
37021
37022@@ -490,7 +491,7 @@ static struct sonypi_device {
37023 spinlock_t fifo_lock;
37024 wait_queue_head_t fifo_proc_list;
37025 struct fasync_struct *fifo_async;
37026- int open_count;
37027+ local_t open_count;
37028 int model;
37029 struct input_dev *input_jog_dev;
37030 struct input_dev *input_key_dev;
37031@@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
37032 static int sonypi_misc_release(struct inode *inode, struct file *file)
37033 {
37034 mutex_lock(&sonypi_device.lock);
37035- sonypi_device.open_count--;
37036+ local_dec(&sonypi_device.open_count);
37037 mutex_unlock(&sonypi_device.lock);
37038 return 0;
37039 }
37040@@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
37041 {
37042 mutex_lock(&sonypi_device.lock);
37043 /* Flush input queue on first open */
37044- if (!sonypi_device.open_count)
37045+ if (!local_read(&sonypi_device.open_count))
37046 kfifo_reset(&sonypi_device.fifo);
37047- sonypi_device.open_count++;
37048+ local_inc(&sonypi_device.open_count);
37049 mutex_unlock(&sonypi_device.lock);
37050
37051 return 0;
37052diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
37053index 64420b3..5c40b56 100644
37054--- a/drivers/char/tpm/tpm_acpi.c
37055+++ b/drivers/char/tpm/tpm_acpi.c
37056@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
37057 virt = acpi_os_map_memory(start, len);
37058 if (!virt) {
37059 kfree(log->bios_event_log);
37060+ log->bios_event_log = NULL;
37061 printk("%s: ERROR - Unable to map memory\n", __func__);
37062 return -EIO;
37063 }
37064
37065- memcpy_fromio(log->bios_event_log, virt, len);
37066+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
37067
37068 acpi_os_unmap_memory(virt, len);
37069 return 0;
37070diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
37071index 84ddc55..1d32f1e 100644
37072--- a/drivers/char/tpm/tpm_eventlog.c
37073+++ b/drivers/char/tpm/tpm_eventlog.c
37074@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
37075 event = addr;
37076
37077 if ((event->event_type == 0 && event->event_size == 0) ||
37078- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
37079+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
37080 return NULL;
37081
37082 return addr;
37083@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
37084 return NULL;
37085
37086 if ((event->event_type == 0 && event->event_size == 0) ||
37087- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
37088+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
37089 return NULL;
37090
37091 (*pos)++;
37092@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
37093 int i;
37094
37095 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
37096- seq_putc(m, data[i]);
37097+ if (!seq_putc(m, data[i]))
37098+ return -EFAULT;
37099
37100 return 0;
37101 }
37102diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
37103index fc45567..fa2a590 100644
37104--- a/drivers/char/virtio_console.c
37105+++ b/drivers/char/virtio_console.c
37106@@ -682,7 +682,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
37107 if (to_user) {
37108 ssize_t ret;
37109
37110- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
37111+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
37112 if (ret)
37113 return -EFAULT;
37114 } else {
37115@@ -785,7 +785,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
37116 if (!port_has_data(port) && !port->host_connected)
37117 return 0;
37118
37119- return fill_readbuf(port, ubuf, count, true);
37120+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
37121 }
37122
37123 static int wait_port_writable(struct port *port, bool nonblock)
37124diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
37125index a33f46f..a720eed 100644
37126--- a/drivers/clk/clk-composite.c
37127+++ b/drivers/clk/clk-composite.c
37128@@ -122,7 +122,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
37129 struct clk *clk;
37130 struct clk_init_data init;
37131 struct clk_composite *composite;
37132- struct clk_ops *clk_composite_ops;
37133+ clk_ops_no_const *clk_composite_ops;
37134
37135 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
37136 if (!composite) {
37137diff --git a/drivers/clk/socfpga/clk.c b/drivers/clk/socfpga/clk.c
37138index 5bb848c..f1d4fc9 100644
37139--- a/drivers/clk/socfpga/clk.c
37140+++ b/drivers/clk/socfpga/clk.c
37141@@ -22,6 +22,7 @@
37142 #include <linux/clk-provider.h>
37143 #include <linux/io.h>
37144 #include <linux/of.h>
37145+#include <asm/pgtable.h>
37146
37147 /* Clock Manager offsets */
37148 #define CLKMGR_CTRL 0x0
37149@@ -152,8 +153,10 @@ static __init struct clk *socfpga_clk_init(struct device_node *node,
37150 streq(clk_name, "periph_pll") ||
37151 streq(clk_name, "sdram_pll")) {
37152 socfpga_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
37153- clk_pll_ops.enable = clk_gate_ops.enable;
37154- clk_pll_ops.disable = clk_gate_ops.disable;
37155+ pax_open_kernel();
37156+ *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
37157+ *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
37158+ pax_close_kernel();
37159 }
37160
37161 clk = clk_register(NULL, &socfpga_clk->hw.hw);
37162@@ -244,7 +247,7 @@ static unsigned long socfpga_clk_recalc_rate(struct clk_hw *hwclk,
37163 return parent_rate / div;
37164 }
37165
37166-static struct clk_ops gateclk_ops = {
37167+static clk_ops_no_const gateclk_ops __read_only = {
37168 .recalc_rate = socfpga_clk_recalc_rate,
37169 .get_parent = socfpga_clk_get_parent,
37170 .set_parent = socfpga_clk_set_parent,
37171diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
37172index 3926402..37b580d 100644
37173--- a/drivers/cpufreq/acpi-cpufreq.c
37174+++ b/drivers/cpufreq/acpi-cpufreq.c
37175@@ -173,7 +173,7 @@ static ssize_t show_global_boost(struct kobject *kobj,
37176 return sprintf(buf, "%u\n", boost_enabled);
37177 }
37178
37179-static struct global_attr global_boost = __ATTR(boost, 0644,
37180+static global_attr_no_const global_boost = __ATTR(boost, 0644,
37181 show_global_boost,
37182 store_global_boost);
37183
37184@@ -722,8 +722,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
37185 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
37186 per_cpu(acfreq_data, cpu) = data;
37187
37188- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
37189- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
37190+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
37191+ pax_open_kernel();
37192+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
37193+ pax_close_kernel();
37194+ }
37195
37196 result = acpi_processor_register_performance(data->acpi_data, cpu);
37197 if (result)
37198@@ -851,7 +854,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
37199 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
37200 break;
37201 case ACPI_ADR_SPACE_FIXED_HARDWARE:
37202- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
37203+ pax_open_kernel();
37204+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
37205+ pax_close_kernel();
37206 policy->cur = get_cur_freq_on_cpu(cpu);
37207 break;
37208 default:
37209@@ -862,8 +867,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
37210 acpi_processor_notify_smm(THIS_MODULE);
37211
37212 /* Check for APERF/MPERF support in hardware */
37213- if (boot_cpu_has(X86_FEATURE_APERFMPERF))
37214- acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
37215+ if (boot_cpu_has(X86_FEATURE_APERFMPERF)) {
37216+ pax_open_kernel();
37217+ *(void **)&acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
37218+ pax_close_kernel();
37219+ }
37220
37221 pr_debug("CPU%u - ACPI performance management activated.\n", cpu);
37222 for (i = 0; i < perf->state_count; i++)
37223diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
37224index f0a5e2b..0a7ee46 100644
37225--- a/drivers/cpufreq/cpufreq.c
37226+++ b/drivers/cpufreq/cpufreq.c
37227@@ -1959,7 +1959,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
37228 return NOTIFY_OK;
37229 }
37230
37231-static struct notifier_block __refdata cpufreq_cpu_notifier = {
37232+static struct notifier_block cpufreq_cpu_notifier = {
37233 .notifier_call = cpufreq_cpu_callback,
37234 };
37235
37236@@ -1991,8 +1991,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
37237
37238 pr_debug("trying to register driver %s\n", driver_data->name);
37239
37240- if (driver_data->setpolicy)
37241- driver_data->flags |= CPUFREQ_CONST_LOOPS;
37242+ if (driver_data->setpolicy) {
37243+ pax_open_kernel();
37244+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
37245+ pax_close_kernel();
37246+ }
37247
37248 write_lock_irqsave(&cpufreq_driver_lock, flags);
37249 if (cpufreq_driver) {
37250diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
37251index e59afaa..a53a3ff 100644
37252--- a/drivers/cpufreq/cpufreq_governor.c
37253+++ b/drivers/cpufreq/cpufreq_governor.c
37254@@ -191,7 +191,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
37255 struct dbs_data *dbs_data;
37256 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
37257 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
37258- struct od_ops *od_ops = NULL;
37259+ const struct od_ops *od_ops = NULL;
37260 struct od_dbs_tuners *od_tuners = NULL;
37261 struct cs_dbs_tuners *cs_tuners = NULL;
37262 struct cpu_dbs_common_info *cpu_cdbs;
37263@@ -257,7 +257,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
37264
37265 if ((cdata->governor == GOV_CONSERVATIVE) &&
37266 (!policy->governor->initialized)) {
37267- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37268+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37269
37270 cpufreq_register_notifier(cs_ops->notifier_block,
37271 CPUFREQ_TRANSITION_NOTIFIER);
37272@@ -277,7 +277,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
37273
37274 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
37275 (policy->governor->initialized == 1)) {
37276- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37277+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
37278
37279 cpufreq_unregister_notifier(cs_ops->notifier_block,
37280 CPUFREQ_TRANSITION_NOTIFIER);
37281diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
37282index d5f12b4..eb30af1 100644
37283--- a/drivers/cpufreq/cpufreq_governor.h
37284+++ b/drivers/cpufreq/cpufreq_governor.h
37285@@ -204,7 +204,7 @@ struct common_dbs_data {
37286 void (*exit)(struct dbs_data *dbs_data);
37287
37288 /* Governor specific ops, see below */
37289- void *gov_ops;
37290+ const void *gov_ops;
37291 };
37292
37293 /* Governer Per policy data */
37294@@ -224,7 +224,7 @@ struct od_ops {
37295 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
37296 unsigned int freq_next, unsigned int relation);
37297 void (*freq_increase)(struct cpufreq_policy *p, unsigned int freq);
37298-};
37299+} __no_const;
37300
37301 struct cs_ops {
37302 struct notifier_block *notifier_block;
37303diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
37304index c087347..989aa2e 100644
37305--- a/drivers/cpufreq/cpufreq_ondemand.c
37306+++ b/drivers/cpufreq/cpufreq_ondemand.c
37307@@ -560,7 +560,7 @@ static void od_exit(struct dbs_data *dbs_data)
37308
37309 define_get_cpu_dbs_routines(od_cpu_dbs_info);
37310
37311-static struct od_ops od_ops = {
37312+static struct od_ops od_ops __read_only = {
37313 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
37314 .powersave_bias_target = generic_powersave_bias_target,
37315 .freq_increase = dbs_freq_increase,
37316@@ -615,14 +615,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
37317 (struct cpufreq_policy *, unsigned int, unsigned int),
37318 unsigned int powersave_bias)
37319 {
37320- od_ops.powersave_bias_target = f;
37321+ pax_open_kernel();
37322+ *(void **)&od_ops.powersave_bias_target = f;
37323+ pax_close_kernel();
37324 od_set_powersave_bias(powersave_bias);
37325 }
37326 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
37327
37328 void od_unregister_powersave_bias_handler(void)
37329 {
37330- od_ops.powersave_bias_target = generic_powersave_bias_target;
37331+ pax_open_kernel();
37332+ *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
37333+ pax_close_kernel();
37334 od_set_powersave_bias(0);
37335 }
37336 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
37337diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
37338index d37568c..fbb19a1 100644
37339--- a/drivers/cpufreq/cpufreq_stats.c
37340+++ b/drivers/cpufreq/cpufreq_stats.c
37341@@ -365,7 +365,7 @@ static int cpufreq_stat_cpu_callback(struct notifier_block *nfb,
37342 }
37343
37344 /* priority=1 so this will get called before cpufreq_remove_dev */
37345-static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
37346+static struct notifier_block cpufreq_stat_cpu_notifier = {
37347 .notifier_call = cpufreq_stat_cpu_callback,
37348 .priority = 1,
37349 };
37350diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
37351index 9ee7817..17b658e 100644
37352--- a/drivers/cpufreq/p4-clockmod.c
37353+++ b/drivers/cpufreq/p4-clockmod.c
37354@@ -160,10 +160,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
37355 case 0x0F: /* Core Duo */
37356 case 0x16: /* Celeron Core */
37357 case 0x1C: /* Atom */
37358- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37359+ pax_open_kernel();
37360+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37361+ pax_close_kernel();
37362 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
37363 case 0x0D: /* Pentium M (Dothan) */
37364- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37365+ pax_open_kernel();
37366+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37367+ pax_close_kernel();
37368 /* fall through */
37369 case 0x09: /* Pentium M (Banias) */
37370 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
37371@@ -175,7 +179,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
37372
37373 /* on P-4s, the TSC runs with constant frequency independent whether
37374 * throttling is active or not. */
37375- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37376+ pax_open_kernel();
37377+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
37378+ pax_close_kernel();
37379
37380 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
37381 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
37382diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
37383index 880ee29..2445bc6 100644
37384--- a/drivers/cpufreq/sparc-us3-cpufreq.c
37385+++ b/drivers/cpufreq/sparc-us3-cpufreq.c
37386@@ -18,14 +18,12 @@
37387 #include <asm/head.h>
37388 #include <asm/timer.h>
37389
37390-static struct cpufreq_driver *cpufreq_us3_driver;
37391-
37392 struct us3_freq_percpu_info {
37393 struct cpufreq_frequency_table table[4];
37394 };
37395
37396 /* Indexed by cpu number. */
37397-static struct us3_freq_percpu_info *us3_freq_table;
37398+static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
37399
37400 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
37401 * in the Safari config register.
37402@@ -186,12 +184,25 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
37403
37404 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
37405 {
37406- if (cpufreq_us3_driver)
37407- us3_set_cpu_divider_index(policy, 0);
37408+ us3_set_cpu_divider_index(policy->cpu, 0);
37409
37410 return 0;
37411 }
37412
37413+static int __init us3_freq_init(void);
37414+static void __exit us3_freq_exit(void);
37415+
37416+static struct cpufreq_driver cpufreq_us3_driver = {
37417+ .init = us3_freq_cpu_init,
37418+ .verify = us3_freq_verify,
37419+ .target = us3_freq_target,
37420+ .get = us3_freq_get,
37421+ .exit = us3_freq_cpu_exit,
37422+ .owner = THIS_MODULE,
37423+ .name = "UltraSPARC-III",
37424+
37425+};
37426+
37427 static int __init us3_freq_init(void)
37428 {
37429 unsigned long manuf, impl, ver;
37430@@ -208,57 +219,15 @@ static int __init us3_freq_init(void)
37431 (impl == CHEETAH_IMPL ||
37432 impl == CHEETAH_PLUS_IMPL ||
37433 impl == JAGUAR_IMPL ||
37434- impl == PANTHER_IMPL)) {
37435- struct cpufreq_driver *driver;
37436-
37437- ret = -ENOMEM;
37438- driver = kzalloc(sizeof(struct cpufreq_driver), GFP_KERNEL);
37439- if (!driver)
37440- goto err_out;
37441-
37442- us3_freq_table = kzalloc(
37443- (NR_CPUS * sizeof(struct us3_freq_percpu_info)),
37444- GFP_KERNEL);
37445- if (!us3_freq_table)
37446- goto err_out;
37447-
37448- driver->init = us3_freq_cpu_init;
37449- driver->verify = us3_freq_verify;
37450- driver->target = us3_freq_target;
37451- driver->get = us3_freq_get;
37452- driver->exit = us3_freq_cpu_exit;
37453- driver->owner = THIS_MODULE,
37454- strcpy(driver->name, "UltraSPARC-III");
37455-
37456- cpufreq_us3_driver = driver;
37457- ret = cpufreq_register_driver(driver);
37458- if (ret)
37459- goto err_out;
37460-
37461- return 0;
37462-
37463-err_out:
37464- if (driver) {
37465- kfree(driver);
37466- cpufreq_us3_driver = NULL;
37467- }
37468- kfree(us3_freq_table);
37469- us3_freq_table = NULL;
37470- return ret;
37471- }
37472+ impl == PANTHER_IMPL))
37473+ return cpufreq_register_driver(&cpufreq_us3_driver);
37474
37475 return -ENODEV;
37476 }
37477
37478 static void __exit us3_freq_exit(void)
37479 {
37480- if (cpufreq_us3_driver) {
37481- cpufreq_unregister_driver(cpufreq_us3_driver);
37482- kfree(cpufreq_us3_driver);
37483- cpufreq_us3_driver = NULL;
37484- kfree(us3_freq_table);
37485- us3_freq_table = NULL;
37486- }
37487+ cpufreq_unregister_driver(&cpufreq_us3_driver);
37488 }
37489
37490 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
37491diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
37492index 0915e71..53376ed 100644
37493--- a/drivers/cpufreq/speedstep-centrino.c
37494+++ b/drivers/cpufreq/speedstep-centrino.c
37495@@ -353,8 +353,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
37496 !cpu_has(cpu, X86_FEATURE_EST))
37497 return -ENODEV;
37498
37499- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
37500- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
37501+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
37502+ pax_open_kernel();
37503+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
37504+ pax_close_kernel();
37505+ }
37506
37507 if (policy->cpu != 0)
37508 return -ENODEV;
37509diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
37510index fdc432f..98e64e2 100644
37511--- a/drivers/cpuidle/cpuidle.c
37512+++ b/drivers/cpuidle/cpuidle.c
37513@@ -254,7 +254,7 @@ static int poll_idle(struct cpuidle_device *dev,
37514
37515 static void poll_idle_init(struct cpuidle_driver *drv)
37516 {
37517- struct cpuidle_state *state = &drv->states[0];
37518+ cpuidle_state_no_const *state = &drv->states[0];
37519
37520 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
37521 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
37522diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
37523index ea2f8e7..70ac501 100644
37524--- a/drivers/cpuidle/governor.c
37525+++ b/drivers/cpuidle/governor.c
37526@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
37527 mutex_lock(&cpuidle_lock);
37528 if (__cpuidle_find_governor(gov->name) == NULL) {
37529 ret = 0;
37530- list_add_tail(&gov->governor_list, &cpuidle_governors);
37531+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
37532 if (!cpuidle_curr_governor ||
37533 cpuidle_curr_governor->rating < gov->rating)
37534 cpuidle_switch_governor(gov);
37535@@ -135,7 +135,7 @@ void cpuidle_unregister_governor(struct cpuidle_governor *gov)
37536 new_gov = cpuidle_replace_governor(gov->rating);
37537 cpuidle_switch_governor(new_gov);
37538 }
37539- list_del(&gov->governor_list);
37540+ pax_list_del((struct list_head *)&gov->governor_list);
37541 mutex_unlock(&cpuidle_lock);
37542 }
37543
37544diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
37545index 428754a..8bdf9cc 100644
37546--- a/drivers/cpuidle/sysfs.c
37547+++ b/drivers/cpuidle/sysfs.c
37548@@ -131,7 +131,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
37549 NULL
37550 };
37551
37552-static struct attribute_group cpuidle_attr_group = {
37553+static attribute_group_no_const cpuidle_attr_group = {
37554 .attrs = cpuidle_default_attrs,
37555 .name = "cpuidle",
37556 };
37557diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
37558index 12fea3e..1e28f47 100644
37559--- a/drivers/crypto/hifn_795x.c
37560+++ b/drivers/crypto/hifn_795x.c
37561@@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
37562 MODULE_PARM_DESC(hifn_pll_ref,
37563 "PLL reference clock (pci[freq] or ext[freq], default ext)");
37564
37565-static atomic_t hifn_dev_number;
37566+static atomic_unchecked_t hifn_dev_number;
37567
37568 #define ACRYPTO_OP_DECRYPT 0
37569 #define ACRYPTO_OP_ENCRYPT 1
37570@@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
37571 goto err_out_disable_pci_device;
37572
37573 snprintf(name, sizeof(name), "hifn%d",
37574- atomic_inc_return(&hifn_dev_number)-1);
37575+ atomic_inc_return_unchecked(&hifn_dev_number)-1);
37576
37577 err = pci_request_regions(pdev, name);
37578 if (err)
37579diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
37580index e94e619..f7e249c 100644
37581--- a/drivers/devfreq/devfreq.c
37582+++ b/drivers/devfreq/devfreq.c
37583@@ -607,7 +607,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
37584 goto err_out;
37585 }
37586
37587- list_add(&governor->node, &devfreq_governor_list);
37588+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
37589
37590 list_for_each_entry(devfreq, &devfreq_list, node) {
37591 int ret = 0;
37592@@ -695,7 +695,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
37593 }
37594 }
37595
37596- list_del(&governor->node);
37597+ pax_list_del((struct list_head *)&governor->node);
37598 err_out:
37599 mutex_unlock(&devfreq_list_lock);
37600
37601diff --git a/drivers/dma/sh/shdma.c b/drivers/dma/sh/shdma.c
37602index 5039fbc..841169f 100644
37603--- a/drivers/dma/sh/shdma.c
37604+++ b/drivers/dma/sh/shdma.c
37605@@ -488,7 +488,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
37606 return ret;
37607 }
37608
37609-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
37610+static struct notifier_block sh_dmae_nmi_notifier = {
37611 .notifier_call = sh_dmae_nmi_handler,
37612
37613 /* Run before NMI debug handler and KGDB */
37614diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
37615index 211021d..201d47f 100644
37616--- a/drivers/edac/edac_device.c
37617+++ b/drivers/edac/edac_device.c
37618@@ -474,9 +474,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
37619 */
37620 int edac_device_alloc_index(void)
37621 {
37622- static atomic_t device_indexes = ATOMIC_INIT(0);
37623+ static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
37624
37625- return atomic_inc_return(&device_indexes) - 1;
37626+ return atomic_inc_return_unchecked(&device_indexes) - 1;
37627 }
37628 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
37629
37630diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
37631index e7c32c4..6397af1 100644
37632--- a/drivers/edac/edac_mc_sysfs.c
37633+++ b/drivers/edac/edac_mc_sysfs.c
37634@@ -148,7 +148,7 @@ static const char * const edac_caps[] = {
37635 struct dev_ch_attribute {
37636 struct device_attribute attr;
37637 int channel;
37638-};
37639+} __do_const;
37640
37641 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
37642 struct dev_ch_attribute dev_attr_legacy_##_name = \
37643@@ -1005,14 +1005,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
37644 }
37645
37646 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
37647+ pax_open_kernel();
37648 if (mci->get_sdram_scrub_rate) {
37649- dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
37650- dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
37651+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
37652+ *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
37653 }
37654 if (mci->set_sdram_scrub_rate) {
37655- dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
37656- dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
37657+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
37658+ *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
37659 }
37660+ pax_close_kernel();
37661 err = device_create_file(&mci->dev,
37662 &dev_attr_sdram_scrub_rate);
37663 if (err) {
37664diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
37665index dd370f9..0281629 100644
37666--- a/drivers/edac/edac_pci.c
37667+++ b/drivers/edac/edac_pci.c
37668@@ -29,7 +29,7 @@
37669
37670 static DEFINE_MUTEX(edac_pci_ctls_mutex);
37671 static LIST_HEAD(edac_pci_list);
37672-static atomic_t pci_indexes = ATOMIC_INIT(0);
37673+static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
37674
37675 /*
37676 * edac_pci_alloc_ctl_info
37677@@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
37678 */
37679 int edac_pci_alloc_index(void)
37680 {
37681- return atomic_inc_return(&pci_indexes) - 1;
37682+ return atomic_inc_return_unchecked(&pci_indexes) - 1;
37683 }
37684 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
37685
37686diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
37687index e8658e4..22746d6 100644
37688--- a/drivers/edac/edac_pci_sysfs.c
37689+++ b/drivers/edac/edac_pci_sysfs.c
37690@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
37691 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
37692 static int edac_pci_poll_msec = 1000; /* one second workq period */
37693
37694-static atomic_t pci_parity_count = ATOMIC_INIT(0);
37695-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
37696+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
37697+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
37698
37699 static struct kobject *edac_pci_top_main_kobj;
37700 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
37701@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
37702 void *value;
37703 ssize_t(*show) (void *, char *);
37704 ssize_t(*store) (void *, const char *, size_t);
37705-};
37706+} __do_const;
37707
37708 /* Set of show/store abstract level functions for PCI Parity object */
37709 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
37710@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37711 edac_printk(KERN_CRIT, EDAC_PCI,
37712 "Signaled System Error on %s\n",
37713 pci_name(dev));
37714- atomic_inc(&pci_nonparity_count);
37715+ atomic_inc_unchecked(&pci_nonparity_count);
37716 }
37717
37718 if (status & (PCI_STATUS_PARITY)) {
37719@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37720 "Master Data Parity Error on %s\n",
37721 pci_name(dev));
37722
37723- atomic_inc(&pci_parity_count);
37724+ atomic_inc_unchecked(&pci_parity_count);
37725 }
37726
37727 if (status & (PCI_STATUS_DETECTED_PARITY)) {
37728@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37729 "Detected Parity Error on %s\n",
37730 pci_name(dev));
37731
37732- atomic_inc(&pci_parity_count);
37733+ atomic_inc_unchecked(&pci_parity_count);
37734 }
37735 }
37736
37737@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37738 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
37739 "Signaled System Error on %s\n",
37740 pci_name(dev));
37741- atomic_inc(&pci_nonparity_count);
37742+ atomic_inc_unchecked(&pci_nonparity_count);
37743 }
37744
37745 if (status & (PCI_STATUS_PARITY)) {
37746@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37747 "Master Data Parity Error on "
37748 "%s\n", pci_name(dev));
37749
37750- atomic_inc(&pci_parity_count);
37751+ atomic_inc_unchecked(&pci_parity_count);
37752 }
37753
37754 if (status & (PCI_STATUS_DETECTED_PARITY)) {
37755@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
37756 "Detected Parity Error on %s\n",
37757 pci_name(dev));
37758
37759- atomic_inc(&pci_parity_count);
37760+ atomic_inc_unchecked(&pci_parity_count);
37761 }
37762 }
37763 }
37764@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
37765 if (!check_pci_errors)
37766 return;
37767
37768- before_count = atomic_read(&pci_parity_count);
37769+ before_count = atomic_read_unchecked(&pci_parity_count);
37770
37771 /* scan all PCI devices looking for a Parity Error on devices and
37772 * bridges.
37773@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
37774 /* Only if operator has selected panic on PCI Error */
37775 if (edac_pci_get_panic_on_pe()) {
37776 /* If the count is different 'after' from 'before' */
37777- if (before_count != atomic_read(&pci_parity_count))
37778+ if (before_count != atomic_read_unchecked(&pci_parity_count))
37779 panic("EDAC: PCI Parity Error");
37780 }
37781 }
37782diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
37783index 51b7e3a..aa8a3e8 100644
37784--- a/drivers/edac/mce_amd.h
37785+++ b/drivers/edac/mce_amd.h
37786@@ -77,7 +77,7 @@ struct amd_decoder_ops {
37787 bool (*mc0_mce)(u16, u8);
37788 bool (*mc1_mce)(u16, u8);
37789 bool (*mc2_mce)(u16, u8);
37790-};
37791+} __no_const;
37792
37793 void amd_report_gart_errors(bool);
37794 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
37795diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
37796index 57ea7f4..af06b76 100644
37797--- a/drivers/firewire/core-card.c
37798+++ b/drivers/firewire/core-card.c
37799@@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
37800 const struct fw_card_driver *driver,
37801 struct device *device)
37802 {
37803- static atomic_t index = ATOMIC_INIT(-1);
37804+ static atomic_unchecked_t index = ATOMIC_INIT(-1);
37805
37806- card->index = atomic_inc_return(&index);
37807+ card->index = atomic_inc_return_unchecked(&index);
37808 card->driver = driver;
37809 card->device = device;
37810 card->current_tlabel = 0;
37811@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
37812
37813 void fw_core_remove_card(struct fw_card *card)
37814 {
37815- struct fw_card_driver dummy_driver = dummy_driver_template;
37816+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
37817
37818 card->driver->update_phy_reg(card, 4,
37819 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
37820diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
37821index de4aa40..49ab1f2 100644
37822--- a/drivers/firewire/core-device.c
37823+++ b/drivers/firewire/core-device.c
37824@@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
37825 struct config_rom_attribute {
37826 struct device_attribute attr;
37827 u32 key;
37828-};
37829+} __do_const;
37830
37831 static ssize_t show_immediate(struct device *dev,
37832 struct device_attribute *dattr, char *buf)
37833diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
37834index 28a94c7..58da63a 100644
37835--- a/drivers/firewire/core-transaction.c
37836+++ b/drivers/firewire/core-transaction.c
37837@@ -38,6 +38,7 @@
37838 #include <linux/timer.h>
37839 #include <linux/types.h>
37840 #include <linux/workqueue.h>
37841+#include <linux/sched.h>
37842
37843 #include <asm/byteorder.h>
37844
37845diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
37846index 515a42c..5ecf3ba 100644
37847--- a/drivers/firewire/core.h
37848+++ b/drivers/firewire/core.h
37849@@ -111,6 +111,7 @@ struct fw_card_driver {
37850
37851 int (*stop_iso)(struct fw_iso_context *ctx);
37852 };
37853+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
37854
37855 void fw_card_initialize(struct fw_card *card,
37856 const struct fw_card_driver *driver, struct device *device);
37857diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
37858index 94a58a0..f5eba42 100644
37859--- a/drivers/firmware/dmi-id.c
37860+++ b/drivers/firmware/dmi-id.c
37861@@ -16,7 +16,7 @@
37862 struct dmi_device_attribute{
37863 struct device_attribute dev_attr;
37864 int field;
37865-};
37866+} __do_const;
37867 #define to_dmi_dev_attr(_dev_attr) \
37868 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
37869
37870diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
37871index 232fa8f..386c255 100644
37872--- a/drivers/firmware/dmi_scan.c
37873+++ b/drivers/firmware/dmi_scan.c
37874@@ -504,11 +504,6 @@ void __init dmi_scan_machine(void)
37875 }
37876 }
37877 else {
37878- /*
37879- * no iounmap() for that ioremap(); it would be a no-op, but
37880- * it's so early in setup that sucker gets confused into doing
37881- * what it shouldn't if we actually call it.
37882- */
37883 p = dmi_ioremap(0xF0000, 0x10000);
37884 if (p == NULL)
37885 goto error;
37886@@ -806,7 +801,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
37887 if (buf == NULL)
37888 return -1;
37889
37890- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
37891+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
37892
37893 iounmap(buf);
37894 return 0;
37895diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
37896index 5145fa3..0d3babd 100644
37897--- a/drivers/firmware/efi/efi.c
37898+++ b/drivers/firmware/efi/efi.c
37899@@ -65,14 +65,16 @@ static struct attribute_group efi_subsys_attr_group = {
37900 };
37901
37902 static struct efivars generic_efivars;
37903-static struct efivar_operations generic_ops;
37904+static efivar_operations_no_const generic_ops __read_only;
37905
37906 static int generic_ops_register(void)
37907 {
37908- generic_ops.get_variable = efi.get_variable;
37909- generic_ops.set_variable = efi.set_variable;
37910- generic_ops.get_next_variable = efi.get_next_variable;
37911- generic_ops.query_variable_store = efi_query_variable_store;
37912+ pax_open_kernel();
37913+ *(void **)&generic_ops.get_variable = efi.get_variable;
37914+ *(void **)&generic_ops.set_variable = efi.set_variable;
37915+ *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
37916+ *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
37917+ pax_close_kernel();
37918
37919 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
37920 }
37921diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
37922index 8a7432a..28fb839 100644
37923--- a/drivers/firmware/efi/efivars.c
37924+++ b/drivers/firmware/efi/efivars.c
37925@@ -452,7 +452,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
37926 static int
37927 create_efivars_bin_attributes(void)
37928 {
37929- struct bin_attribute *attr;
37930+ bin_attribute_no_const *attr;
37931 int error;
37932
37933 /* new_var */
37934diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
37935index 2a90ba6..07f3733 100644
37936--- a/drivers/firmware/google/memconsole.c
37937+++ b/drivers/firmware/google/memconsole.c
37938@@ -147,7 +147,9 @@ static int __init memconsole_init(void)
37939 if (!found_memconsole())
37940 return -ENODEV;
37941
37942- memconsole_bin_attr.size = memconsole_length;
37943+ pax_open_kernel();
37944+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
37945+ pax_close_kernel();
37946
37947 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
37948
37949diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
37950index 2729e3d..f9deca1 100644
37951--- a/drivers/gpio/gpio-ich.c
37952+++ b/drivers/gpio/gpio-ich.c
37953@@ -71,7 +71,7 @@ struct ichx_desc {
37954 /* Some chipsets have quirks, let these use their own request/get */
37955 int (*request)(struct gpio_chip *chip, unsigned offset);
37956 int (*get)(struct gpio_chip *chip, unsigned offset);
37957-};
37958+} __do_const;
37959
37960 static struct {
37961 spinlock_t lock;
37962diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
37963index 9902732..64b62dd 100644
37964--- a/drivers/gpio/gpio-vr41xx.c
37965+++ b/drivers/gpio/gpio-vr41xx.c
37966@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
37967 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
37968 maskl, pendl, maskh, pendh);
37969
37970- atomic_inc(&irq_err_count);
37971+ atomic_inc_unchecked(&irq_err_count);
37972
37973 return -EINVAL;
37974 }
37975diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
37976index 6a64749..0767a9f 100644
37977--- a/drivers/gpu/drm/drm_crtc_helper.c
37978+++ b/drivers/gpu/drm/drm_crtc_helper.c
37979@@ -322,7 +322,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
37980 struct drm_crtc *tmp;
37981 int crtc_mask = 1;
37982
37983- WARN(!crtc, "checking null crtc?\n");
37984+ BUG_ON(!crtc);
37985
37986 dev = crtc->dev;
37987
37988diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
37989index 99fcd7c..13cf6c5 100644
37990--- a/drivers/gpu/drm/drm_drv.c
37991+++ b/drivers/gpu/drm/drm_drv.c
37992@@ -307,7 +307,7 @@ module_exit(drm_core_exit);
37993 /**
37994 * Copy and IOCTL return string to user space
37995 */
37996-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
37997+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
37998 {
37999 int len;
38000
38001@@ -377,7 +377,7 @@ long drm_ioctl(struct file *filp,
38002 struct drm_file *file_priv = filp->private_data;
38003 struct drm_device *dev;
38004 const struct drm_ioctl_desc *ioctl = NULL;
38005- drm_ioctl_t *func;
38006+ drm_ioctl_no_const_t func;
38007 unsigned int nr = DRM_IOCTL_NR(cmd);
38008 int retcode = -EINVAL;
38009 char stack_kdata[128];
38010@@ -390,7 +390,7 @@ long drm_ioctl(struct file *filp,
38011 return -ENODEV;
38012
38013 atomic_inc(&dev->ioctl_count);
38014- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
38015+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
38016 ++file_priv->ioctl_count;
38017
38018 if ((nr >= DRM_CORE_IOCTL_COUNT) &&
38019diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
38020index 3a24385..4e426e0 100644
38021--- a/drivers/gpu/drm/drm_fops.c
38022+++ b/drivers/gpu/drm/drm_fops.c
38023@@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
38024 }
38025
38026 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
38027- atomic_set(&dev->counts[i], 0);
38028+ atomic_set_unchecked(&dev->counts[i], 0);
38029
38030 dev->sigdata.lock = NULL;
38031
38032@@ -135,7 +135,7 @@ int drm_open(struct inode *inode, struct file *filp)
38033 if (drm_device_is_unplugged(dev))
38034 return -ENODEV;
38035
38036- if (!dev->open_count++)
38037+ if (local_inc_return(&dev->open_count) == 1)
38038 need_setup = 1;
38039 mutex_lock(&dev->struct_mutex);
38040 old_imapping = inode->i_mapping;
38041@@ -151,7 +151,7 @@ int drm_open(struct inode *inode, struct file *filp)
38042 retcode = drm_open_helper(inode, filp, dev);
38043 if (retcode)
38044 goto err_undo;
38045- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
38046+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
38047 if (need_setup) {
38048 retcode = drm_setup(dev);
38049 if (retcode)
38050@@ -166,7 +166,7 @@ err_undo:
38051 iput(container_of(dev->dev_mapping, struct inode, i_data));
38052 dev->dev_mapping = old_mapping;
38053 mutex_unlock(&dev->struct_mutex);
38054- dev->open_count--;
38055+ local_dec(&dev->open_count);
38056 return retcode;
38057 }
38058 EXPORT_SYMBOL(drm_open);
38059@@ -456,7 +456,7 @@ int drm_release(struct inode *inode, struct file *filp)
38060
38061 mutex_lock(&drm_global_mutex);
38062
38063- DRM_DEBUG("open_count = %d\n", dev->open_count);
38064+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
38065
38066 if (dev->driver->preclose)
38067 dev->driver->preclose(dev, file_priv);
38068@@ -465,10 +465,10 @@ int drm_release(struct inode *inode, struct file *filp)
38069 * Begin inline drm_release
38070 */
38071
38072- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
38073+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
38074 task_pid_nr(current),
38075 (long)old_encode_dev(file_priv->minor->device),
38076- dev->open_count);
38077+ local_read(&dev->open_count));
38078
38079 /* Release any auth tokens that might point to this file_priv,
38080 (do that under the drm_global_mutex) */
38081@@ -565,8 +565,8 @@ int drm_release(struct inode *inode, struct file *filp)
38082 * End inline drm_release
38083 */
38084
38085- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
38086- if (!--dev->open_count) {
38087+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
38088+ if (local_dec_and_test(&dev->open_count)) {
38089 if (atomic_read(&dev->ioctl_count)) {
38090 DRM_ERROR("Device busy: %d\n",
38091 atomic_read(&dev->ioctl_count));
38092diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
38093index f731116..629842c 100644
38094--- a/drivers/gpu/drm/drm_global.c
38095+++ b/drivers/gpu/drm/drm_global.c
38096@@ -36,7 +36,7 @@
38097 struct drm_global_item {
38098 struct mutex mutex;
38099 void *object;
38100- int refcount;
38101+ atomic_t refcount;
38102 };
38103
38104 static struct drm_global_item glob[DRM_GLOBAL_NUM];
38105@@ -49,7 +49,7 @@ void drm_global_init(void)
38106 struct drm_global_item *item = &glob[i];
38107 mutex_init(&item->mutex);
38108 item->object = NULL;
38109- item->refcount = 0;
38110+ atomic_set(&item->refcount, 0);
38111 }
38112 }
38113
38114@@ -59,7 +59,7 @@ void drm_global_release(void)
38115 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
38116 struct drm_global_item *item = &glob[i];
38117 BUG_ON(item->object != NULL);
38118- BUG_ON(item->refcount != 0);
38119+ BUG_ON(atomic_read(&item->refcount) != 0);
38120 }
38121 }
38122
38123@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
38124 void *object;
38125
38126 mutex_lock(&item->mutex);
38127- if (item->refcount == 0) {
38128+ if (atomic_read(&item->refcount) == 0) {
38129 item->object = kzalloc(ref->size, GFP_KERNEL);
38130 if (unlikely(item->object == NULL)) {
38131 ret = -ENOMEM;
38132@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
38133 goto out_err;
38134
38135 }
38136- ++item->refcount;
38137+ atomic_inc(&item->refcount);
38138 ref->object = item->object;
38139 object = item->object;
38140 mutex_unlock(&item->mutex);
38141@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
38142 struct drm_global_item *item = &glob[ref->global_type];
38143
38144 mutex_lock(&item->mutex);
38145- BUG_ON(item->refcount == 0);
38146+ BUG_ON(atomic_read(&item->refcount) == 0);
38147 BUG_ON(ref->object != item->object);
38148- if (--item->refcount == 0) {
38149+ if (atomic_dec_and_test(&item->refcount)) {
38150 ref->release(ref);
38151 item->object = NULL;
38152 }
38153diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
38154index d4b20ce..77a8d41 100644
38155--- a/drivers/gpu/drm/drm_info.c
38156+++ b/drivers/gpu/drm/drm_info.c
38157@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
38158 struct drm_local_map *map;
38159 struct drm_map_list *r_list;
38160
38161- /* Hardcoded from _DRM_FRAME_BUFFER,
38162- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
38163- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
38164- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
38165+ static const char * const types[] = {
38166+ [_DRM_FRAME_BUFFER] = "FB",
38167+ [_DRM_REGISTERS] = "REG",
38168+ [_DRM_SHM] = "SHM",
38169+ [_DRM_AGP] = "AGP",
38170+ [_DRM_SCATTER_GATHER] = "SG",
38171+ [_DRM_CONSISTENT] = "PCI",
38172+ [_DRM_GEM] = "GEM" };
38173 const char *type;
38174 int i;
38175
38176@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
38177 map = r_list->map;
38178 if (!map)
38179 continue;
38180- if (map->type < 0 || map->type > 5)
38181+ if (map->type >= ARRAY_SIZE(types))
38182 type = "??";
38183 else
38184 type = types[map->type];
38185@@ -253,7 +257,11 @@ int drm_vma_info(struct seq_file *m, void *data)
38186 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
38187 vma->vm_flags & VM_LOCKED ? 'l' : '-',
38188 vma->vm_flags & VM_IO ? 'i' : '-',
38189+#ifdef CONFIG_GRKERNSEC_HIDESYM
38190+ 0);
38191+#else
38192 vma->vm_pgoff);
38193+#endif
38194
38195 #if defined(__i386__)
38196 pgprot = pgprot_val(vma->vm_page_prot);
38197diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
38198index 2f4c434..dd12cd2 100644
38199--- a/drivers/gpu/drm/drm_ioc32.c
38200+++ b/drivers/gpu/drm/drm_ioc32.c
38201@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
38202 request = compat_alloc_user_space(nbytes);
38203 if (!access_ok(VERIFY_WRITE, request, nbytes))
38204 return -EFAULT;
38205- list = (struct drm_buf_desc *) (request + 1);
38206+ list = (struct drm_buf_desc __user *) (request + 1);
38207
38208 if (__put_user(count, &request->count)
38209 || __put_user(list, &request->list))
38210@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
38211 request = compat_alloc_user_space(nbytes);
38212 if (!access_ok(VERIFY_WRITE, request, nbytes))
38213 return -EFAULT;
38214- list = (struct drm_buf_pub *) (request + 1);
38215+ list = (struct drm_buf_pub __user *) (request + 1);
38216
38217 if (__put_user(count, &request->count)
38218 || __put_user(list, &request->list))
38219@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
38220 return 0;
38221 }
38222
38223-drm_ioctl_compat_t *drm_compat_ioctls[] = {
38224+drm_ioctl_compat_t drm_compat_ioctls[] = {
38225 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
38226 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
38227 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
38228@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
38229 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38230 {
38231 unsigned int nr = DRM_IOCTL_NR(cmd);
38232- drm_ioctl_compat_t *fn;
38233 int ret;
38234
38235 /* Assume that ioctls without an explicit compat routine will just
38236@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38237 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
38238 return drm_ioctl(filp, cmd, arg);
38239
38240- fn = drm_compat_ioctls[nr];
38241-
38242- if (fn != NULL)
38243- ret = (*fn) (filp, cmd, arg);
38244+ if (drm_compat_ioctls[nr] != NULL)
38245+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
38246 else
38247 ret = drm_ioctl(filp, cmd, arg);
38248
38249diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
38250index ffd7a7b..a64643e 100644
38251--- a/drivers/gpu/drm/drm_ioctl.c
38252+++ b/drivers/gpu/drm/drm_ioctl.c
38253@@ -265,7 +265,7 @@ int drm_getstats(struct drm_device *dev, void *data,
38254 stats->data[i].value =
38255 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
38256 else
38257- stats->data[i].value = atomic_read(&dev->counts[i]);
38258+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
38259 stats->data[i].type = dev->types[i];
38260 }
38261
38262diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
38263index d752c96..fe08455 100644
38264--- a/drivers/gpu/drm/drm_lock.c
38265+++ b/drivers/gpu/drm/drm_lock.c
38266@@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
38267 if (drm_lock_take(&master->lock, lock->context)) {
38268 master->lock.file_priv = file_priv;
38269 master->lock.lock_time = jiffies;
38270- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
38271+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
38272 break; /* Got lock */
38273 }
38274
38275@@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
38276 return -EINVAL;
38277 }
38278
38279- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
38280+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
38281
38282 if (drm_lock_free(&master->lock, lock->context)) {
38283 /* FIXME: Should really bail out here. */
38284diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
38285index 327ca19..684d3c0 100644
38286--- a/drivers/gpu/drm/drm_stub.c
38287+++ b/drivers/gpu/drm/drm_stub.c
38288@@ -495,7 +495,7 @@ void drm_unplug_dev(struct drm_device *dev)
38289
38290 drm_device_set_unplugged(dev);
38291
38292- if (dev->open_count == 0) {
38293+ if (local_read(&dev->open_count) == 0) {
38294 drm_put_dev(dev);
38295 }
38296 mutex_unlock(&drm_global_mutex);
38297diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
38298index 2290b3b..22056a1 100644
38299--- a/drivers/gpu/drm/drm_sysfs.c
38300+++ b/drivers/gpu/drm/drm_sysfs.c
38301@@ -524,7 +524,7 @@ EXPORT_SYMBOL(drm_sysfs_hotplug_event);
38302 int drm_sysfs_device_add(struct drm_minor *minor)
38303 {
38304 int err;
38305- char *minor_str;
38306+ const char *minor_str;
38307
38308 minor->kdev.parent = minor->dev->dev;
38309
38310diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
38311index ada49ed..29275a0 100644
38312--- a/drivers/gpu/drm/i810/i810_dma.c
38313+++ b/drivers/gpu/drm/i810/i810_dma.c
38314@@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
38315 dma->buflist[vertex->idx],
38316 vertex->discard, vertex->used);
38317
38318- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
38319- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
38320+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
38321+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
38322 sarea_priv->last_enqueue = dev_priv->counter - 1;
38323 sarea_priv->last_dispatch = (int)hw_status[5];
38324
38325@@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
38326 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
38327 mc->last_render);
38328
38329- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
38330- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
38331+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
38332+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
38333 sarea_priv->last_enqueue = dev_priv->counter - 1;
38334 sarea_priv->last_dispatch = (int)hw_status[5];
38335
38336diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
38337index 6e0acad..93c8289 100644
38338--- a/drivers/gpu/drm/i810/i810_drv.h
38339+++ b/drivers/gpu/drm/i810/i810_drv.h
38340@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
38341 int page_flipping;
38342
38343 wait_queue_head_t irq_queue;
38344- atomic_t irq_received;
38345- atomic_t irq_emitted;
38346+ atomic_unchecked_t irq_received;
38347+ atomic_unchecked_t irq_emitted;
38348
38349 int front_offset;
38350 } drm_i810_private_t;
38351diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
38352index 47d6c74..279123f 100644
38353--- a/drivers/gpu/drm/i915/i915_debugfs.c
38354+++ b/drivers/gpu/drm/i915/i915_debugfs.c
38355@@ -541,7 +541,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
38356 I915_READ(GTIMR));
38357 }
38358 seq_printf(m, "Interrupts received: %d\n",
38359- atomic_read(&dev_priv->irq_received));
38360+ atomic_read_unchecked(&dev_priv->irq_received));
38361 for_each_ring(ring, dev_priv, i) {
38362 if (IS_GEN6(dev) || IS_GEN7(dev)) {
38363 seq_printf(m,
38364diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
38365index f466980..8f2883f 100644
38366--- a/drivers/gpu/drm/i915/i915_dma.c
38367+++ b/drivers/gpu/drm/i915/i915_dma.c
38368@@ -1260,7 +1260,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
38369 bool can_switch;
38370
38371 spin_lock(&dev->count_lock);
38372- can_switch = (dev->open_count == 0);
38373+ can_switch = (local_read(&dev->open_count) == 0);
38374 spin_unlock(&dev->count_lock);
38375 return can_switch;
38376 }
38377diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
38378index 1929bff..dab130d 100644
38379--- a/drivers/gpu/drm/i915/i915_drv.h
38380+++ b/drivers/gpu/drm/i915/i915_drv.h
38381@@ -1028,7 +1028,7 @@ typedef struct drm_i915_private {
38382 drm_dma_handle_t *status_page_dmah;
38383 struct resource mch_res;
38384
38385- atomic_t irq_received;
38386+ atomic_unchecked_t irq_received;
38387
38388 /* protects the irq masks */
38389 spinlock_t irq_lock;
38390diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
38391index 87a3227..cd13d8f 100644
38392--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
38393+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
38394@@ -727,9 +727,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
38395
38396 static int
38397 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
38398- int count)
38399+ unsigned int count)
38400 {
38401- int i;
38402+ unsigned int i;
38403 int relocs_total = 0;
38404 int relocs_max = INT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
38405
38406diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
38407index 3c59584..500f2e9 100644
38408--- a/drivers/gpu/drm/i915/i915_ioc32.c
38409+++ b/drivers/gpu/drm/i915/i915_ioc32.c
38410@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
38411 (unsigned long)request);
38412 }
38413
38414-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
38415+static drm_ioctl_compat_t i915_compat_ioctls[] = {
38416 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
38417 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
38418 [DRM_I915_GETPARAM] = compat_i915_getparam,
38419@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
38420 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38421 {
38422 unsigned int nr = DRM_IOCTL_NR(cmd);
38423- drm_ioctl_compat_t *fn = NULL;
38424 int ret;
38425
38426 if (nr < DRM_COMMAND_BASE)
38427 return drm_compat_ioctl(filp, cmd, arg);
38428
38429- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
38430- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
38431-
38432- if (fn != NULL)
38433+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
38434+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
38435 ret = (*fn) (filp, cmd, arg);
38436- else
38437+ } else
38438 ret = drm_ioctl(filp, cmd, arg);
38439
38440 return ret;
38441diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
38442index 3d92a7c..9a9cfd7 100644
38443--- a/drivers/gpu/drm/i915/i915_irq.c
38444+++ b/drivers/gpu/drm/i915/i915_irq.c
38445@@ -970,7 +970,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
38446 int pipe;
38447 u32 pipe_stats[I915_MAX_PIPES];
38448
38449- atomic_inc(&dev_priv->irq_received);
38450+ atomic_inc_unchecked(&dev_priv->irq_received);
38451
38452 while (true) {
38453 iir = I915_READ(VLV_IIR);
38454@@ -1187,7 +1187,7 @@ static irqreturn_t ivybridge_irq_handler(int irq, void *arg)
38455 irqreturn_t ret = IRQ_NONE;
38456 int i;
38457
38458- atomic_inc(&dev_priv->irq_received);
38459+ atomic_inc_unchecked(&dev_priv->irq_received);
38460
38461 /* We get interrupts on unclaimed registers, so check for this before we
38462 * do any I915_{READ,WRITE}. */
38463@@ -1307,7 +1307,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
38464 int ret = IRQ_NONE;
38465 u32 de_iir, gt_iir, de_ier, pm_iir, sde_ier;
38466
38467- atomic_inc(&dev_priv->irq_received);
38468+ atomic_inc_unchecked(&dev_priv->irq_received);
38469
38470 /* disable master interrupt before clearing iir */
38471 de_ier = I915_READ(DEIER);
38472@@ -2566,7 +2566,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
38473 {
38474 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38475
38476- atomic_set(&dev_priv->irq_received, 0);
38477+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38478
38479 I915_WRITE(HWSTAM, 0xeffe);
38480
38481@@ -2588,7 +2588,7 @@ static void ivybridge_irq_preinstall(struct drm_device *dev)
38482 {
38483 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38484
38485- atomic_set(&dev_priv->irq_received, 0);
38486+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38487
38488 I915_WRITE(HWSTAM, 0xeffe);
38489
38490@@ -2616,7 +2616,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
38491 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38492 int pipe;
38493
38494- atomic_set(&dev_priv->irq_received, 0);
38495+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38496
38497 /* VLV magic */
38498 I915_WRITE(VLV_IMR, 0);
38499@@ -2928,7 +2928,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
38500 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38501 int pipe;
38502
38503- atomic_set(&dev_priv->irq_received, 0);
38504+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38505
38506 for_each_pipe(pipe)
38507 I915_WRITE(PIPESTAT(pipe), 0);
38508@@ -3007,7 +3007,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
38509 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
38510 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
38511
38512- atomic_inc(&dev_priv->irq_received);
38513+ atomic_inc_unchecked(&dev_priv->irq_received);
38514
38515 iir = I915_READ16(IIR);
38516 if (iir == 0)
38517@@ -3082,7 +3082,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
38518 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38519 int pipe;
38520
38521- atomic_set(&dev_priv->irq_received, 0);
38522+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38523
38524 if (I915_HAS_HOTPLUG(dev)) {
38525 I915_WRITE(PORT_HOTPLUG_EN, 0);
38526@@ -3181,7 +3181,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
38527 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
38528 int pipe, ret = IRQ_NONE;
38529
38530- atomic_inc(&dev_priv->irq_received);
38531+ atomic_inc_unchecked(&dev_priv->irq_received);
38532
38533 iir = I915_READ(IIR);
38534 do {
38535@@ -3305,7 +3305,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
38536 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
38537 int pipe;
38538
38539- atomic_set(&dev_priv->irq_received, 0);
38540+ atomic_set_unchecked(&dev_priv->irq_received, 0);
38541
38542 I915_WRITE(PORT_HOTPLUG_EN, 0);
38543 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
38544@@ -3414,7 +3414,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
38545 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
38546 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
38547
38548- atomic_inc(&dev_priv->irq_received);
38549+ atomic_inc_unchecked(&dev_priv->irq_received);
38550
38551 iir = I915_READ(IIR);
38552
38553diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
38554index be79f47..95e150b 100644
38555--- a/drivers/gpu/drm/i915/intel_display.c
38556+++ b/drivers/gpu/drm/i915/intel_display.c
38557@@ -9418,13 +9418,13 @@ struct intel_quirk {
38558 int subsystem_vendor;
38559 int subsystem_device;
38560 void (*hook)(struct drm_device *dev);
38561-};
38562+} __do_const;
38563
38564 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
38565 struct intel_dmi_quirk {
38566 void (*hook)(struct drm_device *dev);
38567 const struct dmi_system_id (*dmi_id_list)[];
38568-};
38569+} __do_const;
38570
38571 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
38572 {
38573@@ -9432,18 +9432,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
38574 return 1;
38575 }
38576
38577-static const struct intel_dmi_quirk intel_dmi_quirks[] = {
38578+static const struct dmi_system_id intel_dmi_quirks_table[] = {
38579 {
38580- .dmi_id_list = &(const struct dmi_system_id[]) {
38581- {
38582- .callback = intel_dmi_reverse_brightness,
38583- .ident = "NCR Corporation",
38584- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
38585- DMI_MATCH(DMI_PRODUCT_NAME, ""),
38586- },
38587- },
38588- { } /* terminating entry */
38589+ .callback = intel_dmi_reverse_brightness,
38590+ .ident = "NCR Corporation",
38591+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
38592+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
38593 },
38594+ },
38595+ { } /* terminating entry */
38596+};
38597+
38598+static const struct intel_dmi_quirk intel_dmi_quirks[] = {
38599+ {
38600+ .dmi_id_list = &intel_dmi_quirks_table,
38601 .hook = quirk_invert_brightness,
38602 },
38603 };
38604diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
38605index 54558a0..2d97005 100644
38606--- a/drivers/gpu/drm/mga/mga_drv.h
38607+++ b/drivers/gpu/drm/mga/mga_drv.h
38608@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
38609 u32 clear_cmd;
38610 u32 maccess;
38611
38612- atomic_t vbl_received; /**< Number of vblanks received. */
38613+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
38614 wait_queue_head_t fence_queue;
38615- atomic_t last_fence_retired;
38616+ atomic_unchecked_t last_fence_retired;
38617 u32 next_fence_to_post;
38618
38619 unsigned int fb_cpp;
38620diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
38621index 709e90d..89a1c0d 100644
38622--- a/drivers/gpu/drm/mga/mga_ioc32.c
38623+++ b/drivers/gpu/drm/mga/mga_ioc32.c
38624@@ -189,7 +189,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
38625 return 0;
38626 }
38627
38628-drm_ioctl_compat_t *mga_compat_ioctls[] = {
38629+drm_ioctl_compat_t mga_compat_ioctls[] = {
38630 [DRM_MGA_INIT] = compat_mga_init,
38631 [DRM_MGA_GETPARAM] = compat_mga_getparam,
38632 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
38633@@ -207,18 +207,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
38634 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38635 {
38636 unsigned int nr = DRM_IOCTL_NR(cmd);
38637- drm_ioctl_compat_t *fn = NULL;
38638 int ret;
38639
38640 if (nr < DRM_COMMAND_BASE)
38641 return drm_compat_ioctl(filp, cmd, arg);
38642
38643- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
38644- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
38645-
38646- if (fn != NULL)
38647+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
38648+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
38649 ret = (*fn) (filp, cmd, arg);
38650- else
38651+ } else
38652 ret = drm_ioctl(filp, cmd, arg);
38653
38654 return ret;
38655diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
38656index 598c281..60d590e 100644
38657--- a/drivers/gpu/drm/mga/mga_irq.c
38658+++ b/drivers/gpu/drm/mga/mga_irq.c
38659@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
38660 if (crtc != 0)
38661 return 0;
38662
38663- return atomic_read(&dev_priv->vbl_received);
38664+ return atomic_read_unchecked(&dev_priv->vbl_received);
38665 }
38666
38667
38668@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
38669 /* VBLANK interrupt */
38670 if (status & MGA_VLINEPEN) {
38671 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
38672- atomic_inc(&dev_priv->vbl_received);
38673+ atomic_inc_unchecked(&dev_priv->vbl_received);
38674 drm_handle_vblank(dev, 0);
38675 handled = 1;
38676 }
38677@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
38678 if ((prim_start & ~0x03) != (prim_end & ~0x03))
38679 MGA_WRITE(MGA_PRIMEND, prim_end);
38680
38681- atomic_inc(&dev_priv->last_fence_retired);
38682+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
38683 DRM_WAKEUP(&dev_priv->fence_queue);
38684 handled = 1;
38685 }
38686@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
38687 * using fences.
38688 */
38689 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
38690- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
38691+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
38692 - *sequence) <= (1 << 23)));
38693
38694 *sequence = cur_fence;
38695diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
38696index 3e72876..d1c15ad 100644
38697--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
38698+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
38699@@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
38700 struct bit_table {
38701 const char id;
38702 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
38703-};
38704+} __no_const;
38705
38706 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
38707
38708diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
38709index 41ff7e0..fa854ef 100644
38710--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
38711+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
38712@@ -92,7 +92,6 @@ struct nouveau_drm {
38713 struct drm_global_reference mem_global_ref;
38714 struct ttm_bo_global_ref bo_global_ref;
38715 struct ttm_bo_device bdev;
38716- atomic_t validate_sequence;
38717 int (*move)(struct nouveau_channel *,
38718 struct ttm_buffer_object *,
38719 struct ttm_mem_reg *, struct ttm_mem_reg *);
38720diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
38721index 08214bc..9208577 100644
38722--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
38723+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
38724@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
38725 unsigned long arg)
38726 {
38727 unsigned int nr = DRM_IOCTL_NR(cmd);
38728- drm_ioctl_compat_t *fn = NULL;
38729+ drm_ioctl_compat_t fn = NULL;
38730 int ret;
38731
38732 if (nr < DRM_COMMAND_BASE)
38733diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
38734index 25d3495..d81aaf6 100644
38735--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
38736+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
38737@@ -62,7 +62,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
38738 bool can_switch;
38739
38740 spin_lock(&dev->count_lock);
38741- can_switch = (dev->open_count == 0);
38742+ can_switch = (local_read(&dev->open_count) == 0);
38743 spin_unlock(&dev->count_lock);
38744 return can_switch;
38745 }
38746diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
38747index 1dfd84c..104896c 100644
38748--- a/drivers/gpu/drm/qxl/qxl_ttm.c
38749+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
38750@@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
38751 }
38752 }
38753
38754-static struct vm_operations_struct qxl_ttm_vm_ops;
38755+static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
38756 static const struct vm_operations_struct *ttm_vm_ops;
38757
38758 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
38759@@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
38760 return r;
38761 if (unlikely(ttm_vm_ops == NULL)) {
38762 ttm_vm_ops = vma->vm_ops;
38763+ pax_open_kernel();
38764 qxl_ttm_vm_ops = *ttm_vm_ops;
38765 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
38766+ pax_close_kernel();
38767 }
38768 vma->vm_ops = &qxl_ttm_vm_ops;
38769 return 0;
38770@@ -556,25 +558,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
38771 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
38772 {
38773 #if defined(CONFIG_DEBUG_FS)
38774- static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
38775- static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
38776- unsigned i;
38777+ static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
38778+ {
38779+ .name = "qxl_mem_mm",
38780+ .show = &qxl_mm_dump_table,
38781+ },
38782+ {
38783+ .name = "qxl_surf_mm",
38784+ .show = &qxl_mm_dump_table,
38785+ }
38786+ };
38787
38788- for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
38789- if (i == 0)
38790- sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
38791- else
38792- sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
38793- qxl_mem_types_list[i].name = qxl_mem_types_names[i];
38794- qxl_mem_types_list[i].show = &qxl_mm_dump_table;
38795- qxl_mem_types_list[i].driver_features = 0;
38796- if (i == 0)
38797- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
38798- else
38799- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
38800+ pax_open_kernel();
38801+ *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
38802+ *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
38803+ pax_close_kernel();
38804
38805- }
38806- return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
38807+ return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
38808 #else
38809 return 0;
38810 #endif
38811diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
38812index d4660cf..70dbe65 100644
38813--- a/drivers/gpu/drm/r128/r128_cce.c
38814+++ b/drivers/gpu/drm/r128/r128_cce.c
38815@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
38816
38817 /* GH: Simple idle check.
38818 */
38819- atomic_set(&dev_priv->idle_count, 0);
38820+ atomic_set_unchecked(&dev_priv->idle_count, 0);
38821
38822 /* We don't support anything other than bus-mastering ring mode,
38823 * but the ring can be in either AGP or PCI space for the ring
38824diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
38825index 930c71b..499aded 100644
38826--- a/drivers/gpu/drm/r128/r128_drv.h
38827+++ b/drivers/gpu/drm/r128/r128_drv.h
38828@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
38829 int is_pci;
38830 unsigned long cce_buffers_offset;
38831
38832- atomic_t idle_count;
38833+ atomic_unchecked_t idle_count;
38834
38835 int page_flipping;
38836 int current_page;
38837 u32 crtc_offset;
38838 u32 crtc_offset_cntl;
38839
38840- atomic_t vbl_received;
38841+ atomic_unchecked_t vbl_received;
38842
38843 u32 color_fmt;
38844 unsigned int front_offset;
38845diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
38846index a954c54..9cc595c 100644
38847--- a/drivers/gpu/drm/r128/r128_ioc32.c
38848+++ b/drivers/gpu/drm/r128/r128_ioc32.c
38849@@ -177,7 +177,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
38850 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
38851 }
38852
38853-drm_ioctl_compat_t *r128_compat_ioctls[] = {
38854+drm_ioctl_compat_t r128_compat_ioctls[] = {
38855 [DRM_R128_INIT] = compat_r128_init,
38856 [DRM_R128_DEPTH] = compat_r128_depth,
38857 [DRM_R128_STIPPLE] = compat_r128_stipple,
38858@@ -196,18 +196,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
38859 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38860 {
38861 unsigned int nr = DRM_IOCTL_NR(cmd);
38862- drm_ioctl_compat_t *fn = NULL;
38863 int ret;
38864
38865 if (nr < DRM_COMMAND_BASE)
38866 return drm_compat_ioctl(filp, cmd, arg);
38867
38868- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
38869- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
38870-
38871- if (fn != NULL)
38872+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
38873+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
38874 ret = (*fn) (filp, cmd, arg);
38875- else
38876+ } else
38877 ret = drm_ioctl(filp, cmd, arg);
38878
38879 return ret;
38880diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
38881index 2ea4f09..d391371 100644
38882--- a/drivers/gpu/drm/r128/r128_irq.c
38883+++ b/drivers/gpu/drm/r128/r128_irq.c
38884@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
38885 if (crtc != 0)
38886 return 0;
38887
38888- return atomic_read(&dev_priv->vbl_received);
38889+ return atomic_read_unchecked(&dev_priv->vbl_received);
38890 }
38891
38892 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
38893@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
38894 /* VBLANK interrupt */
38895 if (status & R128_CRTC_VBLANK_INT) {
38896 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
38897- atomic_inc(&dev_priv->vbl_received);
38898+ atomic_inc_unchecked(&dev_priv->vbl_received);
38899 drm_handle_vblank(dev, 0);
38900 return IRQ_HANDLED;
38901 }
38902diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
38903index 19bb7e6..de7e2a2 100644
38904--- a/drivers/gpu/drm/r128/r128_state.c
38905+++ b/drivers/gpu/drm/r128/r128_state.c
38906@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
38907
38908 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
38909 {
38910- if (atomic_read(&dev_priv->idle_count) == 0)
38911+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
38912 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
38913 else
38914- atomic_set(&dev_priv->idle_count, 0);
38915+ atomic_set_unchecked(&dev_priv->idle_count, 0);
38916 }
38917
38918 #endif
38919diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
38920index af85299..ed9ac8d 100644
38921--- a/drivers/gpu/drm/radeon/mkregtable.c
38922+++ b/drivers/gpu/drm/radeon/mkregtable.c
38923@@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
38924 regex_t mask_rex;
38925 regmatch_t match[4];
38926 char buf[1024];
38927- size_t end;
38928+ long end;
38929 int len;
38930 int done = 0;
38931 int r;
38932 unsigned o;
38933 struct offset *offset;
38934 char last_reg_s[10];
38935- int last_reg;
38936+ unsigned long last_reg;
38937
38938 if (regcomp
38939 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
38940diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
38941index 63398ae..669e045 100644
38942--- a/drivers/gpu/drm/radeon/radeon_device.c
38943+++ b/drivers/gpu/drm/radeon/radeon_device.c
38944@@ -1105,7 +1105,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
38945 bool can_switch;
38946
38947 spin_lock(&dev->count_lock);
38948- can_switch = (dev->open_count == 0);
38949+ can_switch = (local_read(&dev->open_count) == 0);
38950 spin_unlock(&dev->count_lock);
38951 return can_switch;
38952 }
38953diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
38954index b369d42..8dd04eb 100644
38955--- a/drivers/gpu/drm/radeon/radeon_drv.h
38956+++ b/drivers/gpu/drm/radeon/radeon_drv.h
38957@@ -258,7 +258,7 @@ typedef struct drm_radeon_private {
38958
38959 /* SW interrupt */
38960 wait_queue_head_t swi_queue;
38961- atomic_t swi_emitted;
38962+ atomic_unchecked_t swi_emitted;
38963 int vblank_crtc;
38964 uint32_t irq_enable_reg;
38965 uint32_t r500_disp_irq_reg;
38966diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
38967index c180df8..5fd8186 100644
38968--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
38969+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
38970@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
38971 request = compat_alloc_user_space(sizeof(*request));
38972 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
38973 || __put_user(req32.param, &request->param)
38974- || __put_user((void __user *)(unsigned long)req32.value,
38975+ || __put_user((unsigned long)req32.value,
38976 &request->value))
38977 return -EFAULT;
38978
38979@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
38980 #define compat_radeon_cp_setparam NULL
38981 #endif /* X86_64 || IA64 */
38982
38983-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
38984+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
38985 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
38986 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
38987 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
38988@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
38989 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
38990 {
38991 unsigned int nr = DRM_IOCTL_NR(cmd);
38992- drm_ioctl_compat_t *fn = NULL;
38993 int ret;
38994
38995 if (nr < DRM_COMMAND_BASE)
38996 return drm_compat_ioctl(filp, cmd, arg);
38997
38998- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
38999- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
39000-
39001- if (fn != NULL)
39002+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
39003+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
39004 ret = (*fn) (filp, cmd, arg);
39005- else
39006+ } else
39007 ret = drm_ioctl(filp, cmd, arg);
39008
39009 return ret;
39010diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
39011index 8d68e97..9dcfed8 100644
39012--- a/drivers/gpu/drm/radeon/radeon_irq.c
39013+++ b/drivers/gpu/drm/radeon/radeon_irq.c
39014@@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
39015 unsigned int ret;
39016 RING_LOCALS;
39017
39018- atomic_inc(&dev_priv->swi_emitted);
39019- ret = atomic_read(&dev_priv->swi_emitted);
39020+ atomic_inc_unchecked(&dev_priv->swi_emitted);
39021+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
39022
39023 BEGIN_RING(4);
39024 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
39025@@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
39026 drm_radeon_private_t *dev_priv =
39027 (drm_radeon_private_t *) dev->dev_private;
39028
39029- atomic_set(&dev_priv->swi_emitted, 0);
39030+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
39031 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
39032
39033 dev->max_vblank_count = 0x001fffff;
39034diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
39035index 4d20910..6726b6d 100644
39036--- a/drivers/gpu/drm/radeon/radeon_state.c
39037+++ b/drivers/gpu/drm/radeon/radeon_state.c
39038@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
39039 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
39040 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
39041
39042- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
39043+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
39044 sarea_priv->nbox * sizeof(depth_boxes[0])))
39045 return -EFAULT;
39046
39047@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
39048 {
39049 drm_radeon_private_t *dev_priv = dev->dev_private;
39050 drm_radeon_getparam_t *param = data;
39051- int value;
39052+ int value = 0;
39053
39054 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
39055
39056diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
39057index 6c0ce89..57a2529 100644
39058--- a/drivers/gpu/drm/radeon/radeon_ttm.c
39059+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
39060@@ -782,7 +782,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
39061 man->size = size >> PAGE_SHIFT;
39062 }
39063
39064-static struct vm_operations_struct radeon_ttm_vm_ops;
39065+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
39066 static const struct vm_operations_struct *ttm_vm_ops = NULL;
39067
39068 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
39069@@ -823,8 +823,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
39070 }
39071 if (unlikely(ttm_vm_ops == NULL)) {
39072 ttm_vm_ops = vma->vm_ops;
39073+ pax_open_kernel();
39074 radeon_ttm_vm_ops = *ttm_vm_ops;
39075 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
39076+ pax_close_kernel();
39077 }
39078 vma->vm_ops = &radeon_ttm_vm_ops;
39079 return 0;
39080@@ -853,38 +855,33 @@ static int radeon_mm_dump_table(struct seq_file *m, void *data)
39081 static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
39082 {
39083 #if defined(CONFIG_DEBUG_FS)
39084- static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2];
39085- static char radeon_mem_types_names[RADEON_DEBUGFS_MEM_TYPES+2][32];
39086+ static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2] = {
39087+ {
39088+ .name = "radeon_vram_mm",
39089+ .show = &radeon_mm_dump_table,
39090+ },
39091+ {
39092+ .name = "radeon_gtt_mm",
39093+ .show = &radeon_mm_dump_table,
39094+ },
39095+ {
39096+ .name = "ttm_page_pool",
39097+ .show = &ttm_page_alloc_debugfs,
39098+ },
39099+ {
39100+ .name = "ttm_dma_page_pool",
39101+ .show = &ttm_dma_page_alloc_debugfs,
39102+ },
39103+ };
39104 unsigned i;
39105
39106- for (i = 0; i < RADEON_DEBUGFS_MEM_TYPES; i++) {
39107- if (i == 0)
39108- sprintf(radeon_mem_types_names[i], "radeon_vram_mm");
39109- else
39110- sprintf(radeon_mem_types_names[i], "radeon_gtt_mm");
39111- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
39112- radeon_mem_types_list[i].show = &radeon_mm_dump_table;
39113- radeon_mem_types_list[i].driver_features = 0;
39114- if (i == 0)
39115- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
39116- else
39117- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
39118-
39119- }
39120- /* Add ttm page pool to debugfs */
39121- sprintf(radeon_mem_types_names[i], "ttm_page_pool");
39122- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
39123- radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
39124- radeon_mem_types_list[i].driver_features = 0;
39125- radeon_mem_types_list[i++].data = NULL;
39126+ pax_open_kernel();
39127+ *(void **)&radeon_mem_types_list[0].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
39128+ *(void **)&radeon_mem_types_list[1].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
39129+ pax_close_kernel();
39130 #ifdef CONFIG_SWIOTLB
39131- if (swiotlb_nr_tbl()) {
39132- sprintf(radeon_mem_types_names[i], "ttm_dma_page_pool");
39133- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
39134- radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
39135- radeon_mem_types_list[i].driver_features = 0;
39136- radeon_mem_types_list[i++].data = NULL;
39137- }
39138+ if (swiotlb_nr_tbl())
39139+ i++;
39140 #endif
39141 return radeon_debugfs_add_files(rdev, radeon_mem_types_list, i);
39142
39143diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
39144index d8ddfb3..609de1d 100644
39145--- a/drivers/gpu/drm/radeon/rs690.c
39146+++ b/drivers/gpu/drm/radeon/rs690.c
39147@@ -345,9 +345,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
39148 if (max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
39149 rdev->pm.sideport_bandwidth.full)
39150 max_bandwidth = rdev->pm.sideport_bandwidth;
39151- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
39152+ read_delay_latency.full = dfixed_const(800 * 1000);
39153 read_delay_latency.full = dfixed_div(read_delay_latency,
39154 rdev->pm.igp_sideport_mclk);
39155+ a.full = dfixed_const(370);
39156+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
39157 } else {
39158 if (max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
39159 rdev->pm.k8_bandwidth.full)
39160diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
39161index dbc2def..0a9f710 100644
39162--- a/drivers/gpu/drm/ttm/ttm_memory.c
39163+++ b/drivers/gpu/drm/ttm/ttm_memory.c
39164@@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
39165 zone->glob = glob;
39166 glob->zone_kernel = zone;
39167 ret = kobject_init_and_add(
39168- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
39169+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
39170 if (unlikely(ret != 0)) {
39171 kobject_put(&zone->kobj);
39172 return ret;
39173@@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
39174 zone->glob = glob;
39175 glob->zone_dma32 = zone;
39176 ret = kobject_init_and_add(
39177- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
39178+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
39179 if (unlikely(ret != 0)) {
39180 kobject_put(&zone->kobj);
39181 return ret;
39182diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
39183index bd2a3b4..122d9ad 100644
39184--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
39185+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
39186@@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
39187 static int ttm_pool_mm_shrink(struct shrinker *shrink,
39188 struct shrink_control *sc)
39189 {
39190- static atomic_t start_pool = ATOMIC_INIT(0);
39191+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
39192 unsigned i;
39193- unsigned pool_offset = atomic_add_return(1, &start_pool);
39194+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
39195 struct ttm_page_pool *pool;
39196 int shrink_pages = sc->nr_to_scan;
39197
39198diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
39199index 97e9d61..bf23c461 100644
39200--- a/drivers/gpu/drm/udl/udl_fb.c
39201+++ b/drivers/gpu/drm/udl/udl_fb.c
39202@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
39203 fb_deferred_io_cleanup(info);
39204 kfree(info->fbdefio);
39205 info->fbdefio = NULL;
39206- info->fbops->fb_mmap = udl_fb_mmap;
39207 }
39208
39209 pr_warn("released /dev/fb%d user=%d count=%d\n",
39210diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
39211index 893a650..6190d3b 100644
39212--- a/drivers/gpu/drm/via/via_drv.h
39213+++ b/drivers/gpu/drm/via/via_drv.h
39214@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
39215 typedef uint32_t maskarray_t[5];
39216
39217 typedef struct drm_via_irq {
39218- atomic_t irq_received;
39219+ atomic_unchecked_t irq_received;
39220 uint32_t pending_mask;
39221 uint32_t enable_mask;
39222 wait_queue_head_t irq_queue;
39223@@ -75,7 +75,7 @@ typedef struct drm_via_private {
39224 struct timeval last_vblank;
39225 int last_vblank_valid;
39226 unsigned usec_per_vblank;
39227- atomic_t vbl_received;
39228+ atomic_unchecked_t vbl_received;
39229 drm_via_state_t hc_state;
39230 char pci_buf[VIA_PCI_BUF_SIZE];
39231 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
39232diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
39233index ac98964..5dbf512 100644
39234--- a/drivers/gpu/drm/via/via_irq.c
39235+++ b/drivers/gpu/drm/via/via_irq.c
39236@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
39237 if (crtc != 0)
39238 return 0;
39239
39240- return atomic_read(&dev_priv->vbl_received);
39241+ return atomic_read_unchecked(&dev_priv->vbl_received);
39242 }
39243
39244 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39245@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39246
39247 status = VIA_READ(VIA_REG_INTERRUPT);
39248 if (status & VIA_IRQ_VBLANK_PENDING) {
39249- atomic_inc(&dev_priv->vbl_received);
39250- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
39251+ atomic_inc_unchecked(&dev_priv->vbl_received);
39252+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
39253 do_gettimeofday(&cur_vblank);
39254 if (dev_priv->last_vblank_valid) {
39255 dev_priv->usec_per_vblank =
39256@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39257 dev_priv->last_vblank = cur_vblank;
39258 dev_priv->last_vblank_valid = 1;
39259 }
39260- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
39261+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
39262 DRM_DEBUG("US per vblank is: %u\n",
39263 dev_priv->usec_per_vblank);
39264 }
39265@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
39266
39267 for (i = 0; i < dev_priv->num_irqs; ++i) {
39268 if (status & cur_irq->pending_mask) {
39269- atomic_inc(&cur_irq->irq_received);
39270+ atomic_inc_unchecked(&cur_irq->irq_received);
39271 DRM_WAKEUP(&cur_irq->irq_queue);
39272 handled = 1;
39273 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
39274@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
39275 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
39276 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
39277 masks[irq][4]));
39278- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
39279+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
39280 } else {
39281 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
39282 (((cur_irq_sequence =
39283- atomic_read(&cur_irq->irq_received)) -
39284+ atomic_read_unchecked(&cur_irq->irq_received)) -
39285 *sequence) <= (1 << 23)));
39286 }
39287 *sequence = cur_irq_sequence;
39288@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
39289 }
39290
39291 for (i = 0; i < dev_priv->num_irqs; ++i) {
39292- atomic_set(&cur_irq->irq_received, 0);
39293+ atomic_set_unchecked(&cur_irq->irq_received, 0);
39294 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
39295 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
39296 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
39297@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
39298 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
39299 case VIA_IRQ_RELATIVE:
39300 irqwait->request.sequence +=
39301- atomic_read(&cur_irq->irq_received);
39302+ atomic_read_unchecked(&cur_irq->irq_received);
39303 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
39304 case VIA_IRQ_ABSOLUTE:
39305 break;
39306diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
39307index 13aeda7..4a952d1 100644
39308--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
39309+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
39310@@ -290,7 +290,7 @@ struct vmw_private {
39311 * Fencing and IRQs.
39312 */
39313
39314- atomic_t marker_seq;
39315+ atomic_unchecked_t marker_seq;
39316 wait_queue_head_t fence_queue;
39317 wait_queue_head_t fifo_queue;
39318 int fence_queue_waiters; /* Protected by hw_mutex */
39319diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
39320index 3eb1486..0a47ee9 100644
39321--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
39322+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
39323@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
39324 (unsigned int) min,
39325 (unsigned int) fifo->capabilities);
39326
39327- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
39328+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
39329 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
39330 vmw_marker_queue_init(&fifo->marker_queue);
39331 return vmw_fifo_send_fence(dev_priv, &dummy);
39332@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
39333 if (reserveable)
39334 iowrite32(bytes, fifo_mem +
39335 SVGA_FIFO_RESERVED);
39336- return fifo_mem + (next_cmd >> 2);
39337+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
39338 } else {
39339 need_bounce = true;
39340 }
39341@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
39342
39343 fm = vmw_fifo_reserve(dev_priv, bytes);
39344 if (unlikely(fm == NULL)) {
39345- *seqno = atomic_read(&dev_priv->marker_seq);
39346+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
39347 ret = -ENOMEM;
39348 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
39349 false, 3*HZ);
39350@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
39351 }
39352
39353 do {
39354- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
39355+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
39356 } while (*seqno == 0);
39357
39358 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
39359diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
39360index c509d40..3b640c3 100644
39361--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
39362+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
39363@@ -138,7 +138,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
39364 int ret;
39365
39366 num_clips = arg->num_clips;
39367- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
39368+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
39369
39370 if (unlikely(num_clips == 0))
39371 return 0;
39372@@ -222,7 +222,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
39373 int ret;
39374
39375 num_clips = arg->num_clips;
39376- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
39377+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
39378
39379 if (unlikely(num_clips == 0))
39380 return 0;
39381diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
39382index 4640adb..e1384ed 100644
39383--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
39384+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
39385@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
39386 * emitted. Then the fence is stale and signaled.
39387 */
39388
39389- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
39390+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
39391 > VMW_FENCE_WRAP);
39392
39393 return ret;
39394@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
39395
39396 if (fifo_idle)
39397 down_read(&fifo_state->rwsem);
39398- signal_seq = atomic_read(&dev_priv->marker_seq);
39399+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
39400 ret = 0;
39401
39402 for (;;) {
39403diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
39404index 8a8725c2..afed796 100644
39405--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
39406+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
39407@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
39408 while (!vmw_lag_lt(queue, us)) {
39409 spin_lock(&queue->lock);
39410 if (list_empty(&queue->head))
39411- seqno = atomic_read(&dev_priv->marker_seq);
39412+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
39413 else {
39414 marker = list_first_entry(&queue->head,
39415 struct vmw_marker, head);
39416diff --git a/drivers/gpu/host1x/drm/dc.c b/drivers/gpu/host1x/drm/dc.c
39417index 5360e5a..c2c0d26 100644
39418--- a/drivers/gpu/host1x/drm/dc.c
39419+++ b/drivers/gpu/host1x/drm/dc.c
39420@@ -1004,7 +1004,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
39421 }
39422
39423 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
39424- dc->debugfs_files[i].data = dc;
39425+ *(void **)&dc->debugfs_files[i].data = dc;
39426
39427 err = drm_debugfs_create_files(dc->debugfs_files,
39428 ARRAY_SIZE(debugfs_files),
39429diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
39430index 36668d1..9f4ccb0 100644
39431--- a/drivers/hid/hid-core.c
39432+++ b/drivers/hid/hid-core.c
39433@@ -63,6 +63,8 @@ struct hid_report *hid_register_report(struct hid_device *device, unsigned type,
39434 struct hid_report_enum *report_enum = device->report_enum + type;
39435 struct hid_report *report;
39436
39437+ if (id >= HID_MAX_IDS)
39438+ return NULL;
39439 if (report_enum->report_id_hash[id])
39440 return report_enum->report_id_hash[id];
39441
39442@@ -404,8 +406,10 @@ static int hid_parser_global(struct hid_parser *parser, struct hid_item *item)
39443
39444 case HID_GLOBAL_ITEM_TAG_REPORT_ID:
39445 parser->global.report_id = item_udata(item);
39446- if (parser->global.report_id == 0) {
39447- hid_err(parser->device, "report_id 0 is invalid\n");
39448+ if (parser->global.report_id == 0 ||
39449+ parser->global.report_id >= HID_MAX_IDS) {
39450+ hid_err(parser->device, "report_id %u is invalid\n",
39451+ parser->global.report_id);
39452 return -1;
39453 }
39454 return 0;
39455@@ -575,7 +579,7 @@ static void hid_close_report(struct hid_device *device)
39456 for (i = 0; i < HID_REPORT_TYPES; i++) {
39457 struct hid_report_enum *report_enum = device->report_enum + i;
39458
39459- for (j = 0; j < 256; j++) {
39460+ for (j = 0; j < HID_MAX_IDS; j++) {
39461 struct hid_report *report = report_enum->report_id_hash[j];
39462 if (report)
39463 hid_free_report(report);
39464@@ -755,6 +759,56 @@ int hid_parse_report(struct hid_device *hid, __u8 *start, unsigned size)
39465 }
39466 EXPORT_SYMBOL_GPL(hid_parse_report);
39467
39468+static const char * const hid_report_names[] = {
39469+ "HID_INPUT_REPORT",
39470+ "HID_OUTPUT_REPORT",
39471+ "HID_FEATURE_REPORT",
39472+};
39473+/**
39474+ * hid_validate_report - validate existing device report
39475+ *
39476+ * @device: hid device
39477+ * @type: which report type to examine
39478+ * @id: which report ID to examine (0 for first)
39479+ * @fields: expected number of fields
39480+ * @report_counts: expected number of values per field
39481+ *
39482+ * Validate the report details after parsing.
39483+ */
39484+struct hid_report *hid_validate_report(struct hid_device *hid,
39485+ unsigned int type, unsigned int id,
39486+ unsigned int fields,
39487+ unsigned int report_counts)
39488+{
39489+ struct hid_report *report;
39490+ unsigned int i;
39491+
39492+ if (type > HID_FEATURE_REPORT) {
39493+ hid_err(hid, "invalid HID report %u\n", type);
39494+ return NULL;
39495+ }
39496+
39497+ report = hid->report_enum[type].report_id_hash[id];
39498+ if (!report) {
39499+ hid_err(hid, "missing %s %u\n", hid_report_names[type], id);
39500+ return NULL;
39501+ }
39502+ if (report->maxfield < fields) {
39503+ hid_err(hid, "not enough fields in %s %u\n",
39504+ hid_report_names[type], id);
39505+ return NULL;
39506+ }
39507+ for (i = 0; i < fields; i++) {
39508+ if (report->field[i]->report_count < report_counts) {
39509+ hid_err(hid, "not enough values in %s %u fields\n",
39510+ hid_report_names[type], id);
39511+ return NULL;
39512+ }
39513+ }
39514+ return report;
39515+}
39516+EXPORT_SYMBOL_GPL(hid_validate_report);
39517+
39518 /**
39519 * hid_open_report - open a driver-specific device report
39520 *
39521@@ -1152,7 +1206,12 @@ EXPORT_SYMBOL_GPL(hid_output_report);
39522
39523 int hid_set_field(struct hid_field *field, unsigned offset, __s32 value)
39524 {
39525- unsigned size = field->report_size;
39526+ unsigned size;
39527+
39528+ if (!field)
39529+ return -1;
39530+
39531+ size = field->report_size;
39532
39533 hid_dump_input(field->report->device, field->usage + offset, value);
39534
39535@@ -2285,7 +2344,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
39536
39537 int hid_add_device(struct hid_device *hdev)
39538 {
39539- static atomic_t id = ATOMIC_INIT(0);
39540+ static atomic_unchecked_t id = ATOMIC_INIT(0);
39541 int ret;
39542
39543 if (WARN_ON(hdev->status & HID_STAT_ADDED))
39544@@ -2319,7 +2378,7 @@ int hid_add_device(struct hid_device *hdev)
39545 /* XXX hack, any other cleaner solution after the driver core
39546 * is converted to allow more than 20 bytes as the device name? */
39547 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
39548- hdev->vendor, hdev->product, atomic_inc_return(&id));
39549+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
39550
39551 hid_debug_register(hdev, dev_name(&hdev->dev));
39552 ret = device_add(&hdev->dev);
39553diff --git a/drivers/hid/hid-lenovo-tpkbd.c b/drivers/hid/hid-lenovo-tpkbd.c
39554index 07837f5..b697ada 100644
39555--- a/drivers/hid/hid-lenovo-tpkbd.c
39556+++ b/drivers/hid/hid-lenovo-tpkbd.c
39557@@ -341,6 +341,11 @@ static int tpkbd_probe_tp(struct hid_device *hdev)
39558 char *name_mute, *name_micmute;
39559 int ret;
39560
39561+ /* Validate required reports. */
39562+ if (!hid_validate_report(hdev, HID_OUTPUT_REPORT, 4, 4, 1) ||
39563+ !hid_validate_report(hdev, HID_OUTPUT_REPORT, 3, 1, 2))
39564+ return -ENODEV;
39565+
39566 if (sysfs_create_group(&hdev->dev.kobj,
39567 &tpkbd_attr_group_pointer)) {
39568 hid_warn(hdev, "Could not create sysfs group\n");
39569diff --git a/drivers/hid/hid-lg2ff.c b/drivers/hid/hid-lg2ff.c
39570index b3cd150..9805197 100644
39571--- a/drivers/hid/hid-lg2ff.c
39572+++ b/drivers/hid/hid-lg2ff.c
39573@@ -64,26 +64,13 @@ int lg2ff_init(struct hid_device *hid)
39574 struct hid_report *report;
39575 struct hid_input *hidinput = list_entry(hid->inputs.next,
39576 struct hid_input, list);
39577- struct list_head *report_list =
39578- &hid->report_enum[HID_OUTPUT_REPORT].report_list;
39579 struct input_dev *dev = hidinput->input;
39580 int error;
39581
39582- if (list_empty(report_list)) {
39583- hid_err(hid, "no output report found\n");
39584+ /* Check that the report looks ok */
39585+ report = hid_validate_report(hid, HID_OUTPUT_REPORT, 0, 1, 7);
39586+ if (!report)
39587 return -ENODEV;
39588- }
39589-
39590- report = list_entry(report_list->next, struct hid_report, list);
39591-
39592- if (report->maxfield < 1) {
39593- hid_err(hid, "output report is empty\n");
39594- return -ENODEV;
39595- }
39596- if (report->field[0]->report_count < 7) {
39597- hid_err(hid, "not enough values in the field\n");
39598- return -ENODEV;
39599- }
39600
39601 lg2ff = kmalloc(sizeof(struct lg2ff_device), GFP_KERNEL);
39602 if (!lg2ff)
39603diff --git a/drivers/hid/hid-lg3ff.c b/drivers/hid/hid-lg3ff.c
39604index e52f181..53ac79b 100644
39605--- a/drivers/hid/hid-lg3ff.c
39606+++ b/drivers/hid/hid-lg3ff.c
39607@@ -66,10 +66,11 @@ static int hid_lg3ff_play(struct input_dev *dev, void *data,
39608 int x, y;
39609
39610 /*
39611- * Maxusage should always be 63 (maximum fields)
39612- * likely a better way to ensure this data is clean
39613+ * Available values in the field should always be 63, but we only use up to
39614+ * 35. Instead, clear the entire area, however big it is.
39615 */
39616- memset(report->field[0]->value, 0, sizeof(__s32)*report->field[0]->maxusage);
39617+ memset(report->field[0]->value, 0,
39618+ sizeof(__s32) * report->field[0]->report_count);
39619
39620 switch (effect->type) {
39621 case FF_CONSTANT:
39622@@ -129,32 +130,14 @@ static const signed short ff3_joystick_ac[] = {
39623 int lg3ff_init(struct hid_device *hid)
39624 {
39625 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
39626- struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list;
39627 struct input_dev *dev = hidinput->input;
39628- struct hid_report *report;
39629- struct hid_field *field;
39630 const signed short *ff_bits = ff3_joystick_ac;
39631 int error;
39632 int i;
39633
39634- /* Find the report to use */
39635- if (list_empty(report_list)) {
39636- hid_err(hid, "No output report found\n");
39637- return -1;
39638- }
39639-
39640 /* Check that the report looks ok */
39641- report = list_entry(report_list->next, struct hid_report, list);
39642- if (!report) {
39643- hid_err(hid, "NULL output report\n");
39644- return -1;
39645- }
39646-
39647- field = report->field[0];
39648- if (!field) {
39649- hid_err(hid, "NULL field\n");
39650- return -1;
39651- }
39652+ if (!hid_validate_report(hid, HID_OUTPUT_REPORT, 0, 1, 35))
39653+ return -ENODEV;
39654
39655 /* Assume single fixed device G940 */
39656 for (i = 0; ff_bits[i] >= 0; i++)
39657diff --git a/drivers/hid/hid-lg4ff.c b/drivers/hid/hid-lg4ff.c
39658index 0ddae2a..8b89f0f 100644
39659--- a/drivers/hid/hid-lg4ff.c
39660+++ b/drivers/hid/hid-lg4ff.c
39661@@ -484,34 +484,16 @@ static enum led_brightness lg4ff_led_get_brightness(struct led_classdev *led_cde
39662 int lg4ff_init(struct hid_device *hid)
39663 {
39664 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
39665- struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list;
39666 struct input_dev *dev = hidinput->input;
39667- struct hid_report *report;
39668- struct hid_field *field;
39669 struct lg4ff_device_entry *entry;
39670 struct lg_drv_data *drv_data;
39671 struct usb_device_descriptor *udesc;
39672 int error, i, j;
39673 __u16 bcdDevice, rev_maj, rev_min;
39674
39675- /* Find the report to use */
39676- if (list_empty(report_list)) {
39677- hid_err(hid, "No output report found\n");
39678- return -1;
39679- }
39680-
39681 /* Check that the report looks ok */
39682- report = list_entry(report_list->next, struct hid_report, list);
39683- if (!report) {
39684- hid_err(hid, "NULL output report\n");
39685+ if (!hid_validate_report(hid, HID_OUTPUT_REPORT, 0, 1, 7))
39686 return -1;
39687- }
39688-
39689- field = report->field[0];
39690- if (!field) {
39691- hid_err(hid, "NULL field\n");
39692- return -1;
39693- }
39694
39695 /* Check what wheel has been connected */
39696 for (i = 0; i < ARRAY_SIZE(lg4ff_devices); i++) {
39697diff --git a/drivers/hid/hid-lgff.c b/drivers/hid/hid-lgff.c
39698index d7ea8c8..a84fb40 100644
39699--- a/drivers/hid/hid-lgff.c
39700+++ b/drivers/hid/hid-lgff.c
39701@@ -128,27 +128,14 @@ static void hid_lgff_set_autocenter(struct input_dev *dev, u16 magnitude)
39702 int lgff_init(struct hid_device* hid)
39703 {
39704 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
39705- struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list;
39706 struct input_dev *dev = hidinput->input;
39707- struct hid_report *report;
39708- struct hid_field *field;
39709 const signed short *ff_bits = ff_joystick;
39710 int error;
39711 int i;
39712
39713- /* Find the report to use */
39714- if (list_empty(report_list)) {
39715- hid_err(hid, "No output report found\n");
39716- return -1;
39717- }
39718-
39719 /* Check that the report looks ok */
39720- report = list_entry(report_list->next, struct hid_report, list);
39721- field = report->field[0];
39722- if (!field) {
39723- hid_err(hid, "NULL field\n");
39724- return -1;
39725- }
39726+ if (!hid_validate_report(hid, HID_OUTPUT_REPORT, 0, 1, 7))
39727+ return -ENODEV;
39728
39729 for (i = 0; i < ARRAY_SIZE(devices); i++) {
39730 if (dev->id.vendor == devices[i].idVendor &&
39731diff --git a/drivers/hid/hid-logitech-dj.c b/drivers/hid/hid-logitech-dj.c
39732index cd33084..7b99c2a 100644
39733--- a/drivers/hid/hid-logitech-dj.c
39734+++ b/drivers/hid/hid-logitech-dj.c
39735@@ -461,7 +461,7 @@ static int logi_dj_recv_send_report(struct dj_receiver_dev *djrcv_dev,
39736 struct hid_report *report;
39737 struct hid_report_enum *output_report_enum;
39738 u8 *data = (u8 *)(&dj_report->device_index);
39739- int i;
39740+ unsigned int i, length;
39741
39742 output_report_enum = &hdev->report_enum[HID_OUTPUT_REPORT];
39743 report = output_report_enum->report_id_hash[REPORT_ID_DJ_SHORT];
39744@@ -471,7 +471,9 @@ static int logi_dj_recv_send_report(struct dj_receiver_dev *djrcv_dev,
39745 return -ENODEV;
39746 }
39747
39748- for (i = 0; i < report->field[0]->report_count; i++)
39749+ length = min_t(size_t, sizeof(*dj_report) - 1,
39750+ report->field[0]->report_count);
39751+ for (i = 0; i < length; i++)
39752 report->field[0]->value[i] = data[i];
39753
39754 hid_hw_request(hdev, report, HID_REQ_SET_REPORT);
39755@@ -783,6 +785,12 @@ static int logi_dj_probe(struct hid_device *hdev,
39756 goto hid_parse_fail;
39757 }
39758
39759+ if (!hid_validate_report(hdev, HID_OUTPUT_REPORT, REPORT_ID_DJ_SHORT,
39760+ 1, 3)) {
39761+ retval = -ENODEV;
39762+ goto hid_parse_fail;
39763+ }
39764+
39765 /* Starts the usb device and connects to upper interfaces hiddev and
39766 * hidraw */
39767 retval = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
39768diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c
39769index cb0e361..2aa275e 100644
39770--- a/drivers/hid/hid-multitouch.c
39771+++ b/drivers/hid/hid-multitouch.c
39772@@ -330,9 +330,18 @@ static void mt_feature_mapping(struct hid_device *hdev,
39773 break;
39774 }
39775 }
39776+ /* Ignore if value index is out of bounds. */
39777+ if (td->inputmode_index < 0 ||
39778+ td->inputmode_index >= field->report_count) {
39779+ dev_err(&hdev->dev, "HID_DG_INPUTMODE out of range\n");
39780+ td->inputmode = -1;
39781+ }
39782
39783 break;
39784 case HID_DG_CONTACTMAX:
39785+ /* Ignore if value count is out of bounds. */
39786+ if (field->report_count < 1)
39787+ break;
39788 td->maxcontact_report_id = field->report->id;
39789 td->maxcontacts = field->value[0];
39790 if (!td->maxcontacts &&
39791@@ -743,15 +752,21 @@ static void mt_touch_report(struct hid_device *hid, struct hid_report *report)
39792 unsigned count;
39793 int r, n;
39794
39795+ if (report->maxfield == 0)
39796+ return;
39797+
39798 /*
39799 * Includes multi-packet support where subsequent
39800 * packets are sent with zero contactcount.
39801 */
39802- if (td->cc_index >= 0) {
39803- struct hid_field *field = report->field[td->cc_index];
39804- int value = field->value[td->cc_value_index];
39805- if (value)
39806- td->num_expected = value;
39807+ if (td->cc_index >= 0 && td->cc_index < report->maxfield) {
39808+ field = report->field[td->cc_index];
39809+ if (td->cc_value_index >= 0 &&
39810+ td->cc_value_index < field->report_count) {
39811+ int value = field->value[td->cc_value_index];
39812+ if (value)
39813+ td->num_expected = value;
39814+ }
39815 }
39816
39817 for (r = 0; r < report->maxfield; r++) {
39818diff --git a/drivers/hid/hid-ntrig.c b/drivers/hid/hid-ntrig.c
39819index ef95102..5482156 100644
39820--- a/drivers/hid/hid-ntrig.c
39821+++ b/drivers/hid/hid-ntrig.c
39822@@ -115,7 +115,8 @@ static inline int ntrig_get_mode(struct hid_device *hdev)
39823 struct hid_report *report = hdev->report_enum[HID_FEATURE_REPORT].
39824 report_id_hash[0x0d];
39825
39826- if (!report)
39827+ if (!report || report->maxfield < 1 ||
39828+ report->field[0]->report_count < 1)
39829 return -EINVAL;
39830
39831 hid_hw_request(hdev, report, HID_REQ_GET_REPORT);
39832diff --git a/drivers/hid/hid-picolcd_core.c b/drivers/hid/hid-picolcd_core.c
39833index b48092d..72bba1e 100644
39834--- a/drivers/hid/hid-picolcd_core.c
39835+++ b/drivers/hid/hid-picolcd_core.c
39836@@ -290,7 +290,7 @@ static ssize_t picolcd_operation_mode_store(struct device *dev,
39837 buf += 10;
39838 cnt -= 10;
39839 }
39840- if (!report)
39841+ if (!report || report->maxfield < 1)
39842 return -EINVAL;
39843
39844 while (cnt > 0 && (buf[cnt-1] == '\n' || buf[cnt-1] == '\r'))
39845diff --git a/drivers/hid/hid-pl.c b/drivers/hid/hid-pl.c
39846index d29112f..2dcd7d9 100644
39847--- a/drivers/hid/hid-pl.c
39848+++ b/drivers/hid/hid-pl.c
39849@@ -132,8 +132,14 @@ static int plff_init(struct hid_device *hid)
39850 strong = &report->field[0]->value[2];
39851 weak = &report->field[0]->value[3];
39852 debug("detected single-field device");
39853- } else if (report->maxfield >= 4 && report->field[0]->maxusage == 1 &&
39854- report->field[0]->usage[0].hid == (HID_UP_LED | 0x43)) {
39855+ } else if (report->field[0]->maxusage == 1 &&
39856+ report->field[0]->usage[0].hid ==
39857+ (HID_UP_LED | 0x43) &&
39858+ report->maxfield >= 4 &&
39859+ report->field[0]->report_count >= 1 &&
39860+ report->field[1]->report_count >= 1 &&
39861+ report->field[2]->report_count >= 1 &&
39862+ report->field[3]->report_count >= 1) {
39863 report->field[0]->value[0] = 0x00;
39864 report->field[1]->value[0] = 0x00;
39865 strong = &report->field[2]->value[0];
39866diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c
39867index ca749810..aa34755 100644
39868--- a/drivers/hid/hid-sensor-hub.c
39869+++ b/drivers/hid/hid-sensor-hub.c
39870@@ -221,7 +221,8 @@ int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
39871
39872 mutex_lock(&data->mutex);
39873 report = sensor_hub_report(report_id, hsdev->hdev, HID_FEATURE_REPORT);
39874- if (!report || (field_index >= report->maxfield)) {
39875+ if (!report || (field_index >= report->maxfield) ||
39876+ report->field[field_index]->report_count < 1) {
39877 ret = -EINVAL;
39878 goto done_proc;
39879 }
39880diff --git a/drivers/hid/hid-steelseries.c b/drivers/hid/hid-steelseries.c
39881index d164911..ef42e86 100644
39882--- a/drivers/hid/hid-steelseries.c
39883+++ b/drivers/hid/hid-steelseries.c
39884@@ -249,6 +249,11 @@ static int steelseries_srws1_probe(struct hid_device *hdev,
39885 goto err_free;
39886 }
39887
39888+ if (!hid_validate_report(hdev, HID_OUTPUT_REPORT, 0, 1, 16)) {
39889+ ret = -ENODEV;
39890+ goto err_free;
39891+ }
39892+
39893 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
39894 if (ret) {
39895 hid_err(hdev, "hw start failed\n");
39896diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
39897index c13fb5b..55a3802 100644
39898--- a/drivers/hid/hid-wiimote-debug.c
39899+++ b/drivers/hid/hid-wiimote-debug.c
39900@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
39901 else if (size == 0)
39902 return -EIO;
39903
39904- if (copy_to_user(u, buf, size))
39905+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
39906 return -EFAULT;
39907
39908 *off += size;
39909diff --git a/drivers/hid/hid-zpff.c b/drivers/hid/hid-zpff.c
39910index 6ec28a3..b124991 100644
39911--- a/drivers/hid/hid-zpff.c
39912+++ b/drivers/hid/hid-zpff.c
39913@@ -68,22 +68,12 @@ static int zpff_init(struct hid_device *hid)
39914 struct hid_report *report;
39915 struct hid_input *hidinput = list_entry(hid->inputs.next,
39916 struct hid_input, list);
39917- struct list_head *report_list =
39918- &hid->report_enum[HID_OUTPUT_REPORT].report_list;
39919 struct input_dev *dev = hidinput->input;
39920 int error;
39921
39922- if (list_empty(report_list)) {
39923- hid_err(hid, "no output report found\n");
39924+ report = hid_validate_report(hid, HID_OUTPUT_REPORT, 0, 4, 1);
39925+ if (!report)
39926 return -ENODEV;
39927- }
39928-
39929- report = list_entry(report_list->next, struct hid_report, list);
39930-
39931- if (report->maxfield < 4) {
39932- hid_err(hid, "not enough fields in report\n");
39933- return -ENODEV;
39934- }
39935
39936 zpff = kzalloc(sizeof(struct zpff_device), GFP_KERNEL);
39937 if (!zpff)
39938diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
39939index fc307e0..2b255e8 100644
39940--- a/drivers/hid/uhid.c
39941+++ b/drivers/hid/uhid.c
39942@@ -47,7 +47,7 @@ struct uhid_device {
39943 struct mutex report_lock;
39944 wait_queue_head_t report_wait;
39945 atomic_t report_done;
39946- atomic_t report_id;
39947+ atomic_unchecked_t report_id;
39948 struct uhid_event report_buf;
39949 };
39950
39951@@ -187,7 +187,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
39952
39953 spin_lock_irqsave(&uhid->qlock, flags);
39954 ev->type = UHID_FEATURE;
39955- ev->u.feature.id = atomic_inc_return(&uhid->report_id);
39956+ ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
39957 ev->u.feature.rnum = rnum;
39958 ev->u.feature.rtype = report_type;
39959
39960@@ -471,7 +471,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
39961 spin_lock_irqsave(&uhid->qlock, flags);
39962
39963 /* id for old report; drop it silently */
39964- if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
39965+ if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
39966 goto unlock;
39967 if (atomic_read(&uhid->report_done))
39968 goto unlock;
39969diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
39970index 6de6c98..18319e9 100644
39971--- a/drivers/hv/channel.c
39972+++ b/drivers/hv/channel.c
39973@@ -406,8 +406,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
39974 int ret = 0;
39975 int t;
39976
39977- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
39978- atomic_inc(&vmbus_connection.next_gpadl_handle);
39979+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
39980+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
39981
39982 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
39983 if (ret)
39984diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
39985index 88f4096..e50452e 100644
39986--- a/drivers/hv/hv.c
39987+++ b/drivers/hv/hv.c
39988@@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
39989 u64 output_address = (output) ? virt_to_phys(output) : 0;
39990 u32 output_address_hi = output_address >> 32;
39991 u32 output_address_lo = output_address & 0xFFFFFFFF;
39992- void *hypercall_page = hv_context.hypercall_page;
39993+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
39994
39995 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
39996 "=a"(hv_status_lo) : "d" (control_hi),
39997diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
39998index deb5c25..ed2d4fd 100644
39999--- a/drivers/hv/hv_balloon.c
40000+++ b/drivers/hv/hv_balloon.c
40001@@ -464,7 +464,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
40002
40003 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
40004 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
40005-static atomic_t trans_id = ATOMIC_INIT(0);
40006+static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
40007
40008 static int dm_ring_size = (5 * PAGE_SIZE);
40009
40010@@ -825,7 +825,7 @@ static void hot_add_req(struct work_struct *dummy)
40011 memset(&resp, 0, sizeof(struct dm_hot_add_response));
40012 resp.hdr.type = DM_MEM_HOT_ADD_RESPONSE;
40013 resp.hdr.size = sizeof(struct dm_hot_add_response);
40014- resp.hdr.trans_id = atomic_inc_return(&trans_id);
40015+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40016
40017 #ifdef CONFIG_MEMORY_HOTPLUG
40018 pg_start = dm->ha_wrk.ha_page_range.finfo.start_page;
40019@@ -960,7 +960,7 @@ static void post_status(struct hv_dynmem_device *dm)
40020 memset(&status, 0, sizeof(struct dm_status));
40021 status.hdr.type = DM_STATUS_REPORT;
40022 status.hdr.size = sizeof(struct dm_status);
40023- status.hdr.trans_id = atomic_inc_return(&trans_id);
40024+ status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40025
40026 /*
40027 * The host expects the guest to report free memory.
40028@@ -980,7 +980,7 @@ static void post_status(struct hv_dynmem_device *dm)
40029 * send the status. This can happen if we were interrupted
40030 * after we picked our transaction ID.
40031 */
40032- if (status.hdr.trans_id != atomic_read(&trans_id))
40033+ if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
40034 return;
40035
40036 vmbus_sendpacket(dm->dev->channel, &status,
40037@@ -1081,7 +1081,7 @@ static void balloon_up(struct work_struct *dummy)
40038 bl_resp = (struct dm_balloon_response *)send_buffer;
40039 memset(send_buffer, 0, PAGE_SIZE);
40040 bl_resp->hdr.type = DM_BALLOON_RESPONSE;
40041- bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
40042+ bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40043 bl_resp->hdr.size = sizeof(struct dm_balloon_response);
40044 bl_resp->more_pages = 1;
40045
40046@@ -1152,7 +1152,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
40047
40048 memset(&resp, 0, sizeof(struct dm_unballoon_response));
40049 resp.hdr.type = DM_UNBALLOON_RESPONSE;
40050- resp.hdr.trans_id = atomic_inc_return(&trans_id);
40051+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40052 resp.hdr.size = sizeof(struct dm_unballoon_response);
40053
40054 vmbus_sendpacket(dm_device.dev->channel, &resp,
40055@@ -1215,7 +1215,7 @@ static void version_resp(struct hv_dynmem_device *dm,
40056 memset(&version_req, 0, sizeof(struct dm_version_request));
40057 version_req.hdr.type = DM_VERSION_REQUEST;
40058 version_req.hdr.size = sizeof(struct dm_version_request);
40059- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
40060+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40061 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
40062 version_req.is_last_attempt = 1;
40063
40064@@ -1385,7 +1385,7 @@ static int balloon_probe(struct hv_device *dev,
40065 memset(&version_req, 0, sizeof(struct dm_version_request));
40066 version_req.hdr.type = DM_VERSION_REQUEST;
40067 version_req.hdr.size = sizeof(struct dm_version_request);
40068- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
40069+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40070 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
40071 version_req.is_last_attempt = 0;
40072
40073@@ -1416,7 +1416,7 @@ static int balloon_probe(struct hv_device *dev,
40074 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
40075 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
40076 cap_msg.hdr.size = sizeof(struct dm_capabilities);
40077- cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
40078+ cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40079
40080 cap_msg.caps.cap_bits.balloon = 1;
40081 cap_msg.caps.cap_bits.hot_add = 1;
40082diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
40083index d84918f..7f38f9f 100644
40084--- a/drivers/hv/hyperv_vmbus.h
40085+++ b/drivers/hv/hyperv_vmbus.h
40086@@ -595,7 +595,7 @@ enum vmbus_connect_state {
40087 struct vmbus_connection {
40088 enum vmbus_connect_state conn_state;
40089
40090- atomic_t next_gpadl_handle;
40091+ atomic_unchecked_t next_gpadl_handle;
40092
40093 /*
40094 * Represents channel interrupts. Each bit position represents a
40095diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
40096index e8e071f..5b4b245 100644
40097--- a/drivers/hv/vmbus_drv.c
40098+++ b/drivers/hv/vmbus_drv.c
40099@@ -672,10 +672,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
40100 {
40101 int ret = 0;
40102
40103- static atomic_t device_num = ATOMIC_INIT(0);
40104+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
40105
40106 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
40107- atomic_inc_return(&device_num));
40108+ atomic_inc_return_unchecked(&device_num));
40109
40110 child_device_obj->device.bus = &hv_bus;
40111 child_device_obj->device.parent = &hv_acpi_dev->dev;
40112diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
40113index 6351aba..dc4aaf4 100644
40114--- a/drivers/hwmon/acpi_power_meter.c
40115+++ b/drivers/hwmon/acpi_power_meter.c
40116@@ -117,7 +117,7 @@ struct sensor_template {
40117 struct device_attribute *devattr,
40118 const char *buf, size_t count);
40119 int index;
40120-};
40121+} __do_const;
40122
40123 /* Averaging interval */
40124 static int update_avg_interval(struct acpi_power_meter_resource *resource)
40125@@ -629,7 +629,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
40126 struct sensor_template *attrs)
40127 {
40128 struct device *dev = &resource->acpi_dev->dev;
40129- struct sensor_device_attribute *sensors =
40130+ sensor_device_attribute_no_const *sensors =
40131 &resource->sensors[resource->num_sensors];
40132 int res = 0;
40133
40134diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
40135index 62c2e32..8f2859a 100644
40136--- a/drivers/hwmon/applesmc.c
40137+++ b/drivers/hwmon/applesmc.c
40138@@ -1084,7 +1084,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
40139 {
40140 struct applesmc_node_group *grp;
40141 struct applesmc_dev_attr *node;
40142- struct attribute *attr;
40143+ attribute_no_const *attr;
40144 int ret, i;
40145
40146 for (grp = groups; grp->format; grp++) {
40147diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
40148index b25c643..a13460d 100644
40149--- a/drivers/hwmon/asus_atk0110.c
40150+++ b/drivers/hwmon/asus_atk0110.c
40151@@ -152,10 +152,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
40152 struct atk_sensor_data {
40153 struct list_head list;
40154 struct atk_data *data;
40155- struct device_attribute label_attr;
40156- struct device_attribute input_attr;
40157- struct device_attribute limit1_attr;
40158- struct device_attribute limit2_attr;
40159+ device_attribute_no_const label_attr;
40160+ device_attribute_no_const input_attr;
40161+ device_attribute_no_const limit1_attr;
40162+ device_attribute_no_const limit2_attr;
40163 char label_attr_name[ATTR_NAME_SIZE];
40164 char input_attr_name[ATTR_NAME_SIZE];
40165 char limit1_attr_name[ATTR_NAME_SIZE];
40166@@ -275,7 +275,7 @@ static ssize_t atk_name_show(struct device *dev,
40167 static struct device_attribute atk_name_attr =
40168 __ATTR(name, 0444, atk_name_show, NULL);
40169
40170-static void atk_init_attribute(struct device_attribute *attr, char *name,
40171+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
40172 sysfs_show_func show)
40173 {
40174 sysfs_attr_init(&attr->attr);
40175diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
40176index 2e5e2dc..5208b31 100644
40177--- a/drivers/hwmon/coretemp.c
40178+++ b/drivers/hwmon/coretemp.c
40179@@ -785,7 +785,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
40180 return NOTIFY_OK;
40181 }
40182
40183-static struct notifier_block coretemp_cpu_notifier __refdata = {
40184+static struct notifier_block coretemp_cpu_notifier = {
40185 .notifier_call = coretemp_cpu_callback,
40186 };
40187
40188diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
40189index 1429f6e..ee03d59 100644
40190--- a/drivers/hwmon/ibmaem.c
40191+++ b/drivers/hwmon/ibmaem.c
40192@@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
40193 struct aem_rw_sensor_template *rw)
40194 {
40195 struct device *dev = &data->pdev->dev;
40196- struct sensor_device_attribute *sensors = data->sensors;
40197+ sensor_device_attribute_no_const *sensors = data->sensors;
40198 int err;
40199
40200 /* Set up read-only sensors */
40201diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
40202index 708081b..fe2d4ab 100644
40203--- a/drivers/hwmon/iio_hwmon.c
40204+++ b/drivers/hwmon/iio_hwmon.c
40205@@ -73,7 +73,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
40206 {
40207 struct device *dev = &pdev->dev;
40208 struct iio_hwmon_state *st;
40209- struct sensor_device_attribute *a;
40210+ sensor_device_attribute_no_const *a;
40211 int ret, i;
40212 int in_i = 1, temp_i = 1, curr_i = 1;
40213 enum iio_chan_type type;
40214diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
40215index 9add6092..ee7ba3f 100644
40216--- a/drivers/hwmon/pmbus/pmbus_core.c
40217+++ b/drivers/hwmon/pmbus/pmbus_core.c
40218@@ -781,7 +781,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
40219 return 0;
40220 }
40221
40222-static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
40223+static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
40224 const char *name,
40225 umode_t mode,
40226 ssize_t (*show)(struct device *dev,
40227@@ -798,7 +798,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
40228 dev_attr->store = store;
40229 }
40230
40231-static void pmbus_attr_init(struct sensor_device_attribute *a,
40232+static void pmbus_attr_init(sensor_device_attribute_no_const *a,
40233 const char *name,
40234 umode_t mode,
40235 ssize_t (*show)(struct device *dev,
40236@@ -820,7 +820,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
40237 u16 reg, u8 mask)
40238 {
40239 struct pmbus_boolean *boolean;
40240- struct sensor_device_attribute *a;
40241+ sensor_device_attribute_no_const *a;
40242
40243 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
40244 if (!boolean)
40245@@ -845,7 +845,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
40246 bool update, bool readonly)
40247 {
40248 struct pmbus_sensor *sensor;
40249- struct device_attribute *a;
40250+ device_attribute_no_const *a;
40251
40252 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
40253 if (!sensor)
40254@@ -876,7 +876,7 @@ static int pmbus_add_label(struct pmbus_data *data,
40255 const char *lstring, int index)
40256 {
40257 struct pmbus_label *label;
40258- struct device_attribute *a;
40259+ device_attribute_no_const *a;
40260
40261 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
40262 if (!label)
40263diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
40264index 2507f90..1645765 100644
40265--- a/drivers/hwmon/sht15.c
40266+++ b/drivers/hwmon/sht15.c
40267@@ -169,7 +169,7 @@ struct sht15_data {
40268 int supply_uv;
40269 bool supply_uv_valid;
40270 struct work_struct update_supply_work;
40271- atomic_t interrupt_handled;
40272+ atomic_unchecked_t interrupt_handled;
40273 };
40274
40275 /**
40276@@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
40277 ret = gpio_direction_input(data->pdata->gpio_data);
40278 if (ret)
40279 return ret;
40280- atomic_set(&data->interrupt_handled, 0);
40281+ atomic_set_unchecked(&data->interrupt_handled, 0);
40282
40283 enable_irq(gpio_to_irq(data->pdata->gpio_data));
40284 if (gpio_get_value(data->pdata->gpio_data) == 0) {
40285 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
40286 /* Only relevant if the interrupt hasn't occurred. */
40287- if (!atomic_read(&data->interrupt_handled))
40288+ if (!atomic_read_unchecked(&data->interrupt_handled))
40289 schedule_work(&data->read_work);
40290 }
40291 ret = wait_event_timeout(data->wait_queue,
40292@@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
40293
40294 /* First disable the interrupt */
40295 disable_irq_nosync(irq);
40296- atomic_inc(&data->interrupt_handled);
40297+ atomic_inc_unchecked(&data->interrupt_handled);
40298 /* Then schedule a reading work struct */
40299 if (data->state != SHT15_READING_NOTHING)
40300 schedule_work(&data->read_work);
40301@@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
40302 * If not, then start the interrupt again - care here as could
40303 * have gone low in meantime so verify it hasn't!
40304 */
40305- atomic_set(&data->interrupt_handled, 0);
40306+ atomic_set_unchecked(&data->interrupt_handled, 0);
40307 enable_irq(gpio_to_irq(data->pdata->gpio_data));
40308 /* If still not occurred or another handler was scheduled */
40309 if (gpio_get_value(data->pdata->gpio_data)
40310- || atomic_read(&data->interrupt_handled))
40311+ || atomic_read_unchecked(&data->interrupt_handled))
40312 return;
40313 }
40314
40315diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
40316index 38944e9..ae9e5ed 100644
40317--- a/drivers/hwmon/via-cputemp.c
40318+++ b/drivers/hwmon/via-cputemp.c
40319@@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
40320 return NOTIFY_OK;
40321 }
40322
40323-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
40324+static struct notifier_block via_cputemp_cpu_notifier = {
40325 .notifier_call = via_cputemp_cpu_callback,
40326 };
40327
40328diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
40329index 07f01ac..d79ad3d 100644
40330--- a/drivers/i2c/busses/i2c-amd756-s4882.c
40331+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
40332@@ -43,7 +43,7 @@
40333 extern struct i2c_adapter amd756_smbus;
40334
40335 static struct i2c_adapter *s4882_adapter;
40336-static struct i2c_algorithm *s4882_algo;
40337+static i2c_algorithm_no_const *s4882_algo;
40338
40339 /* Wrapper access functions for multiplexed SMBus */
40340 static DEFINE_MUTEX(amd756_lock);
40341diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
40342index 2ca268d..c6acbdf 100644
40343--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
40344+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
40345@@ -41,7 +41,7 @@
40346 extern struct i2c_adapter *nforce2_smbus;
40347
40348 static struct i2c_adapter *s4985_adapter;
40349-static struct i2c_algorithm *s4985_algo;
40350+static i2c_algorithm_no_const *s4985_algo;
40351
40352 /* Wrapper access functions for multiplexed SMBus */
40353 static DEFINE_MUTEX(nforce2_lock);
40354diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
40355index c3ccdea..5b3dc1a 100644
40356--- a/drivers/i2c/i2c-dev.c
40357+++ b/drivers/i2c/i2c-dev.c
40358@@ -271,7 +271,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
40359 break;
40360 }
40361
40362- data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
40363+ data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
40364 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
40365 if (IS_ERR(rdwr_pa[i].buf)) {
40366 res = PTR_ERR(rdwr_pa[i].buf);
40367diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
40368index 0b510ba..4fbb5085 100644
40369--- a/drivers/ide/ide-cd.c
40370+++ b/drivers/ide/ide-cd.c
40371@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
40372 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
40373 if ((unsigned long)buf & alignment
40374 || blk_rq_bytes(rq) & q->dma_pad_mask
40375- || object_is_on_stack(buf))
40376+ || object_starts_on_stack(buf))
40377 drive->dma = 0;
40378 }
40379 }
40380diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
40381index e145931..08bfc59 100644
40382--- a/drivers/iio/industrialio-core.c
40383+++ b/drivers/iio/industrialio-core.c
40384@@ -506,7 +506,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
40385 }
40386
40387 static
40388-int __iio_device_attr_init(struct device_attribute *dev_attr,
40389+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
40390 const char *postfix,
40391 struct iio_chan_spec const *chan,
40392 ssize_t (*readfunc)(struct device *dev,
40393diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
40394index 784b97c..c9ceadf 100644
40395--- a/drivers/infiniband/core/cm.c
40396+++ b/drivers/infiniband/core/cm.c
40397@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
40398
40399 struct cm_counter_group {
40400 struct kobject obj;
40401- atomic_long_t counter[CM_ATTR_COUNT];
40402+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
40403 };
40404
40405 struct cm_counter_attribute {
40406@@ -1395,7 +1395,7 @@ static void cm_dup_req_handler(struct cm_work *work,
40407 struct ib_mad_send_buf *msg = NULL;
40408 int ret;
40409
40410- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40411+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40412 counter[CM_REQ_COUNTER]);
40413
40414 /* Quick state check to discard duplicate REQs. */
40415@@ -1779,7 +1779,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
40416 if (!cm_id_priv)
40417 return;
40418
40419- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40420+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40421 counter[CM_REP_COUNTER]);
40422 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
40423 if (ret)
40424@@ -1946,7 +1946,7 @@ static int cm_rtu_handler(struct cm_work *work)
40425 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
40426 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
40427 spin_unlock_irq(&cm_id_priv->lock);
40428- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40429+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40430 counter[CM_RTU_COUNTER]);
40431 goto out;
40432 }
40433@@ -2129,7 +2129,7 @@ static int cm_dreq_handler(struct cm_work *work)
40434 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
40435 dreq_msg->local_comm_id);
40436 if (!cm_id_priv) {
40437- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40438+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40439 counter[CM_DREQ_COUNTER]);
40440 cm_issue_drep(work->port, work->mad_recv_wc);
40441 return -EINVAL;
40442@@ -2154,7 +2154,7 @@ static int cm_dreq_handler(struct cm_work *work)
40443 case IB_CM_MRA_REP_RCVD:
40444 break;
40445 case IB_CM_TIMEWAIT:
40446- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40447+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40448 counter[CM_DREQ_COUNTER]);
40449 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
40450 goto unlock;
40451@@ -2168,7 +2168,7 @@ static int cm_dreq_handler(struct cm_work *work)
40452 cm_free_msg(msg);
40453 goto deref;
40454 case IB_CM_DREQ_RCVD:
40455- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40456+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40457 counter[CM_DREQ_COUNTER]);
40458 goto unlock;
40459 default:
40460@@ -2535,7 +2535,7 @@ static int cm_mra_handler(struct cm_work *work)
40461 ib_modify_mad(cm_id_priv->av.port->mad_agent,
40462 cm_id_priv->msg, timeout)) {
40463 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
40464- atomic_long_inc(&work->port->
40465+ atomic_long_inc_unchecked(&work->port->
40466 counter_group[CM_RECV_DUPLICATES].
40467 counter[CM_MRA_COUNTER]);
40468 goto out;
40469@@ -2544,7 +2544,7 @@ static int cm_mra_handler(struct cm_work *work)
40470 break;
40471 case IB_CM_MRA_REQ_RCVD:
40472 case IB_CM_MRA_REP_RCVD:
40473- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40474+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40475 counter[CM_MRA_COUNTER]);
40476 /* fall through */
40477 default:
40478@@ -2706,7 +2706,7 @@ static int cm_lap_handler(struct cm_work *work)
40479 case IB_CM_LAP_IDLE:
40480 break;
40481 case IB_CM_MRA_LAP_SENT:
40482- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40483+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40484 counter[CM_LAP_COUNTER]);
40485 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
40486 goto unlock;
40487@@ -2722,7 +2722,7 @@ static int cm_lap_handler(struct cm_work *work)
40488 cm_free_msg(msg);
40489 goto deref;
40490 case IB_CM_LAP_RCVD:
40491- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40492+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40493 counter[CM_LAP_COUNTER]);
40494 goto unlock;
40495 default:
40496@@ -3006,7 +3006,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
40497 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
40498 if (cur_cm_id_priv) {
40499 spin_unlock_irq(&cm.lock);
40500- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
40501+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
40502 counter[CM_SIDR_REQ_COUNTER]);
40503 goto out; /* Duplicate message. */
40504 }
40505@@ -3218,10 +3218,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
40506 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
40507 msg->retries = 1;
40508
40509- atomic_long_add(1 + msg->retries,
40510+ atomic_long_add_unchecked(1 + msg->retries,
40511 &port->counter_group[CM_XMIT].counter[attr_index]);
40512 if (msg->retries)
40513- atomic_long_add(msg->retries,
40514+ atomic_long_add_unchecked(msg->retries,
40515 &port->counter_group[CM_XMIT_RETRIES].
40516 counter[attr_index]);
40517
40518@@ -3431,7 +3431,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
40519 }
40520
40521 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
40522- atomic_long_inc(&port->counter_group[CM_RECV].
40523+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
40524 counter[attr_id - CM_ATTR_ID_OFFSET]);
40525
40526 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
40527@@ -3636,7 +3636,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
40528 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
40529
40530 return sprintf(buf, "%ld\n",
40531- atomic_long_read(&group->counter[cm_attr->index]));
40532+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
40533 }
40534
40535 static const struct sysfs_ops cm_counter_ops = {
40536diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
40537index 9f5ad7c..588cd84 100644
40538--- a/drivers/infiniband/core/fmr_pool.c
40539+++ b/drivers/infiniband/core/fmr_pool.c
40540@@ -98,8 +98,8 @@ struct ib_fmr_pool {
40541
40542 struct task_struct *thread;
40543
40544- atomic_t req_ser;
40545- atomic_t flush_ser;
40546+ atomic_unchecked_t req_ser;
40547+ atomic_unchecked_t flush_ser;
40548
40549 wait_queue_head_t force_wait;
40550 };
40551@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
40552 struct ib_fmr_pool *pool = pool_ptr;
40553
40554 do {
40555- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
40556+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
40557 ib_fmr_batch_release(pool);
40558
40559- atomic_inc(&pool->flush_ser);
40560+ atomic_inc_unchecked(&pool->flush_ser);
40561 wake_up_interruptible(&pool->force_wait);
40562
40563 if (pool->flush_function)
40564@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
40565 }
40566
40567 set_current_state(TASK_INTERRUPTIBLE);
40568- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
40569+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
40570 !kthread_should_stop())
40571 schedule();
40572 __set_current_state(TASK_RUNNING);
40573@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
40574 pool->dirty_watermark = params->dirty_watermark;
40575 pool->dirty_len = 0;
40576 spin_lock_init(&pool->pool_lock);
40577- atomic_set(&pool->req_ser, 0);
40578- atomic_set(&pool->flush_ser, 0);
40579+ atomic_set_unchecked(&pool->req_ser, 0);
40580+ atomic_set_unchecked(&pool->flush_ser, 0);
40581 init_waitqueue_head(&pool->force_wait);
40582
40583 pool->thread = kthread_run(ib_fmr_cleanup_thread,
40584@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
40585 }
40586 spin_unlock_irq(&pool->pool_lock);
40587
40588- serial = atomic_inc_return(&pool->req_ser);
40589+ serial = atomic_inc_return_unchecked(&pool->req_ser);
40590 wake_up_process(pool->thread);
40591
40592 if (wait_event_interruptible(pool->force_wait,
40593- atomic_read(&pool->flush_ser) - serial >= 0))
40594+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
40595 return -EINTR;
40596
40597 return 0;
40598@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
40599 } else {
40600 list_add_tail(&fmr->list, &pool->dirty_list);
40601 if (++pool->dirty_len >= pool->dirty_watermark) {
40602- atomic_inc(&pool->req_ser);
40603+ atomic_inc_unchecked(&pool->req_ser);
40604 wake_up_process(pool->thread);
40605 }
40606 }
40607diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
40608index 4cb8eb2..146bf60 100644
40609--- a/drivers/infiniband/hw/cxgb4/mem.c
40610+++ b/drivers/infiniband/hw/cxgb4/mem.c
40611@@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
40612 int err;
40613 struct fw_ri_tpte tpt;
40614 u32 stag_idx;
40615- static atomic_t key;
40616+ static atomic_unchecked_t key;
40617
40618 if (c4iw_fatal_error(rdev))
40619 return -EIO;
40620@@ -266,7 +266,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
40621 if (rdev->stats.stag.cur > rdev->stats.stag.max)
40622 rdev->stats.stag.max = rdev->stats.stag.cur;
40623 mutex_unlock(&rdev->stats.lock);
40624- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
40625+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
40626 }
40627 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
40628 __func__, stag_state, type, pdid, stag_idx);
40629diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
40630index 79b3dbc..96e5fcc 100644
40631--- a/drivers/infiniband/hw/ipath/ipath_rc.c
40632+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
40633@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
40634 struct ib_atomic_eth *ateth;
40635 struct ipath_ack_entry *e;
40636 u64 vaddr;
40637- atomic64_t *maddr;
40638+ atomic64_unchecked_t *maddr;
40639 u64 sdata;
40640 u32 rkey;
40641 u8 next;
40642@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
40643 IB_ACCESS_REMOTE_ATOMIC)))
40644 goto nack_acc_unlck;
40645 /* Perform atomic OP and save result. */
40646- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
40647+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
40648 sdata = be64_to_cpu(ateth->swap_data);
40649 e = &qp->s_ack_queue[qp->r_head_ack_queue];
40650 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
40651- (u64) atomic64_add_return(sdata, maddr) - sdata :
40652+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
40653 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
40654 be64_to_cpu(ateth->compare_data),
40655 sdata);
40656diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
40657index 1f95bba..9530f87 100644
40658--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
40659+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
40660@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
40661 unsigned long flags;
40662 struct ib_wc wc;
40663 u64 sdata;
40664- atomic64_t *maddr;
40665+ atomic64_unchecked_t *maddr;
40666 enum ib_wc_status send_status;
40667
40668 /*
40669@@ -382,11 +382,11 @@ again:
40670 IB_ACCESS_REMOTE_ATOMIC)))
40671 goto acc_err;
40672 /* Perform atomic OP and save result. */
40673- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
40674+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
40675 sdata = wqe->wr.wr.atomic.compare_add;
40676 *(u64 *) sqp->s_sge.sge.vaddr =
40677 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
40678- (u64) atomic64_add_return(sdata, maddr) - sdata :
40679+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
40680 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
40681 sdata, wqe->wr.wr.atomic.swap);
40682 goto send_comp;
40683diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
40684index f2a3f48..673ec79 100644
40685--- a/drivers/infiniband/hw/mlx4/mad.c
40686+++ b/drivers/infiniband/hw/mlx4/mad.c
40687@@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
40688
40689 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
40690 {
40691- return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
40692+ return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
40693 cpu_to_be64(0xff00000000000000LL);
40694 }
40695
40696diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
40697index 25b2cdf..099ff97 100644
40698--- a/drivers/infiniband/hw/mlx4/mcg.c
40699+++ b/drivers/infiniband/hw/mlx4/mcg.c
40700@@ -1040,7 +1040,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
40701 {
40702 char name[20];
40703
40704- atomic_set(&ctx->tid, 0);
40705+ atomic_set_unchecked(&ctx->tid, 0);
40706 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
40707 ctx->mcg_wq = create_singlethread_workqueue(name);
40708 if (!ctx->mcg_wq)
40709diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
40710index f61ec26..ebf72cf 100644
40711--- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
40712+++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
40713@@ -398,7 +398,7 @@ struct mlx4_ib_demux_ctx {
40714 struct list_head mcg_mgid0_list;
40715 struct workqueue_struct *mcg_wq;
40716 struct mlx4_ib_demux_pv_ctx **tun;
40717- atomic_t tid;
40718+ atomic_unchecked_t tid;
40719 int flushing; /* flushing the work queue */
40720 };
40721
40722diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
40723index 9d3e5c1..d9afe4a 100644
40724--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
40725+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
40726@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
40727 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
40728 }
40729
40730-int mthca_QUERY_FW(struct mthca_dev *dev)
40731+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
40732 {
40733 struct mthca_mailbox *mailbox;
40734 u32 *outbox;
40735diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
40736index ed9a989..e0c5871 100644
40737--- a/drivers/infiniband/hw/mthca/mthca_mr.c
40738+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
40739@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
40740 return key;
40741 }
40742
40743-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
40744+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
40745 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
40746 {
40747 struct mthca_mailbox *mailbox;
40748diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
40749index 4291410..d2ab1fb 100644
40750--- a/drivers/infiniband/hw/nes/nes.c
40751+++ b/drivers/infiniband/hw/nes/nes.c
40752@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
40753 LIST_HEAD(nes_adapter_list);
40754 static LIST_HEAD(nes_dev_list);
40755
40756-atomic_t qps_destroyed;
40757+atomic_unchecked_t qps_destroyed;
40758
40759 static unsigned int ee_flsh_adapter;
40760 static unsigned int sysfs_nonidx_addr;
40761@@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
40762 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
40763 struct nes_adapter *nesadapter = nesdev->nesadapter;
40764
40765- atomic_inc(&qps_destroyed);
40766+ atomic_inc_unchecked(&qps_destroyed);
40767
40768 /* Free the control structures */
40769
40770diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
40771index 33cc589..3bd6538 100644
40772--- a/drivers/infiniband/hw/nes/nes.h
40773+++ b/drivers/infiniband/hw/nes/nes.h
40774@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
40775 extern unsigned int wqm_quanta;
40776 extern struct list_head nes_adapter_list;
40777
40778-extern atomic_t cm_connects;
40779-extern atomic_t cm_accepts;
40780-extern atomic_t cm_disconnects;
40781-extern atomic_t cm_closes;
40782-extern atomic_t cm_connecteds;
40783-extern atomic_t cm_connect_reqs;
40784-extern atomic_t cm_rejects;
40785-extern atomic_t mod_qp_timouts;
40786-extern atomic_t qps_created;
40787-extern atomic_t qps_destroyed;
40788-extern atomic_t sw_qps_destroyed;
40789+extern atomic_unchecked_t cm_connects;
40790+extern atomic_unchecked_t cm_accepts;
40791+extern atomic_unchecked_t cm_disconnects;
40792+extern atomic_unchecked_t cm_closes;
40793+extern atomic_unchecked_t cm_connecteds;
40794+extern atomic_unchecked_t cm_connect_reqs;
40795+extern atomic_unchecked_t cm_rejects;
40796+extern atomic_unchecked_t mod_qp_timouts;
40797+extern atomic_unchecked_t qps_created;
40798+extern atomic_unchecked_t qps_destroyed;
40799+extern atomic_unchecked_t sw_qps_destroyed;
40800 extern u32 mh_detected;
40801 extern u32 mh_pauses_sent;
40802 extern u32 cm_packets_sent;
40803@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
40804 extern u32 cm_packets_received;
40805 extern u32 cm_packets_dropped;
40806 extern u32 cm_packets_retrans;
40807-extern atomic_t cm_listens_created;
40808-extern atomic_t cm_listens_destroyed;
40809+extern atomic_unchecked_t cm_listens_created;
40810+extern atomic_unchecked_t cm_listens_destroyed;
40811 extern u32 cm_backlog_drops;
40812-extern atomic_t cm_loopbacks;
40813-extern atomic_t cm_nodes_created;
40814-extern atomic_t cm_nodes_destroyed;
40815-extern atomic_t cm_accel_dropped_pkts;
40816-extern atomic_t cm_resets_recvd;
40817-extern atomic_t pau_qps_created;
40818-extern atomic_t pau_qps_destroyed;
40819+extern atomic_unchecked_t cm_loopbacks;
40820+extern atomic_unchecked_t cm_nodes_created;
40821+extern atomic_unchecked_t cm_nodes_destroyed;
40822+extern atomic_unchecked_t cm_accel_dropped_pkts;
40823+extern atomic_unchecked_t cm_resets_recvd;
40824+extern atomic_unchecked_t pau_qps_created;
40825+extern atomic_unchecked_t pau_qps_destroyed;
40826
40827 extern u32 int_mod_timer_init;
40828 extern u32 int_mod_cq_depth_256;
40829diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
40830index 24b9f1a..00fd004 100644
40831--- a/drivers/infiniband/hw/nes/nes_cm.c
40832+++ b/drivers/infiniband/hw/nes/nes_cm.c
40833@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
40834 u32 cm_packets_retrans;
40835 u32 cm_packets_created;
40836 u32 cm_packets_received;
40837-atomic_t cm_listens_created;
40838-atomic_t cm_listens_destroyed;
40839+atomic_unchecked_t cm_listens_created;
40840+atomic_unchecked_t cm_listens_destroyed;
40841 u32 cm_backlog_drops;
40842-atomic_t cm_loopbacks;
40843-atomic_t cm_nodes_created;
40844-atomic_t cm_nodes_destroyed;
40845-atomic_t cm_accel_dropped_pkts;
40846-atomic_t cm_resets_recvd;
40847+atomic_unchecked_t cm_loopbacks;
40848+atomic_unchecked_t cm_nodes_created;
40849+atomic_unchecked_t cm_nodes_destroyed;
40850+atomic_unchecked_t cm_accel_dropped_pkts;
40851+atomic_unchecked_t cm_resets_recvd;
40852
40853 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
40854 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
40855@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
40856
40857 static struct nes_cm_core *g_cm_core;
40858
40859-atomic_t cm_connects;
40860-atomic_t cm_accepts;
40861-atomic_t cm_disconnects;
40862-atomic_t cm_closes;
40863-atomic_t cm_connecteds;
40864-atomic_t cm_connect_reqs;
40865-atomic_t cm_rejects;
40866+atomic_unchecked_t cm_connects;
40867+atomic_unchecked_t cm_accepts;
40868+atomic_unchecked_t cm_disconnects;
40869+atomic_unchecked_t cm_closes;
40870+atomic_unchecked_t cm_connecteds;
40871+atomic_unchecked_t cm_connect_reqs;
40872+atomic_unchecked_t cm_rejects;
40873
40874 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
40875 {
40876@@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
40877 kfree(listener);
40878 listener = NULL;
40879 ret = 0;
40880- atomic_inc(&cm_listens_destroyed);
40881+ atomic_inc_unchecked(&cm_listens_destroyed);
40882 } else {
40883 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
40884 }
40885@@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
40886 cm_node->rem_mac);
40887
40888 add_hte_node(cm_core, cm_node);
40889- atomic_inc(&cm_nodes_created);
40890+ atomic_inc_unchecked(&cm_nodes_created);
40891
40892 return cm_node;
40893 }
40894@@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
40895 }
40896
40897 atomic_dec(&cm_core->node_cnt);
40898- atomic_inc(&cm_nodes_destroyed);
40899+ atomic_inc_unchecked(&cm_nodes_destroyed);
40900 nesqp = cm_node->nesqp;
40901 if (nesqp) {
40902 nesqp->cm_node = NULL;
40903@@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
40904
40905 static void drop_packet(struct sk_buff *skb)
40906 {
40907- atomic_inc(&cm_accel_dropped_pkts);
40908+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
40909 dev_kfree_skb_any(skb);
40910 }
40911
40912@@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
40913 {
40914
40915 int reset = 0; /* whether to send reset in case of err.. */
40916- atomic_inc(&cm_resets_recvd);
40917+ atomic_inc_unchecked(&cm_resets_recvd);
40918 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
40919 " refcnt=%d\n", cm_node, cm_node->state,
40920 atomic_read(&cm_node->ref_count));
40921@@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
40922 rem_ref_cm_node(cm_node->cm_core, cm_node);
40923 return NULL;
40924 }
40925- atomic_inc(&cm_loopbacks);
40926+ atomic_inc_unchecked(&cm_loopbacks);
40927 loopbackremotenode->loopbackpartner = cm_node;
40928 loopbackremotenode->tcp_cntxt.rcv_wscale =
40929 NES_CM_DEFAULT_RCV_WND_SCALE;
40930@@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
40931 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
40932 else {
40933 rem_ref_cm_node(cm_core, cm_node);
40934- atomic_inc(&cm_accel_dropped_pkts);
40935+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
40936 dev_kfree_skb_any(skb);
40937 }
40938 break;
40939@@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
40940
40941 if ((cm_id) && (cm_id->event_handler)) {
40942 if (issue_disconn) {
40943- atomic_inc(&cm_disconnects);
40944+ atomic_inc_unchecked(&cm_disconnects);
40945 cm_event.event = IW_CM_EVENT_DISCONNECT;
40946 cm_event.status = disconn_status;
40947 cm_event.local_addr = cm_id->local_addr;
40948@@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
40949 }
40950
40951 if (issue_close) {
40952- atomic_inc(&cm_closes);
40953+ atomic_inc_unchecked(&cm_closes);
40954 nes_disconnect(nesqp, 1);
40955
40956 cm_id->provider_data = nesqp;
40957@@ -3033,7 +3033,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
40958
40959 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
40960 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
40961- atomic_inc(&cm_accepts);
40962+ atomic_inc_unchecked(&cm_accepts);
40963
40964 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
40965 netdev_refcnt_read(nesvnic->netdev));
40966@@ -3228,7 +3228,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
40967 struct nes_cm_core *cm_core;
40968 u8 *start_buff;
40969
40970- atomic_inc(&cm_rejects);
40971+ atomic_inc_unchecked(&cm_rejects);
40972 cm_node = (struct nes_cm_node *)cm_id->provider_data;
40973 loopback = cm_node->loopbackpartner;
40974 cm_core = cm_node->cm_core;
40975@@ -3288,7 +3288,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
40976 ntohl(cm_id->local_addr.sin_addr.s_addr),
40977 ntohs(cm_id->local_addr.sin_port));
40978
40979- atomic_inc(&cm_connects);
40980+ atomic_inc_unchecked(&cm_connects);
40981 nesqp->active_conn = 1;
40982
40983 /* cache the cm_id in the qp */
40984@@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
40985 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
40986 return err;
40987 }
40988- atomic_inc(&cm_listens_created);
40989+ atomic_inc_unchecked(&cm_listens_created);
40990 }
40991
40992 cm_id->add_ref(cm_id);
40993@@ -3499,7 +3499,7 @@ static void cm_event_connected(struct nes_cm_event *event)
40994
40995 if (nesqp->destroyed)
40996 return;
40997- atomic_inc(&cm_connecteds);
40998+ atomic_inc_unchecked(&cm_connecteds);
40999 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
41000 " local port 0x%04X. jiffies = %lu.\n",
41001 nesqp->hwqp.qp_id,
41002@@ -3679,7 +3679,7 @@ static void cm_event_reset(struct nes_cm_event *event)
41003
41004 cm_id->add_ref(cm_id);
41005 ret = cm_id->event_handler(cm_id, &cm_event);
41006- atomic_inc(&cm_closes);
41007+ atomic_inc_unchecked(&cm_closes);
41008 cm_event.event = IW_CM_EVENT_CLOSE;
41009 cm_event.status = 0;
41010 cm_event.provider_data = cm_id->provider_data;
41011@@ -3715,7 +3715,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
41012 return;
41013 cm_id = cm_node->cm_id;
41014
41015- atomic_inc(&cm_connect_reqs);
41016+ atomic_inc_unchecked(&cm_connect_reqs);
41017 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
41018 cm_node, cm_id, jiffies);
41019
41020@@ -3755,7 +3755,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
41021 return;
41022 cm_id = cm_node->cm_id;
41023
41024- atomic_inc(&cm_connect_reqs);
41025+ atomic_inc_unchecked(&cm_connect_reqs);
41026 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
41027 cm_node, cm_id, jiffies);
41028
41029diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
41030index 4166452..fc952c3 100644
41031--- a/drivers/infiniband/hw/nes/nes_mgt.c
41032+++ b/drivers/infiniband/hw/nes/nes_mgt.c
41033@@ -40,8 +40,8 @@
41034 #include "nes.h"
41035 #include "nes_mgt.h"
41036
41037-atomic_t pau_qps_created;
41038-atomic_t pau_qps_destroyed;
41039+atomic_unchecked_t pau_qps_created;
41040+atomic_unchecked_t pau_qps_destroyed;
41041
41042 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
41043 {
41044@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
41045 {
41046 struct sk_buff *skb;
41047 unsigned long flags;
41048- atomic_inc(&pau_qps_destroyed);
41049+ atomic_inc_unchecked(&pau_qps_destroyed);
41050
41051 /* Free packets that have not yet been forwarded */
41052 /* Lock is acquired by skb_dequeue when removing the skb */
41053@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
41054 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
41055 skb_queue_head_init(&nesqp->pau_list);
41056 spin_lock_init(&nesqp->pau_lock);
41057- atomic_inc(&pau_qps_created);
41058+ atomic_inc_unchecked(&pau_qps_created);
41059 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
41060 }
41061
41062diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
41063index 49eb511..a774366 100644
41064--- a/drivers/infiniband/hw/nes/nes_nic.c
41065+++ b/drivers/infiniband/hw/nes/nes_nic.c
41066@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
41067 target_stat_values[++index] = mh_detected;
41068 target_stat_values[++index] = mh_pauses_sent;
41069 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
41070- target_stat_values[++index] = atomic_read(&cm_connects);
41071- target_stat_values[++index] = atomic_read(&cm_accepts);
41072- target_stat_values[++index] = atomic_read(&cm_disconnects);
41073- target_stat_values[++index] = atomic_read(&cm_connecteds);
41074- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
41075- target_stat_values[++index] = atomic_read(&cm_rejects);
41076- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
41077- target_stat_values[++index] = atomic_read(&qps_created);
41078- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
41079- target_stat_values[++index] = atomic_read(&qps_destroyed);
41080- target_stat_values[++index] = atomic_read(&cm_closes);
41081+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
41082+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
41083+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
41084+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
41085+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
41086+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
41087+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
41088+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
41089+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
41090+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
41091+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
41092 target_stat_values[++index] = cm_packets_sent;
41093 target_stat_values[++index] = cm_packets_bounced;
41094 target_stat_values[++index] = cm_packets_created;
41095 target_stat_values[++index] = cm_packets_received;
41096 target_stat_values[++index] = cm_packets_dropped;
41097 target_stat_values[++index] = cm_packets_retrans;
41098- target_stat_values[++index] = atomic_read(&cm_listens_created);
41099- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
41100+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
41101+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
41102 target_stat_values[++index] = cm_backlog_drops;
41103- target_stat_values[++index] = atomic_read(&cm_loopbacks);
41104- target_stat_values[++index] = atomic_read(&cm_nodes_created);
41105- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
41106- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
41107- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
41108+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
41109+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
41110+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
41111+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
41112+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
41113 target_stat_values[++index] = nesadapter->free_4kpbl;
41114 target_stat_values[++index] = nesadapter->free_256pbl;
41115 target_stat_values[++index] = int_mod_timer_init;
41116 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
41117 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
41118 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
41119- target_stat_values[++index] = atomic_read(&pau_qps_created);
41120- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
41121+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
41122+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
41123 }
41124
41125 /**
41126diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
41127index 5b53ca5..443da3c 100644
41128--- a/drivers/infiniband/hw/nes/nes_verbs.c
41129+++ b/drivers/infiniband/hw/nes/nes_verbs.c
41130@@ -46,9 +46,9 @@
41131
41132 #include <rdma/ib_umem.h>
41133
41134-atomic_t mod_qp_timouts;
41135-atomic_t qps_created;
41136-atomic_t sw_qps_destroyed;
41137+atomic_unchecked_t mod_qp_timouts;
41138+atomic_unchecked_t qps_created;
41139+atomic_unchecked_t sw_qps_destroyed;
41140
41141 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
41142
41143@@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
41144 if (init_attr->create_flags)
41145 return ERR_PTR(-EINVAL);
41146
41147- atomic_inc(&qps_created);
41148+ atomic_inc_unchecked(&qps_created);
41149 switch (init_attr->qp_type) {
41150 case IB_QPT_RC:
41151 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
41152@@ -1466,7 +1466,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
41153 struct iw_cm_event cm_event;
41154 int ret = 0;
41155
41156- atomic_inc(&sw_qps_destroyed);
41157+ atomic_inc_unchecked(&sw_qps_destroyed);
41158 nesqp->destroyed = 1;
41159
41160 /* Blow away the connection if it exists. */
41161diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
41162index 4a9af79..b993f75 100644
41163--- a/drivers/infiniband/hw/qib/qib.h
41164+++ b/drivers/infiniband/hw/qib/qib.h
41165@@ -52,6 +52,7 @@
41166 #include <linux/kref.h>
41167 #include <linux/sched.h>
41168 #include <linux/kthread.h>
41169+#include <linux/slab.h>
41170
41171 #include "qib_common.h"
41172 #include "qib_verbs.h"
41173diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
41174index da739d9..da1c7f4 100644
41175--- a/drivers/input/gameport/gameport.c
41176+++ b/drivers/input/gameport/gameport.c
41177@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
41178 */
41179 static void gameport_init_port(struct gameport *gameport)
41180 {
41181- static atomic_t gameport_no = ATOMIC_INIT(0);
41182+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
41183
41184 __module_get(THIS_MODULE);
41185
41186 mutex_init(&gameport->drv_mutex);
41187 device_initialize(&gameport->dev);
41188 dev_set_name(&gameport->dev, "gameport%lu",
41189- (unsigned long)atomic_inc_return(&gameport_no) - 1);
41190+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
41191 gameport->dev.bus = &gameport_bus;
41192 gameport->dev.release = gameport_release_port;
41193 if (gameport->parent)
41194diff --git a/drivers/input/input.c b/drivers/input/input.c
41195index c044699..174d71a 100644
41196--- a/drivers/input/input.c
41197+++ b/drivers/input/input.c
41198@@ -2019,7 +2019,7 @@ static void devm_input_device_unregister(struct device *dev, void *res)
41199 */
41200 int input_register_device(struct input_dev *dev)
41201 {
41202- static atomic_t input_no = ATOMIC_INIT(0);
41203+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
41204 struct input_devres *devres = NULL;
41205 struct input_handler *handler;
41206 unsigned int packet_size;
41207@@ -2074,7 +2074,7 @@ int input_register_device(struct input_dev *dev)
41208 dev->setkeycode = input_default_setkeycode;
41209
41210 dev_set_name(&dev->dev, "input%ld",
41211- (unsigned long) atomic_inc_return(&input_no) - 1);
41212+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
41213
41214 error = device_add(&dev->dev);
41215 if (error)
41216diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
41217index 04c69af..5f92d00 100644
41218--- a/drivers/input/joystick/sidewinder.c
41219+++ b/drivers/input/joystick/sidewinder.c
41220@@ -30,6 +30,7 @@
41221 #include <linux/kernel.h>
41222 #include <linux/module.h>
41223 #include <linux/slab.h>
41224+#include <linux/sched.h>
41225 #include <linux/init.h>
41226 #include <linux/input.h>
41227 #include <linux/gameport.h>
41228diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
41229index 75e3b10..fb390fd 100644
41230--- a/drivers/input/joystick/xpad.c
41231+++ b/drivers/input/joystick/xpad.c
41232@@ -736,7 +736,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
41233
41234 static int xpad_led_probe(struct usb_xpad *xpad)
41235 {
41236- static atomic_t led_seq = ATOMIC_INIT(0);
41237+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
41238 long led_no;
41239 struct xpad_led *led;
41240 struct led_classdev *led_cdev;
41241@@ -749,7 +749,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
41242 if (!led)
41243 return -ENOMEM;
41244
41245- led_no = (long)atomic_inc_return(&led_seq) - 1;
41246+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
41247
41248 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
41249 led->xpad = xpad;
41250diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
41251index e204f26..8459f15 100644
41252--- a/drivers/input/misc/ims-pcu.c
41253+++ b/drivers/input/misc/ims-pcu.c
41254@@ -1621,7 +1621,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
41255
41256 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
41257 {
41258- static atomic_t device_no = ATOMIC_INIT(0);
41259+ static atomic_unchecked_t device_no = ATOMIC_INIT(0);
41260
41261 const struct ims_pcu_device_info *info;
41262 u8 device_id;
41263@@ -1653,7 +1653,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
41264 }
41265
41266 /* Device appears to be operable, complete initialization */
41267- pcu->device_no = atomic_inc_return(&device_no) - 1;
41268+ pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
41269
41270 error = ims_pcu_setup_backlight(pcu);
41271 if (error)
41272diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
41273index 2f0b39d..7370f13 100644
41274--- a/drivers/input/mouse/psmouse.h
41275+++ b/drivers/input/mouse/psmouse.h
41276@@ -116,7 +116,7 @@ struct psmouse_attribute {
41277 ssize_t (*set)(struct psmouse *psmouse, void *data,
41278 const char *buf, size_t count);
41279 bool protect;
41280-};
41281+} __do_const;
41282 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
41283
41284 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
41285diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
41286index 4c842c3..590b0bf 100644
41287--- a/drivers/input/mousedev.c
41288+++ b/drivers/input/mousedev.c
41289@@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
41290
41291 spin_unlock_irq(&client->packet_lock);
41292
41293- if (copy_to_user(buffer, data, count))
41294+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
41295 return -EFAULT;
41296
41297 return count;
41298diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
41299index 25fc597..558bf3b3 100644
41300--- a/drivers/input/serio/serio.c
41301+++ b/drivers/input/serio/serio.c
41302@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
41303 */
41304 static void serio_init_port(struct serio *serio)
41305 {
41306- static atomic_t serio_no = ATOMIC_INIT(0);
41307+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
41308
41309 __module_get(THIS_MODULE);
41310
41311@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
41312 mutex_init(&serio->drv_mutex);
41313 device_initialize(&serio->dev);
41314 dev_set_name(&serio->dev, "serio%ld",
41315- (long)atomic_inc_return(&serio_no) - 1);
41316+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
41317 serio->dev.bus = &serio_bus;
41318 serio->dev.release = serio_release_port;
41319 serio->dev.groups = serio_device_attr_groups;
41320diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
41321index 59df2e7..8f1cafb 100644
41322--- a/drivers/input/serio/serio_raw.c
41323+++ b/drivers/input/serio/serio_raw.c
41324@@ -293,7 +293,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
41325
41326 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
41327 {
41328- static atomic_t serio_raw_no = ATOMIC_INIT(0);
41329+ static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
41330 struct serio_raw *serio_raw;
41331 int err;
41332
41333@@ -304,7 +304,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
41334 }
41335
41336 snprintf(serio_raw->name, sizeof(serio_raw->name),
41337- "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
41338+ "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
41339 kref_init(&serio_raw->kref);
41340 INIT_LIST_HEAD(&serio_raw->client_list);
41341 init_waitqueue_head(&serio_raw->wait);
41342diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
41343index fbe9ca7..dbee61d 100644
41344--- a/drivers/iommu/iommu.c
41345+++ b/drivers/iommu/iommu.c
41346@@ -583,7 +583,7 @@ static struct notifier_block iommu_bus_nb = {
41347 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
41348 {
41349 bus_register_notifier(bus, &iommu_bus_nb);
41350- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
41351+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
41352 }
41353
41354 /**
41355diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
41356index 39f81ae..2660096 100644
41357--- a/drivers/iommu/irq_remapping.c
41358+++ b/drivers/iommu/irq_remapping.c
41359@@ -356,7 +356,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
41360 void panic_if_irq_remap(const char *msg)
41361 {
41362 if (irq_remapping_enabled)
41363- panic(msg);
41364+ panic("%s", msg);
41365 }
41366
41367 static void ir_ack_apic_edge(struct irq_data *data)
41368@@ -377,10 +377,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
41369
41370 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
41371 {
41372- chip->irq_print_chip = ir_print_prefix;
41373- chip->irq_ack = ir_ack_apic_edge;
41374- chip->irq_eoi = ir_ack_apic_level;
41375- chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
41376+ pax_open_kernel();
41377+ *(void **)&chip->irq_print_chip = ir_print_prefix;
41378+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
41379+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
41380+ *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
41381+ pax_close_kernel();
41382 }
41383
41384 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
41385diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
41386index ee7c503..5d4ce08 100644
41387--- a/drivers/irqchip/irq-gic.c
41388+++ b/drivers/irqchip/irq-gic.c
41389@@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
41390 * Supported arch specific GIC irq extension.
41391 * Default make them NULL.
41392 */
41393-struct irq_chip gic_arch_extn = {
41394+irq_chip_no_const gic_arch_extn = {
41395 .irq_eoi = NULL,
41396 .irq_mask = NULL,
41397 .irq_unmask = NULL,
41398@@ -333,7 +333,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
41399 chained_irq_exit(chip, desc);
41400 }
41401
41402-static struct irq_chip gic_chip = {
41403+static irq_chip_no_const gic_chip __read_only = {
41404 .name = "GIC",
41405 .irq_mask = gic_mask_irq,
41406 .irq_unmask = gic_unmask_irq,
41407diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
41408index ac6f72b..81150f2 100644
41409--- a/drivers/isdn/capi/capi.c
41410+++ b/drivers/isdn/capi/capi.c
41411@@ -81,8 +81,8 @@ struct capiminor {
41412
41413 struct capi20_appl *ap;
41414 u32 ncci;
41415- atomic_t datahandle;
41416- atomic_t msgid;
41417+ atomic_unchecked_t datahandle;
41418+ atomic_unchecked_t msgid;
41419
41420 struct tty_port port;
41421 int ttyinstop;
41422@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
41423 capimsg_setu16(s, 2, mp->ap->applid);
41424 capimsg_setu8 (s, 4, CAPI_DATA_B3);
41425 capimsg_setu8 (s, 5, CAPI_RESP);
41426- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
41427+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
41428 capimsg_setu32(s, 8, mp->ncci);
41429 capimsg_setu16(s, 12, datahandle);
41430 }
41431@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
41432 mp->outbytes -= len;
41433 spin_unlock_bh(&mp->outlock);
41434
41435- datahandle = atomic_inc_return(&mp->datahandle);
41436+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
41437 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
41438 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
41439 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
41440 capimsg_setu16(skb->data, 2, mp->ap->applid);
41441 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
41442 capimsg_setu8 (skb->data, 5, CAPI_REQ);
41443- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
41444+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
41445 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
41446 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
41447 capimsg_setu16(skb->data, 16, len); /* Data length */
41448diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
41449index 600c79b..3752bab 100644
41450--- a/drivers/isdn/gigaset/interface.c
41451+++ b/drivers/isdn/gigaset/interface.c
41452@@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
41453 }
41454 tty->driver_data = cs;
41455
41456- ++cs->port.count;
41457+ atomic_inc(&cs->port.count);
41458
41459- if (cs->port.count == 1) {
41460+ if (atomic_read(&cs->port.count) == 1) {
41461 tty_port_tty_set(&cs->port, tty);
41462 cs->port.low_latency = 1;
41463 }
41464@@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
41465
41466 if (!cs->connected)
41467 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
41468- else if (!cs->port.count)
41469+ else if (!atomic_read(&cs->port.count))
41470 dev_warn(cs->dev, "%s: device not opened\n", __func__);
41471- else if (!--cs->port.count)
41472+ else if (!atomic_dec_return(&cs->port.count))
41473 tty_port_tty_set(&cs->port, NULL);
41474
41475 mutex_unlock(&cs->mutex);
41476diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
41477index d0a41cb..f0cdb8c 100644
41478--- a/drivers/isdn/gigaset/usb-gigaset.c
41479+++ b/drivers/isdn/gigaset/usb-gigaset.c
41480@@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
41481 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
41482 memcpy(cs->hw.usb->bchars, buf, 6);
41483 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
41484- 0, 0, &buf, 6, 2000);
41485+ 0, 0, buf, 6, 2000);
41486 }
41487
41488 static void gigaset_freebcshw(struct bc_state *bcs)
41489diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
41490index 4d9b195..455075c 100644
41491--- a/drivers/isdn/hardware/avm/b1.c
41492+++ b/drivers/isdn/hardware/avm/b1.c
41493@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
41494 }
41495 if (left) {
41496 if (t4file->user) {
41497- if (copy_from_user(buf, dp, left))
41498+ if (left > sizeof buf || copy_from_user(buf, dp, left))
41499 return -EFAULT;
41500 } else {
41501 memcpy(buf, dp, left);
41502@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
41503 }
41504 if (left) {
41505 if (config->user) {
41506- if (copy_from_user(buf, dp, left))
41507+ if (left > sizeof buf || copy_from_user(buf, dp, left))
41508 return -EFAULT;
41509 } else {
41510 memcpy(buf, dp, left);
41511diff --git a/drivers/isdn/hisax/amd7930_fn.c b/drivers/isdn/hisax/amd7930_fn.c
41512index 1063bab..36817e0 100644
41513--- a/drivers/isdn/hisax/amd7930_fn.c
41514+++ b/drivers/isdn/hisax/amd7930_fn.c
41515@@ -314,7 +314,7 @@ Amd7930_empty_Dfifo(struct IsdnCardState *cs, int flag)
41516
41517 t += sprintf(t, "Amd7930: empty_Dfifo cnt: %d |", cs->rcvidx);
41518 QuickHex(t, cs->rcvbuf, cs->rcvidx);
41519- debugl1(cs, cs->dlog);
41520+ debugl1(cs, "%s", cs->dlog);
41521 }
41522 /* moves received data in sk-buffer */
41523 memcpy(skb_put(skb, cs->rcvidx), cs->rcvbuf, cs->rcvidx);
41524@@ -406,7 +406,7 @@ Amd7930_fill_Dfifo(struct IsdnCardState *cs)
41525
41526 t += sprintf(t, "Amd7930: fill_Dfifo cnt: %d |", count);
41527 QuickHex(t, deb_ptr, count);
41528- debugl1(cs, cs->dlog);
41529+ debugl1(cs, "%s", cs->dlog);
41530 }
41531 /* AMD interrupts on */
41532 AmdIrqOn(cs);
41533diff --git a/drivers/isdn/hisax/avm_pci.c b/drivers/isdn/hisax/avm_pci.c
41534index ee9b9a0..d1427bd 100644
41535--- a/drivers/isdn/hisax/avm_pci.c
41536+++ b/drivers/isdn/hisax/avm_pci.c
41537@@ -285,7 +285,7 @@ hdlc_empty_fifo(struct BCState *bcs, int count)
41538 t += sprintf(t, "hdlc_empty_fifo %c cnt %d",
41539 bcs->channel ? 'B' : 'A', count);
41540 QuickHex(t, p, count);
41541- debugl1(cs, bcs->blog);
41542+ debugl1(cs, "%s", bcs->blog);
41543 }
41544 }
41545
41546@@ -345,7 +345,7 @@ hdlc_fill_fifo(struct BCState *bcs)
41547 t += sprintf(t, "hdlc_fill_fifo %c cnt %d",
41548 bcs->channel ? 'B' : 'A', count);
41549 QuickHex(t, p, count);
41550- debugl1(cs, bcs->blog);
41551+ debugl1(cs, "%s", bcs->blog);
41552 }
41553 }
41554
41555diff --git a/drivers/isdn/hisax/config.c b/drivers/isdn/hisax/config.c
41556index bf04d2a..b33f53b 100644
41557--- a/drivers/isdn/hisax/config.c
41558+++ b/drivers/isdn/hisax/config.c
41559@@ -1896,7 +1896,7 @@ static void EChannel_proc_rcv(struct hisax_d_if *d_if)
41560 ptr--;
41561 *ptr++ = '\n';
41562 *ptr = 0;
41563- HiSax_putstatus(cs, NULL, cs->dlog);
41564+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
41565 } else
41566 HiSax_putstatus(cs, "LogEcho: ",
41567 "warning Frame too big (%d)",
41568diff --git a/drivers/isdn/hisax/diva.c b/drivers/isdn/hisax/diva.c
41569index 8d0cf6e..4fc90de 100644
41570--- a/drivers/isdn/hisax/diva.c
41571+++ b/drivers/isdn/hisax/diva.c
41572@@ -427,7 +427,7 @@ Memhscx_empty_fifo(struct BCState *bcs, int count)
41573 t += sprintf(t, "hscx_empty_fifo %c cnt %d",
41574 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41575 QuickHex(t, ptr, count);
41576- debugl1(cs, bcs->blog);
41577+ debugl1(cs, "%s", bcs->blog);
41578 }
41579 }
41580
41581@@ -469,7 +469,7 @@ Memhscx_fill_fifo(struct BCState *bcs)
41582 t += sprintf(t, "hscx_fill_fifo %c cnt %d",
41583 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41584 QuickHex(t, ptr, count);
41585- debugl1(cs, bcs->blog);
41586+ debugl1(cs, "%s", bcs->blog);
41587 }
41588 }
41589
41590diff --git a/drivers/isdn/hisax/elsa.c b/drivers/isdn/hisax/elsa.c
41591index 1df6f9a..2be1c8a 100644
41592--- a/drivers/isdn/hisax/elsa.c
41593+++ b/drivers/isdn/hisax/elsa.c
41594@@ -535,7 +535,7 @@ check_arcofi(struct IsdnCardState *cs)
41595 t = tmp;
41596 t += sprintf(tmp, "Arcofi data");
41597 QuickHex(t, p, cs->dc.isac.mon_rxp);
41598- debugl1(cs, tmp);
41599+ debugl1(cs, "%s", tmp);
41600 if ((cs->dc.isac.mon_rxp == 2) && (cs->dc.isac.mon_rx[0] == 0xa0)) {
41601 switch (cs->dc.isac.mon_rx[1]) {
41602 case 0x80:
41603diff --git a/drivers/isdn/hisax/elsa_ser.c b/drivers/isdn/hisax/elsa_ser.c
41604index d4c98d3..3f84dd8 100644
41605--- a/drivers/isdn/hisax/elsa_ser.c
41606+++ b/drivers/isdn/hisax/elsa_ser.c
41607@@ -344,7 +344,7 @@ static inline void receive_chars(struct IsdnCardState *cs,
41608
41609 t += sprintf(t, "modem read cnt %d", cs->hw.elsa.rcvcnt);
41610 QuickHex(t, cs->hw.elsa.rcvbuf, cs->hw.elsa.rcvcnt);
41611- debugl1(cs, tmp);
41612+ debugl1(cs, "%s", tmp);
41613 }
41614 cs->hw.elsa.rcvcnt = 0;
41615 }
41616diff --git a/drivers/isdn/hisax/hfc_pci.c b/drivers/isdn/hisax/hfc_pci.c
41617index 3ccd724..497bd02 100644
41618--- a/drivers/isdn/hisax/hfc_pci.c
41619+++ b/drivers/isdn/hisax/hfc_pci.c
41620@@ -901,7 +901,7 @@ Begin:
41621 ptr--;
41622 *ptr++ = '\n';
41623 *ptr = 0;
41624- HiSax_putstatus(cs, NULL, cs->dlog);
41625+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
41626 } else
41627 HiSax_putstatus(cs, "LogEcho: ", "warning Frame too big (%d)", total - 3);
41628 }
41629diff --git a/drivers/isdn/hisax/hfc_sx.c b/drivers/isdn/hisax/hfc_sx.c
41630index dc4574f..fa1fefd 100644
41631--- a/drivers/isdn/hisax/hfc_sx.c
41632+++ b/drivers/isdn/hisax/hfc_sx.c
41633@@ -674,7 +674,7 @@ receive_emsg(struct IsdnCardState *cs)
41634 ptr--;
41635 *ptr++ = '\n';
41636 *ptr = 0;
41637- HiSax_putstatus(cs, NULL, cs->dlog);
41638+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
41639 } else
41640 HiSax_putstatus(cs, "LogEcho: ", "warning Frame too big (%d)", skb->len);
41641 }
41642diff --git a/drivers/isdn/hisax/hscx_irq.c b/drivers/isdn/hisax/hscx_irq.c
41643index f398d48..a8d6188 100644
41644--- a/drivers/isdn/hisax/hscx_irq.c
41645+++ b/drivers/isdn/hisax/hscx_irq.c
41646@@ -75,7 +75,7 @@ hscx_empty_fifo(struct BCState *bcs, int count)
41647 t += sprintf(t, "hscx_empty_fifo %c cnt %d",
41648 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41649 QuickHex(t, ptr, count);
41650- debugl1(cs, bcs->blog);
41651+ debugl1(cs, "%s", bcs->blog);
41652 }
41653 }
41654
41655@@ -115,7 +115,7 @@ hscx_fill_fifo(struct BCState *bcs)
41656 t += sprintf(t, "hscx_fill_fifo %c cnt %d",
41657 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41658 QuickHex(t, ptr, count);
41659- debugl1(cs, bcs->blog);
41660+ debugl1(cs, "%s", bcs->blog);
41661 }
41662 }
41663
41664diff --git a/drivers/isdn/hisax/icc.c b/drivers/isdn/hisax/icc.c
41665index db5321f..51dae91 100644
41666--- a/drivers/isdn/hisax/icc.c
41667+++ b/drivers/isdn/hisax/icc.c
41668@@ -134,7 +134,7 @@ icc_empty_fifo(struct IsdnCardState *cs, int count)
41669
41670 t += sprintf(t, "icc_empty_fifo cnt %d", count);
41671 QuickHex(t, ptr, count);
41672- debugl1(cs, cs->dlog);
41673+ debugl1(cs, "%s", cs->dlog);
41674 }
41675 }
41676
41677@@ -176,7 +176,7 @@ icc_fill_fifo(struct IsdnCardState *cs)
41678
41679 t += sprintf(t, "icc_fill_fifo cnt %d", count);
41680 QuickHex(t, ptr, count);
41681- debugl1(cs, cs->dlog);
41682+ debugl1(cs, "%s", cs->dlog);
41683 }
41684 }
41685
41686diff --git a/drivers/isdn/hisax/ipacx.c b/drivers/isdn/hisax/ipacx.c
41687index 74feb5c..5faa5de 100644
41688--- a/drivers/isdn/hisax/ipacx.c
41689+++ b/drivers/isdn/hisax/ipacx.c
41690@@ -260,7 +260,7 @@ dch_empty_fifo(struct IsdnCardState *cs, int count)
41691
41692 t += sprintf(t, "dch_empty_fifo() cnt %d", count);
41693 QuickHex(t, ptr, count);
41694- debugl1(cs, cs->dlog);
41695+ debugl1(cs, "%s", cs->dlog);
41696 }
41697 }
41698
41699@@ -307,7 +307,7 @@ dch_fill_fifo(struct IsdnCardState *cs)
41700
41701 t += sprintf(t, "dch_fill_fifo() cnt %d", count);
41702 QuickHex(t, ptr, count);
41703- debugl1(cs, cs->dlog);
41704+ debugl1(cs, "%s", cs->dlog);
41705 }
41706 }
41707
41708@@ -539,7 +539,7 @@ bch_empty_fifo(struct BCState *bcs, int count)
41709
41710 t += sprintf(t, "bch_empty_fifo() B-%d cnt %d", hscx, count);
41711 QuickHex(t, ptr, count);
41712- debugl1(cs, bcs->blog);
41713+ debugl1(cs, "%s", bcs->blog);
41714 }
41715 }
41716
41717@@ -582,7 +582,7 @@ bch_fill_fifo(struct BCState *bcs)
41718
41719 t += sprintf(t, "chb_fill_fifo() B-%d cnt %d", hscx, count);
41720 QuickHex(t, ptr, count);
41721- debugl1(cs, bcs->blog);
41722+ debugl1(cs, "%s", bcs->blog);
41723 }
41724 }
41725
41726diff --git a/drivers/isdn/hisax/isac.c b/drivers/isdn/hisax/isac.c
41727index a365ccc..7fdf78f 100644
41728--- a/drivers/isdn/hisax/isac.c
41729+++ b/drivers/isdn/hisax/isac.c
41730@@ -137,7 +137,7 @@ isac_empty_fifo(struct IsdnCardState *cs, int count)
41731
41732 t += sprintf(t, "isac_empty_fifo cnt %d", count);
41733 QuickHex(t, ptr, count);
41734- debugl1(cs, cs->dlog);
41735+ debugl1(cs, "%s", cs->dlog);
41736 }
41737 }
41738
41739@@ -179,7 +179,7 @@ isac_fill_fifo(struct IsdnCardState *cs)
41740
41741 t += sprintf(t, "isac_fill_fifo cnt %d", count);
41742 QuickHex(t, ptr, count);
41743- debugl1(cs, cs->dlog);
41744+ debugl1(cs, "%s", cs->dlog);
41745 }
41746 }
41747
41748diff --git a/drivers/isdn/hisax/isar.c b/drivers/isdn/hisax/isar.c
41749index 7fdf347..f4956c7 100644
41750--- a/drivers/isdn/hisax/isar.c
41751+++ b/drivers/isdn/hisax/isar.c
41752@@ -74,7 +74,7 @@ sendmsg(struct IsdnCardState *cs, u_char his, u_char creg, u_char len,
41753 t = tmp;
41754 t += sprintf(t, "sendmbox cnt %d", len);
41755 QuickHex(t, &msg[len-i], (i > 64) ? 64 : i);
41756- debugl1(cs, tmp);
41757+ debugl1(cs, "%s", tmp);
41758 i -= 64;
41759 }
41760 }
41761@@ -105,7 +105,7 @@ rcv_mbox(struct IsdnCardState *cs, struct isar_reg *ireg, u_char *msg)
41762 t = tmp;
41763 t += sprintf(t, "rcv_mbox cnt %d", ireg->clsb);
41764 QuickHex(t, &msg[ireg->clsb - i], (i > 64) ? 64 : i);
41765- debugl1(cs, tmp);
41766+ debugl1(cs, "%s", tmp);
41767 i -= 64;
41768 }
41769 }
41770@@ -1248,7 +1248,7 @@ isar_int_main(struct IsdnCardState *cs)
41771 tp += sprintf(debbuf, "msg iis(%x) msb(%x)",
41772 ireg->iis, ireg->cmsb);
41773 QuickHex(tp, (u_char *)ireg->par, ireg->clsb);
41774- debugl1(cs, debbuf);
41775+ debugl1(cs, "%s", debbuf);
41776 }
41777 break;
41778 case ISAR_IIS_INVMSG:
41779diff --git a/drivers/isdn/hisax/jade.c b/drivers/isdn/hisax/jade.c
41780index f946c58..e2ae787 100644
41781--- a/drivers/isdn/hisax/jade.c
41782+++ b/drivers/isdn/hisax/jade.c
41783@@ -81,10 +81,7 @@ modejade(struct BCState *bcs, int mode, int bc)
41784 int jade = bcs->hw.hscx.hscx;
41785
41786 if (cs->debug & L1_DEB_HSCX) {
41787- char tmp[40];
41788- sprintf(tmp, "jade %c mode %d ichan %d",
41789- 'A' + jade, mode, bc);
41790- debugl1(cs, tmp);
41791+ debugl1(cs, "jade %c mode %d ichan %d", 'A' + jade, mode, bc);
41792 }
41793 bcs->mode = mode;
41794 bcs->channel = bc;
41795@@ -257,23 +254,18 @@ void
41796 clear_pending_jade_ints(struct IsdnCardState *cs)
41797 {
41798 int val;
41799- char tmp[64];
41800
41801 cs->BC_Write_Reg(cs, 0, jade_HDLC_IMR, 0x00);
41802 cs->BC_Write_Reg(cs, 1, jade_HDLC_IMR, 0x00);
41803
41804 val = cs->BC_Read_Reg(cs, 1, jade_HDLC_ISR);
41805- sprintf(tmp, "jade B ISTA %x", val);
41806- debugl1(cs, tmp);
41807+ debugl1(cs, "jade B ISTA %x", val);
41808 val = cs->BC_Read_Reg(cs, 0, jade_HDLC_ISR);
41809- sprintf(tmp, "jade A ISTA %x", val);
41810- debugl1(cs, tmp);
41811+ debugl1(cs, "jade A ISTA %x", val);
41812 val = cs->BC_Read_Reg(cs, 1, jade_HDLC_STAR);
41813- sprintf(tmp, "jade B STAR %x", val);
41814- debugl1(cs, tmp);
41815+ debugl1(cs, "jade B STAR %x", val);
41816 val = cs->BC_Read_Reg(cs, 0, jade_HDLC_STAR);
41817- sprintf(tmp, "jade A STAR %x", val);
41818- debugl1(cs, tmp);
41819+ debugl1(cs, "jade A STAR %x", val);
41820 /* Unmask ints */
41821 cs->BC_Write_Reg(cs, 0, jade_HDLC_IMR, 0xF8);
41822 cs->BC_Write_Reg(cs, 1, jade_HDLC_IMR, 0xF8);
41823diff --git a/drivers/isdn/hisax/jade_irq.c b/drivers/isdn/hisax/jade_irq.c
41824index f521fc8..b930da9 100644
41825--- a/drivers/isdn/hisax/jade_irq.c
41826+++ b/drivers/isdn/hisax/jade_irq.c
41827@@ -65,7 +65,7 @@ jade_empty_fifo(struct BCState *bcs, int count)
41828 t += sprintf(t, "jade_empty_fifo %c cnt %d",
41829 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41830 QuickHex(t, ptr, count);
41831- debugl1(cs, bcs->blog);
41832+ debugl1(cs, "%s", bcs->blog);
41833 }
41834 }
41835
41836@@ -105,7 +105,7 @@ jade_fill_fifo(struct BCState *bcs)
41837 t += sprintf(t, "jade_fill_fifo %c cnt %d",
41838 bcs->hw.hscx.hscx ? 'B' : 'A', count);
41839 QuickHex(t, ptr, count);
41840- debugl1(cs, bcs->blog);
41841+ debugl1(cs, "%s", bcs->blog);
41842 }
41843 }
41844
41845diff --git a/drivers/isdn/hisax/l3_1tr6.c b/drivers/isdn/hisax/l3_1tr6.c
41846index 4c1bca5..875402e 100644
41847--- a/drivers/isdn/hisax/l3_1tr6.c
41848+++ b/drivers/isdn/hisax/l3_1tr6.c
41849@@ -63,7 +63,7 @@ l3_1tr6_error(struct l3_process *pc, u_char *msg, struct sk_buff *skb)
41850 {
41851 dev_kfree_skb(skb);
41852 if (pc->st->l3.debug & L3_DEB_WARN)
41853- l3_debug(pc->st, msg);
41854+ l3_debug(pc->st, "%s", msg);
41855 l3_1tr6_release_req(pc, 0, NULL);
41856 }
41857
41858@@ -161,7 +161,6 @@ l3_1tr6_setup(struct l3_process *pc, u_char pr, void *arg)
41859 {
41860 u_char *p;
41861 int bcfound = 0;
41862- char tmp[80];
41863 struct sk_buff *skb = arg;
41864
41865 /* Channel Identification */
41866@@ -214,10 +213,9 @@ l3_1tr6_setup(struct l3_process *pc, u_char pr, void *arg)
41867 /* Signal all services, linklevel takes care of Service-Indicator */
41868 if (bcfound) {
41869 if ((pc->para.setup.si1 != 7) && (pc->st->l3.debug & L3_DEB_WARN)) {
41870- sprintf(tmp, "non-digital call: %s -> %s",
41871+ l3_debug(pc->st, "non-digital call: %s -> %s",
41872 pc->para.setup.phone,
41873 pc->para.setup.eazmsn);
41874- l3_debug(pc->st, tmp);
41875 }
41876 newl3state(pc, 6);
41877 pc->st->l3.l3l4(pc->st, CC_SETUP | INDICATION, pc);
41878@@ -301,7 +299,7 @@ l3_1tr6_info(struct l3_process *pc, u_char pr, void *arg)
41879 {
41880 u_char *p;
41881 int i, tmpcharge = 0;
41882- char a_charge[8], tmp[32];
41883+ char a_charge[8];
41884 struct sk_buff *skb = arg;
41885
41886 p = skb->data;
41887@@ -316,8 +314,8 @@ l3_1tr6_info(struct l3_process *pc, u_char pr, void *arg)
41888 pc->st->l3.l3l4(pc->st, CC_CHARGE | INDICATION, pc);
41889 }
41890 if (pc->st->l3.debug & L3_DEB_CHARGE) {
41891- sprintf(tmp, "charging info %d", pc->para.chargeinfo);
41892- l3_debug(pc->st, tmp);
41893+ l3_debug(pc->st, "charging info %d",
41894+ pc->para.chargeinfo);
41895 }
41896 } else if (pc->st->l3.debug & L3_DEB_CHARGE)
41897 l3_debug(pc->st, "charging info not found");
41898@@ -399,7 +397,7 @@ l3_1tr6_disc(struct l3_process *pc, u_char pr, void *arg)
41899 struct sk_buff *skb = arg;
41900 u_char *p;
41901 int i, tmpcharge = 0;
41902- char a_charge[8], tmp[32];
41903+ char a_charge[8];
41904
41905 StopAllL3Timer(pc);
41906 p = skb->data;
41907@@ -414,8 +412,8 @@ l3_1tr6_disc(struct l3_process *pc, u_char pr, void *arg)
41908 pc->st->l3.l3l4(pc->st, CC_CHARGE | INDICATION, pc);
41909 }
41910 if (pc->st->l3.debug & L3_DEB_CHARGE) {
41911- sprintf(tmp, "charging info %d", pc->para.chargeinfo);
41912- l3_debug(pc->st, tmp);
41913+ l3_debug(pc->st, "charging info %d",
41914+ pc->para.chargeinfo);
41915 }
41916 } else if (pc->st->l3.debug & L3_DEB_CHARGE)
41917 l3_debug(pc->st, "charging info not found");
41918@@ -746,7 +744,6 @@ up1tr6(struct PStack *st, int pr, void *arg)
41919 int i, mt, cr;
41920 struct l3_process *proc;
41921 struct sk_buff *skb = arg;
41922- char tmp[80];
41923
41924 switch (pr) {
41925 case (DL_DATA | INDICATION):
41926@@ -762,26 +759,23 @@ up1tr6(struct PStack *st, int pr, void *arg)
41927 }
41928 if (skb->len < 4) {
41929 if (st->l3.debug & L3_DEB_PROTERR) {
41930- sprintf(tmp, "up1tr6 len only %d", skb->len);
41931- l3_debug(st, tmp);
41932+ l3_debug(st, "up1tr6 len only %d", skb->len);
41933 }
41934 dev_kfree_skb(skb);
41935 return;
41936 }
41937 if ((skb->data[0] & 0xfe) != PROTO_DIS_N0) {
41938 if (st->l3.debug & L3_DEB_PROTERR) {
41939- sprintf(tmp, "up1tr6%sunexpected discriminator %x message len %d",
41940+ l3_debug(st, "up1tr6%sunexpected discriminator %x message len %d",
41941 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
41942 skb->data[0], skb->len);
41943- l3_debug(st, tmp);
41944 }
41945 dev_kfree_skb(skb);
41946 return;
41947 }
41948 if (skb->data[1] != 1) {
41949 if (st->l3.debug & L3_DEB_PROTERR) {
41950- sprintf(tmp, "up1tr6 CR len not 1");
41951- l3_debug(st, tmp);
41952+ l3_debug(st, "up1tr6 CR len not 1");
41953 }
41954 dev_kfree_skb(skb);
41955 return;
41956@@ -791,9 +785,8 @@ up1tr6(struct PStack *st, int pr, void *arg)
41957 if (skb->data[0] == PROTO_DIS_N0) {
41958 dev_kfree_skb(skb);
41959 if (st->l3.debug & L3_DEB_STATE) {
41960- sprintf(tmp, "up1tr6%s N0 mt %x unhandled",
41961+ l3_debug(st, "up1tr6%s N0 mt %x unhandled",
41962 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ", mt);
41963- l3_debug(st, tmp);
41964 }
41965 } else if (skb->data[0] == PROTO_DIS_N1) {
41966 if (!(proc = getl3proc(st, cr))) {
41967@@ -801,8 +794,7 @@ up1tr6(struct PStack *st, int pr, void *arg)
41968 if (cr < 128) {
41969 if (!(proc = new_l3_process(st, cr))) {
41970 if (st->l3.debug & L3_DEB_PROTERR) {
41971- sprintf(tmp, "up1tr6 no roc mem");
41972- l3_debug(st, tmp);
41973+ l3_debug(st, "up1tr6 no roc mem");
41974 }
41975 dev_kfree_skb(skb);
41976 return;
41977@@ -821,8 +813,7 @@ up1tr6(struct PStack *st, int pr, void *arg)
41978 } else {
41979 if (!(proc = new_l3_process(st, cr))) {
41980 if (st->l3.debug & L3_DEB_PROTERR) {
41981- sprintf(tmp, "up1tr6 no roc mem");
41982- l3_debug(st, tmp);
41983+ l3_debug(st, "up1tr6 no roc mem");
41984 }
41985 dev_kfree_skb(skb);
41986 return;
41987@@ -837,18 +828,16 @@ up1tr6(struct PStack *st, int pr, void *arg)
41988 if (i == ARRAY_SIZE(datastln1)) {
41989 dev_kfree_skb(skb);
41990 if (st->l3.debug & L3_DEB_STATE) {
41991- sprintf(tmp, "up1tr6%sstate %d mt %x unhandled",
41992+ l3_debug(st, "up1tr6%sstate %d mt %x unhandled",
41993 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
41994 proc->state, mt);
41995- l3_debug(st, tmp);
41996 }
41997 return;
41998 } else {
41999 if (st->l3.debug & L3_DEB_STATE) {
42000- sprintf(tmp, "up1tr6%sstate %d mt %x",
42001+ l3_debug(st, "up1tr6%sstate %d mt %x",
42002 (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
42003 proc->state, mt);
42004- l3_debug(st, tmp);
42005 }
42006 datastln1[i].rout(proc, pr, skb);
42007 }
42008@@ -861,7 +850,6 @@ down1tr6(struct PStack *st, int pr, void *arg)
42009 int i, cr;
42010 struct l3_process *proc;
42011 struct Channel *chan;
42012- char tmp[80];
42013
42014 if ((DL_ESTABLISH | REQUEST) == pr) {
42015 l3_msg(st, pr, NULL);
42016@@ -888,15 +876,13 @@ down1tr6(struct PStack *st, int pr, void *arg)
42017 break;
42018 if (i == ARRAY_SIZE(downstl)) {
42019 if (st->l3.debug & L3_DEB_STATE) {
42020- sprintf(tmp, "down1tr6 state %d prim %d unhandled",
42021+ l3_debug(st, "down1tr6 state %d prim %d unhandled",
42022 proc->state, pr);
42023- l3_debug(st, tmp);
42024 }
42025 } else {
42026 if (st->l3.debug & L3_DEB_STATE) {
42027- sprintf(tmp, "down1tr6 state %d prim %d",
42028+ l3_debug(st, "down1tr6 state %d prim %d",
42029 proc->state, pr);
42030- l3_debug(st, tmp);
42031 }
42032 downstl[i].rout(proc, pr, arg);
42033 }
42034diff --git a/drivers/isdn/hisax/netjet.c b/drivers/isdn/hisax/netjet.c
42035index b646eed..233e432 100644
42036--- a/drivers/isdn/hisax/netjet.c
42037+++ b/drivers/isdn/hisax/netjet.c
42038@@ -176,7 +176,7 @@ static void printframe(struct IsdnCardState *cs, u_char *buf, int count, char *s
42039 else
42040 j = i;
42041 QuickHex(t, p, j);
42042- debugl1(cs, tmp);
42043+ debugl1(cs, "%s", tmp);
42044 p += j;
42045 i -= j;
42046 t = tmp;
42047diff --git a/drivers/isdn/hisax/q931.c b/drivers/isdn/hisax/q931.c
42048index 041bf52..af1b020 100644
42049--- a/drivers/isdn/hisax/q931.c
42050+++ b/drivers/isdn/hisax/q931.c
42051@@ -1179,7 +1179,7 @@ LogFrame(struct IsdnCardState *cs, u_char *buf, int size)
42052 dp--;
42053 *dp++ = '\n';
42054 *dp = 0;
42055- HiSax_putstatus(cs, NULL, cs->dlog);
42056+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
42057 } else
42058 HiSax_putstatus(cs, "LogFrame: ", "warning Frame too big (%d)", size);
42059 }
42060@@ -1246,7 +1246,7 @@ dlogframe(struct IsdnCardState *cs, struct sk_buff *skb, int dir)
42061 }
42062 if (finish) {
42063 *dp = 0;
42064- HiSax_putstatus(cs, NULL, cs->dlog);
42065+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
42066 return;
42067 }
42068 if ((0xfe & buf[0]) == PROTO_DIS_N0) { /* 1TR6 */
42069@@ -1509,5 +1509,5 @@ dlogframe(struct IsdnCardState *cs, struct sk_buff *skb, int dir)
42070 dp += sprintf(dp, "Unknown protocol %x!", buf[0]);
42071 }
42072 *dp = 0;
42073- HiSax_putstatus(cs, NULL, cs->dlog);
42074+ HiSax_putstatus(cs, NULL, "%s", cs->dlog);
42075 }
42076diff --git a/drivers/isdn/hisax/w6692.c b/drivers/isdn/hisax/w6692.c
42077index d8cac69..a858955 100644
42078--- a/drivers/isdn/hisax/w6692.c
42079+++ b/drivers/isdn/hisax/w6692.c
42080@@ -154,7 +154,7 @@ W6692_empty_fifo(struct IsdnCardState *cs, int count)
42081
42082 t += sprintf(t, "W6692_empty_fifo cnt %d", count);
42083 QuickHex(t, ptr, count);
42084- debugl1(cs, cs->dlog);
42085+ debugl1(cs, "%s", cs->dlog);
42086 }
42087 }
42088
42089@@ -196,7 +196,7 @@ W6692_fill_fifo(struct IsdnCardState *cs)
42090
42091 t += sprintf(t, "W6692_fill_fifo cnt %d", count);
42092 QuickHex(t, ptr, count);
42093- debugl1(cs, cs->dlog);
42094+ debugl1(cs, "%s", cs->dlog);
42095 }
42096 }
42097
42098@@ -226,7 +226,7 @@ W6692B_empty_fifo(struct BCState *bcs, int count)
42099 t += sprintf(t, "W6692B_empty_fifo %c cnt %d",
42100 bcs->channel + '1', count);
42101 QuickHex(t, ptr, count);
42102- debugl1(cs, bcs->blog);
42103+ debugl1(cs, "%s", bcs->blog);
42104 }
42105 }
42106
42107@@ -264,7 +264,7 @@ W6692B_fill_fifo(struct BCState *bcs)
42108 t += sprintf(t, "W6692B_fill_fifo %c cnt %d",
42109 bcs->channel + '1', count);
42110 QuickHex(t, ptr, count);
42111- debugl1(cs, bcs->blog);
42112+ debugl1(cs, "%s", bcs->blog);
42113 }
42114 }
42115
42116diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
42117index 9bb12ba..d4262f7 100644
42118--- a/drivers/isdn/i4l/isdn_common.c
42119+++ b/drivers/isdn/i4l/isdn_common.c
42120@@ -1651,6 +1651,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
42121 } else
42122 return -EINVAL;
42123 case IIOCDBGVAR:
42124+ if (!capable(CAP_SYS_RAWIO))
42125+ return -EPERM;
42126 if (arg) {
42127 if (copy_to_user(argp, &dev, sizeof(ulong)))
42128 return -EFAULT;
42129diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
42130index 3c5f249..5fac4d0 100644
42131--- a/drivers/isdn/i4l/isdn_tty.c
42132+++ b/drivers/isdn/i4l/isdn_tty.c
42133@@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
42134
42135 #ifdef ISDN_DEBUG_MODEM_OPEN
42136 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
42137- port->count);
42138+ atomic_read(&port->count));
42139 #endif
42140- port->count++;
42141+ atomic_inc(&port->count);
42142 port->tty = tty;
42143 /*
42144 * Start up serial port
42145@@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
42146 #endif
42147 return;
42148 }
42149- if ((tty->count == 1) && (port->count != 1)) {
42150+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
42151 /*
42152 * Uh, oh. tty->count is 1, which means that the tty
42153 * structure will be freed. Info->count should always
42154@@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
42155 * serial port won't be shutdown.
42156 */
42157 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
42158- "info->count is %d\n", port->count);
42159- port->count = 1;
42160+ "info->count is %d\n", atomic_read(&port->count));
42161+ atomic_set(&port->count, 1);
42162 }
42163- if (--port->count < 0) {
42164+ if (atomic_dec_return(&port->count) < 0) {
42165 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
42166- info->line, port->count);
42167- port->count = 0;
42168+ info->line, atomic_read(&port->count));
42169+ atomic_set(&port->count, 0);
42170 }
42171- if (port->count) {
42172+ if (atomic_read(&port->count)) {
42173 #ifdef ISDN_DEBUG_MODEM_OPEN
42174 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
42175 #endif
42176@@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
42177 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
42178 return;
42179 isdn_tty_shutdown(info);
42180- port->count = 0;
42181+ atomic_set(&port->count, 0);
42182 port->flags &= ~ASYNC_NORMAL_ACTIVE;
42183 port->tty = NULL;
42184 wake_up_interruptible(&port->open_wait);
42185@@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
42186 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
42187 modem_info *info = &dev->mdm.info[i];
42188
42189- if (info->port.count == 0)
42190+ if (atomic_read(&info->port.count) == 0)
42191 continue;
42192 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
42193 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
42194diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
42195index e74df7c..03a03ba 100644
42196--- a/drivers/isdn/icn/icn.c
42197+++ b/drivers/isdn/icn/icn.c
42198@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
42199 if (count > len)
42200 count = len;
42201 if (user) {
42202- if (copy_from_user(msg, buf, count))
42203+ if (count > sizeof msg || copy_from_user(msg, buf, count))
42204 return -EFAULT;
42205 } else
42206 memcpy(msg, buf, count);
42207diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
42208index 6a8405d..0bd1c7e 100644
42209--- a/drivers/leds/leds-clevo-mail.c
42210+++ b/drivers/leds/leds-clevo-mail.c
42211@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
42212 * detected as working, but in reality it is not) as low as
42213 * possible.
42214 */
42215-static struct dmi_system_id __initdata clevo_mail_led_dmi_table[] = {
42216+static const struct dmi_system_id __initconst clevo_mail_led_dmi_table[] = {
42217 {
42218 .callback = clevo_mail_led_dmi_callback,
42219 .ident = "Clevo D410J",
42220diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
42221index 64e204e..c6bf189 100644
42222--- a/drivers/leds/leds-ss4200.c
42223+++ b/drivers/leds/leds-ss4200.c
42224@@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
42225 * detected as working, but in reality it is not) as low as
42226 * possible.
42227 */
42228-static struct dmi_system_id __initdata nas_led_whitelist[] = {
42229+static const struct dmi_system_id __initconst nas_led_whitelist[] = {
42230 {
42231 .callback = ss4200_led_dmi_callback,
42232 .ident = "Intel SS4200-E",
42233diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
42234index 0bf1e4e..b4bf44e 100644
42235--- a/drivers/lguest/core.c
42236+++ b/drivers/lguest/core.c
42237@@ -97,9 +97,17 @@ static __init int map_switcher(void)
42238 * The end address needs +1 because __get_vm_area allocates an
42239 * extra guard page, so we need space for that.
42240 */
42241+
42242+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
42243+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
42244+ VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
42245+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
42246+#else
42247 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
42248 VM_ALLOC, switcher_addr, switcher_addr
42249 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
42250+#endif
42251+
42252 if (!switcher_vma) {
42253 err = -ENOMEM;
42254 printk("lguest: could not map switcher pages high\n");
42255@@ -124,7 +132,7 @@ static __init int map_switcher(void)
42256 * Now the Switcher is mapped at the right address, we can't fail!
42257 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
42258 */
42259- memcpy(switcher_vma->addr, start_switcher_text,
42260+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
42261 end_switcher_text - start_switcher_text);
42262
42263 printk(KERN_INFO "lguest: mapped switcher at %p\n",
42264diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
42265index a35d8d1..59fb772 100644
42266--- a/drivers/lguest/page_tables.c
42267+++ b/drivers/lguest/page_tables.c
42268@@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
42269 /*:*/
42270
42271 #ifdef CONFIG_X86_PAE
42272-static void release_pmd(pmd_t *spmd)
42273+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
42274 {
42275 /* If the entry's not present, there's nothing to release. */
42276 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
42277diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
42278index 5169239..47cb4db 100644
42279--- a/drivers/lguest/x86/core.c
42280+++ b/drivers/lguest/x86/core.c
42281@@ -59,7 +59,7 @@ static struct {
42282 /* Offset from where switcher.S was compiled to where we've copied it */
42283 static unsigned long switcher_offset(void)
42284 {
42285- return switcher_addr - (unsigned long)start_switcher_text;
42286+ return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
42287 }
42288
42289 /* This cpu's struct lguest_pages (after the Switcher text page) */
42290@@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
42291 * These copies are pretty cheap, so we do them unconditionally: */
42292 /* Save the current Host top-level page directory.
42293 */
42294+
42295+#ifdef CONFIG_PAX_PER_CPU_PGD
42296+ pages->state.host_cr3 = read_cr3();
42297+#else
42298 pages->state.host_cr3 = __pa(current->mm->pgd);
42299+#endif
42300+
42301 /*
42302 * Set up the Guest's page tables to see this CPU's pages (and no
42303 * other CPU's pages).
42304@@ -475,7 +481,7 @@ void __init lguest_arch_host_init(void)
42305 * compiled-in switcher code and the high-mapped copy we just made.
42306 */
42307 for (i = 0; i < IDT_ENTRIES; i++)
42308- default_idt_entries[i] += switcher_offset();
42309+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
42310
42311 /*
42312 * Set up the Switcher's per-cpu areas.
42313@@ -558,7 +564,7 @@ void __init lguest_arch_host_init(void)
42314 * it will be undisturbed when we switch. To change %cs and jump we
42315 * need this structure to feed to Intel's "lcall" instruction.
42316 */
42317- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
42318+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
42319 lguest_entry.segment = LGUEST_CS;
42320
42321 /*
42322diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
42323index 40634b0..4f5855e 100644
42324--- a/drivers/lguest/x86/switcher_32.S
42325+++ b/drivers/lguest/x86/switcher_32.S
42326@@ -87,6 +87,7 @@
42327 #include <asm/page.h>
42328 #include <asm/segment.h>
42329 #include <asm/lguest.h>
42330+#include <asm/processor-flags.h>
42331
42332 // We mark the start of the code to copy
42333 // It's placed in .text tho it's never run here
42334@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
42335 // Changes type when we load it: damn Intel!
42336 // For after we switch over our page tables
42337 // That entry will be read-only: we'd crash.
42338+
42339+#ifdef CONFIG_PAX_KERNEXEC
42340+ mov %cr0, %edx
42341+ xor $X86_CR0_WP, %edx
42342+ mov %edx, %cr0
42343+#endif
42344+
42345 movl $(GDT_ENTRY_TSS*8), %edx
42346 ltr %dx
42347
42348@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
42349 // Let's clear it again for our return.
42350 // The GDT descriptor of the Host
42351 // Points to the table after two "size" bytes
42352- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
42353+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
42354 // Clear "used" from type field (byte 5, bit 2)
42355- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
42356+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
42357+
42358+#ifdef CONFIG_PAX_KERNEXEC
42359+ mov %cr0, %eax
42360+ xor $X86_CR0_WP, %eax
42361+ mov %eax, %cr0
42362+#endif
42363
42364 // Once our page table's switched, the Guest is live!
42365 // The Host fades as we run this final step.
42366@@ -295,13 +309,12 @@ deliver_to_host:
42367 // I consulted gcc, and it gave
42368 // These instructions, which I gladly credit:
42369 leal (%edx,%ebx,8), %eax
42370- movzwl (%eax),%edx
42371- movl 4(%eax), %eax
42372- xorw %ax, %ax
42373- orl %eax, %edx
42374+ movl 4(%eax), %edx
42375+ movw (%eax), %dx
42376 // Now the address of the handler's in %edx
42377 // We call it now: its "iret" drops us home.
42378- jmp *%edx
42379+ ljmp $__KERNEL_CS, $1f
42380+1: jmp *%edx
42381
42382 // Every interrupt can come to us here
42383 // But we must truly tell each apart.
42384diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
42385index 0003992..854bbce 100644
42386--- a/drivers/md/bcache/closure.h
42387+++ b/drivers/md/bcache/closure.h
42388@@ -622,7 +622,7 @@ static inline void closure_wake_up(struct closure_waitlist *list)
42389 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
42390 struct workqueue_struct *wq)
42391 {
42392- BUG_ON(object_is_on_stack(cl));
42393+ BUG_ON(object_starts_on_stack(cl));
42394 closure_set_ip(cl);
42395 cl->fn = fn;
42396 cl->wq = wq;
42397diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
42398index 547c4c5..5be1de4 100644
42399--- a/drivers/md/bcache/super.c
42400+++ b/drivers/md/bcache/super.c
42401@@ -1644,7 +1644,7 @@ err_unlock_gc:
42402 err:
42403 closure_sync(&op.cl);
42404 /* XXX: test this, it's broken */
42405- bch_cache_set_error(c, err);
42406+ bch_cache_set_error(c, "%s", err);
42407 }
42408
42409 static bool can_attach_cache(struct cache *ca, struct cache_set *c)
42410diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
42411index a7fd821..9dcf6c3 100644
42412--- a/drivers/md/bitmap.c
42413+++ b/drivers/md/bitmap.c
42414@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
42415 chunk_kb ? "KB" : "B");
42416 if (bitmap->storage.file) {
42417 seq_printf(seq, ", file: ");
42418- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
42419+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
42420 }
42421
42422 seq_printf(seq, "\n");
42423diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
42424index f1b7586..a49c4bd 100644
42425--- a/drivers/md/dm-ioctl.c
42426+++ b/drivers/md/dm-ioctl.c
42427@@ -1739,7 +1739,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
42428 cmd == DM_LIST_VERSIONS_CMD)
42429 return 0;
42430
42431- if ((cmd == DM_DEV_CREATE_CMD)) {
42432+ if (cmd == DM_DEV_CREATE_CMD) {
42433 if (!*param->name) {
42434 DMWARN("name not supplied when creating device");
42435 return -EINVAL;
42436diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
42437index 699b5be..eac0a15 100644
42438--- a/drivers/md/dm-raid1.c
42439+++ b/drivers/md/dm-raid1.c
42440@@ -40,7 +40,7 @@ enum dm_raid1_error {
42441
42442 struct mirror {
42443 struct mirror_set *ms;
42444- atomic_t error_count;
42445+ atomic_unchecked_t error_count;
42446 unsigned long error_type;
42447 struct dm_dev *dev;
42448 sector_t offset;
42449@@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
42450 struct mirror *m;
42451
42452 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
42453- if (!atomic_read(&m->error_count))
42454+ if (!atomic_read_unchecked(&m->error_count))
42455 return m;
42456
42457 return NULL;
42458@@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
42459 * simple way to tell if a device has encountered
42460 * errors.
42461 */
42462- atomic_inc(&m->error_count);
42463+ atomic_inc_unchecked(&m->error_count);
42464
42465 if (test_and_set_bit(error_type, &m->error_type))
42466 return;
42467@@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
42468 struct mirror *m = get_default_mirror(ms);
42469
42470 do {
42471- if (likely(!atomic_read(&m->error_count)))
42472+ if (likely(!atomic_read_unchecked(&m->error_count)))
42473 return m;
42474
42475 if (m-- == ms->mirror)
42476@@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
42477 {
42478 struct mirror *default_mirror = get_default_mirror(m->ms);
42479
42480- return !atomic_read(&default_mirror->error_count);
42481+ return !atomic_read_unchecked(&default_mirror->error_count);
42482 }
42483
42484 static int mirror_available(struct mirror_set *ms, struct bio *bio)
42485@@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
42486 */
42487 if (likely(region_in_sync(ms, region, 1)))
42488 m = choose_mirror(ms, bio->bi_sector);
42489- else if (m && atomic_read(&m->error_count))
42490+ else if (m && atomic_read_unchecked(&m->error_count))
42491 m = NULL;
42492
42493 if (likely(m))
42494@@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
42495 }
42496
42497 ms->mirror[mirror].ms = ms;
42498- atomic_set(&(ms->mirror[mirror].error_count), 0);
42499+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
42500 ms->mirror[mirror].error_type = 0;
42501 ms->mirror[mirror].offset = offset;
42502
42503@@ -1340,7 +1340,7 @@ static void mirror_resume(struct dm_target *ti)
42504 */
42505 static char device_status_char(struct mirror *m)
42506 {
42507- if (!atomic_read(&(m->error_count)))
42508+ if (!atomic_read_unchecked(&(m->error_count)))
42509 return 'A';
42510
42511 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
42512diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
42513index d907ca6..cfb8384 100644
42514--- a/drivers/md/dm-stripe.c
42515+++ b/drivers/md/dm-stripe.c
42516@@ -20,7 +20,7 @@ struct stripe {
42517 struct dm_dev *dev;
42518 sector_t physical_start;
42519
42520- atomic_t error_count;
42521+ atomic_unchecked_t error_count;
42522 };
42523
42524 struct stripe_c {
42525@@ -185,7 +185,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
42526 kfree(sc);
42527 return r;
42528 }
42529- atomic_set(&(sc->stripe[i].error_count), 0);
42530+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
42531 }
42532
42533 ti->private = sc;
42534@@ -326,7 +326,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
42535 DMEMIT("%d ", sc->stripes);
42536 for (i = 0; i < sc->stripes; i++) {
42537 DMEMIT("%s ", sc->stripe[i].dev->name);
42538- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
42539+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
42540 'D' : 'A';
42541 }
42542 buffer[i] = '\0';
42543@@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
42544 */
42545 for (i = 0; i < sc->stripes; i++)
42546 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
42547- atomic_inc(&(sc->stripe[i].error_count));
42548- if (atomic_read(&(sc->stripe[i].error_count)) <
42549+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
42550+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
42551 DM_IO_ERROR_THRESHOLD)
42552 schedule_work(&sc->trigger_event);
42553 }
42554diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
42555index f221812..aca962b 100644
42556--- a/drivers/md/dm-table.c
42557+++ b/drivers/md/dm-table.c
42558@@ -354,7 +354,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
42559 if (!dev_size)
42560 return 0;
42561
42562- if ((start >= dev_size) || (start + len > dev_size)) {
42563+ if ((start >= dev_size) || (len > dev_size - start)) {
42564 DMWARN("%s: %s too small for target: "
42565 "start=%llu, len=%llu, dev_size=%llu",
42566 dm_device_name(ti->table->md), bdevname(bdev, b),
42567diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
42568index 60bce43..9b997d0 100644
42569--- a/drivers/md/dm-thin-metadata.c
42570+++ b/drivers/md/dm-thin-metadata.c
42571@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
42572 {
42573 pmd->info.tm = pmd->tm;
42574 pmd->info.levels = 2;
42575- pmd->info.value_type.context = pmd->data_sm;
42576+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
42577 pmd->info.value_type.size = sizeof(__le64);
42578 pmd->info.value_type.inc = data_block_inc;
42579 pmd->info.value_type.dec = data_block_dec;
42580@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
42581
42582 pmd->bl_info.tm = pmd->tm;
42583 pmd->bl_info.levels = 1;
42584- pmd->bl_info.value_type.context = pmd->data_sm;
42585+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
42586 pmd->bl_info.value_type.size = sizeof(__le64);
42587 pmd->bl_info.value_type.inc = data_block_inc;
42588 pmd->bl_info.value_type.dec = data_block_dec;
42589diff --git a/drivers/md/dm.c b/drivers/md/dm.c
42590index 9e39d2b..fb879a7 100644
42591--- a/drivers/md/dm.c
42592+++ b/drivers/md/dm.c
42593@@ -178,9 +178,9 @@ struct mapped_device {
42594 /*
42595 * Event handling.
42596 */
42597- atomic_t event_nr;
42598+ atomic_unchecked_t event_nr;
42599 wait_queue_head_t eventq;
42600- atomic_t uevent_seq;
42601+ atomic_unchecked_t uevent_seq;
42602 struct list_head uevent_list;
42603 spinlock_t uevent_lock; /* Protect access to uevent_list */
42604
42605@@ -1916,8 +1916,8 @@ static struct mapped_device *alloc_dev(int minor)
42606 spin_lock_init(&md->deferred_lock);
42607 atomic_set(&md->holders, 1);
42608 atomic_set(&md->open_count, 0);
42609- atomic_set(&md->event_nr, 0);
42610- atomic_set(&md->uevent_seq, 0);
42611+ atomic_set_unchecked(&md->event_nr, 0);
42612+ atomic_set_unchecked(&md->uevent_seq, 0);
42613 INIT_LIST_HEAD(&md->uevent_list);
42614 spin_lock_init(&md->uevent_lock);
42615
42616@@ -2068,7 +2068,7 @@ static void event_callback(void *context)
42617
42618 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
42619
42620- atomic_inc(&md->event_nr);
42621+ atomic_inc_unchecked(&md->event_nr);
42622 wake_up(&md->eventq);
42623 }
42624
42625@@ -2716,18 +2716,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
42626
42627 uint32_t dm_next_uevent_seq(struct mapped_device *md)
42628 {
42629- return atomic_add_return(1, &md->uevent_seq);
42630+ return atomic_add_return_unchecked(1, &md->uevent_seq);
42631 }
42632
42633 uint32_t dm_get_event_nr(struct mapped_device *md)
42634 {
42635- return atomic_read(&md->event_nr);
42636+ return atomic_read_unchecked(&md->event_nr);
42637 }
42638
42639 int dm_wait_event(struct mapped_device *md, int event_nr)
42640 {
42641 return wait_event_interruptible(md->eventq,
42642- (event_nr != atomic_read(&md->event_nr)));
42643+ (event_nr != atomic_read_unchecked(&md->event_nr)));
42644 }
42645
42646 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
42647diff --git a/drivers/md/md.c b/drivers/md/md.c
42648index 9f13e13..411a5b8 100644
42649--- a/drivers/md/md.c
42650+++ b/drivers/md/md.c
42651@@ -234,10 +234,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
42652 * start build, activate spare
42653 */
42654 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
42655-static atomic_t md_event_count;
42656+static atomic_unchecked_t md_event_count;
42657 void md_new_event(struct mddev *mddev)
42658 {
42659- atomic_inc(&md_event_count);
42660+ atomic_inc_unchecked(&md_event_count);
42661 wake_up(&md_event_waiters);
42662 }
42663 EXPORT_SYMBOL_GPL(md_new_event);
42664@@ -247,7 +247,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
42665 */
42666 static void md_new_event_inintr(struct mddev *mddev)
42667 {
42668- atomic_inc(&md_event_count);
42669+ atomic_inc_unchecked(&md_event_count);
42670 wake_up(&md_event_waiters);
42671 }
42672
42673@@ -1502,7 +1502,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
42674 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
42675 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
42676 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
42677- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
42678+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
42679
42680 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
42681 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
42682@@ -1746,7 +1746,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
42683 else
42684 sb->resync_offset = cpu_to_le64(0);
42685
42686- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
42687+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
42688
42689 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
42690 sb->size = cpu_to_le64(mddev->dev_sectors);
42691@@ -2751,7 +2751,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
42692 static ssize_t
42693 errors_show(struct md_rdev *rdev, char *page)
42694 {
42695- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
42696+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
42697 }
42698
42699 static ssize_t
42700@@ -2760,7 +2760,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
42701 char *e;
42702 unsigned long n = simple_strtoul(buf, &e, 10);
42703 if (*buf && (*e == 0 || *e == '\n')) {
42704- atomic_set(&rdev->corrected_errors, n);
42705+ atomic_set_unchecked(&rdev->corrected_errors, n);
42706 return len;
42707 }
42708 return -EINVAL;
42709@@ -3208,8 +3208,8 @@ int md_rdev_init(struct md_rdev *rdev)
42710 rdev->sb_loaded = 0;
42711 rdev->bb_page = NULL;
42712 atomic_set(&rdev->nr_pending, 0);
42713- atomic_set(&rdev->read_errors, 0);
42714- atomic_set(&rdev->corrected_errors, 0);
42715+ atomic_set_unchecked(&rdev->read_errors, 0);
42716+ atomic_set_unchecked(&rdev->corrected_errors, 0);
42717
42718 INIT_LIST_HEAD(&rdev->same_set);
42719 init_waitqueue_head(&rdev->blocked_wait);
42720@@ -7024,7 +7024,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
42721
42722 spin_unlock(&pers_lock);
42723 seq_printf(seq, "\n");
42724- seq->poll_event = atomic_read(&md_event_count);
42725+ seq->poll_event = atomic_read_unchecked(&md_event_count);
42726 return 0;
42727 }
42728 if (v == (void*)2) {
42729@@ -7127,7 +7127,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
42730 return error;
42731
42732 seq = file->private_data;
42733- seq->poll_event = atomic_read(&md_event_count);
42734+ seq->poll_event = atomic_read_unchecked(&md_event_count);
42735 return error;
42736 }
42737
42738@@ -7141,7 +7141,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
42739 /* always allow read */
42740 mask = POLLIN | POLLRDNORM;
42741
42742- if (seq->poll_event != atomic_read(&md_event_count))
42743+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
42744 mask |= POLLERR | POLLPRI;
42745 return mask;
42746 }
42747@@ -7185,7 +7185,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
42748 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
42749 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
42750 (int)part_stat_read(&disk->part0, sectors[1]) -
42751- atomic_read(&disk->sync_io);
42752+ atomic_read_unchecked(&disk->sync_io);
42753 /* sync IO will cause sync_io to increase before the disk_stats
42754 * as sync_io is counted when a request starts, and
42755 * disk_stats is counted when it completes.
42756diff --git a/drivers/md/md.h b/drivers/md/md.h
42757index 20f02c0..fd8c821 100644
42758--- a/drivers/md/md.h
42759+++ b/drivers/md/md.h
42760@@ -94,13 +94,13 @@ struct md_rdev {
42761 * only maintained for arrays that
42762 * support hot removal
42763 */
42764- atomic_t read_errors; /* number of consecutive read errors that
42765+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
42766 * we have tried to ignore.
42767 */
42768 struct timespec last_read_error; /* monotonic time since our
42769 * last read error
42770 */
42771- atomic_t corrected_errors; /* number of corrected read errors,
42772+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
42773 * for reporting to userspace and storing
42774 * in superblock.
42775 */
42776@@ -442,7 +442,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
42777
42778 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
42779 {
42780- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
42781+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
42782 }
42783
42784 struct md_personality
42785diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
42786index 3e6d115..ffecdeb 100644
42787--- a/drivers/md/persistent-data/dm-space-map.h
42788+++ b/drivers/md/persistent-data/dm-space-map.h
42789@@ -71,6 +71,7 @@ struct dm_space_map {
42790 dm_sm_threshold_fn fn,
42791 void *context);
42792 };
42793+typedef struct dm_space_map __no_const dm_space_map_no_const;
42794
42795 /*----------------------------------------------------------------*/
42796
42797diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
42798index d60412c..8d4c982 100644
42799--- a/drivers/md/raid1.c
42800+++ b/drivers/md/raid1.c
42801@@ -1823,7 +1823,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
42802 if (r1_sync_page_io(rdev, sect, s,
42803 bio->bi_io_vec[idx].bv_page,
42804 READ) != 0)
42805- atomic_add(s, &rdev->corrected_errors);
42806+ atomic_add_unchecked(s, &rdev->corrected_errors);
42807 }
42808 sectors -= s;
42809 sect += s;
42810@@ -2050,7 +2050,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
42811 test_bit(In_sync, &rdev->flags)) {
42812 if (r1_sync_page_io(rdev, sect, s,
42813 conf->tmppage, READ)) {
42814- atomic_add(s, &rdev->corrected_errors);
42815+ atomic_add_unchecked(s, &rdev->corrected_errors);
42816 printk(KERN_INFO
42817 "md/raid1:%s: read error corrected "
42818 "(%d sectors at %llu on %s)\n",
42819diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
42820index df7b0a0..a257495 100644
42821--- a/drivers/md/raid10.c
42822+++ b/drivers/md/raid10.c
42823@@ -1962,7 +1962,7 @@ static void end_sync_read(struct bio *bio, int error)
42824 /* The write handler will notice the lack of
42825 * R10BIO_Uptodate and record any errors etc
42826 */
42827- atomic_add(r10_bio->sectors,
42828+ atomic_add_unchecked(r10_bio->sectors,
42829 &conf->mirrors[d].rdev->corrected_errors);
42830
42831 /* for reconstruct, we always reschedule after a read.
42832@@ -2320,7 +2320,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
42833 {
42834 struct timespec cur_time_mon;
42835 unsigned long hours_since_last;
42836- unsigned int read_errors = atomic_read(&rdev->read_errors);
42837+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
42838
42839 ktime_get_ts(&cur_time_mon);
42840
42841@@ -2342,9 +2342,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
42842 * overflowing the shift of read_errors by hours_since_last.
42843 */
42844 if (hours_since_last >= 8 * sizeof(read_errors))
42845- atomic_set(&rdev->read_errors, 0);
42846+ atomic_set_unchecked(&rdev->read_errors, 0);
42847 else
42848- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
42849+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
42850 }
42851
42852 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
42853@@ -2398,8 +2398,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
42854 return;
42855
42856 check_decay_read_errors(mddev, rdev);
42857- atomic_inc(&rdev->read_errors);
42858- if (atomic_read(&rdev->read_errors) > max_read_errors) {
42859+ atomic_inc_unchecked(&rdev->read_errors);
42860+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
42861 char b[BDEVNAME_SIZE];
42862 bdevname(rdev->bdev, b);
42863
42864@@ -2407,7 +2407,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
42865 "md/raid10:%s: %s: Raid device exceeded "
42866 "read_error threshold [cur %d:max %d]\n",
42867 mdname(mddev), b,
42868- atomic_read(&rdev->read_errors), max_read_errors);
42869+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
42870 printk(KERN_NOTICE
42871 "md/raid10:%s: %s: Failing raid device\n",
42872 mdname(mddev), b);
42873@@ -2562,7 +2562,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
42874 sect +
42875 choose_data_offset(r10_bio, rdev)),
42876 bdevname(rdev->bdev, b));
42877- atomic_add(s, &rdev->corrected_errors);
42878+ atomic_add_unchecked(s, &rdev->corrected_errors);
42879 }
42880
42881 rdev_dec_pending(rdev, mddev);
42882diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
42883index 78ea443..7d57513 100644
42884--- a/drivers/md/raid5.c
42885+++ b/drivers/md/raid5.c
42886@@ -1764,21 +1764,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
42887 mdname(conf->mddev), STRIPE_SECTORS,
42888 (unsigned long long)s,
42889 bdevname(rdev->bdev, b));
42890- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
42891+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
42892 clear_bit(R5_ReadError, &sh->dev[i].flags);
42893 clear_bit(R5_ReWrite, &sh->dev[i].flags);
42894 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
42895 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
42896
42897- if (atomic_read(&rdev->read_errors))
42898- atomic_set(&rdev->read_errors, 0);
42899+ if (atomic_read_unchecked(&rdev->read_errors))
42900+ atomic_set_unchecked(&rdev->read_errors, 0);
42901 } else {
42902 const char *bdn = bdevname(rdev->bdev, b);
42903 int retry = 0;
42904 int set_bad = 0;
42905
42906 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
42907- atomic_inc(&rdev->read_errors);
42908+ atomic_inc_unchecked(&rdev->read_errors);
42909 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
42910 printk_ratelimited(
42911 KERN_WARNING
42912@@ -1806,7 +1806,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
42913 mdname(conf->mddev),
42914 (unsigned long long)s,
42915 bdn);
42916- } else if (atomic_read(&rdev->read_errors)
42917+ } else if (atomic_read_unchecked(&rdev->read_errors)
42918 > conf->max_nr_stripes)
42919 printk(KERN_WARNING
42920 "md/raid:%s: Too many read errors, failing device %s.\n",
42921diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
42922index 401ef64..836e563 100644
42923--- a/drivers/media/dvb-core/dvbdev.c
42924+++ b/drivers/media/dvb-core/dvbdev.c
42925@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
42926 const struct dvb_device *template, void *priv, int type)
42927 {
42928 struct dvb_device *dvbdev;
42929- struct file_operations *dvbdevfops;
42930+ file_operations_no_const *dvbdevfops;
42931 struct device *clsdev;
42932 int minor;
42933 int id;
42934diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
42935index 9b6c3bb..baeb5c7 100644
42936--- a/drivers/media/dvb-frontends/dib3000.h
42937+++ b/drivers/media/dvb-frontends/dib3000.h
42938@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
42939 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
42940 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
42941 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
42942-};
42943+} __no_const;
42944
42945 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
42946 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
42947diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
42948index ecf21d9..b992428d 100644
42949--- a/drivers/media/pci/cx88/cx88-video.c
42950+++ b/drivers/media/pci/cx88/cx88-video.c
42951@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
42952
42953 /* ------------------------------------------------------------------ */
42954
42955-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42956-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42957-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42958+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42959+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42960+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
42961
42962 module_param_array(video_nr, int, NULL, 0444);
42963 module_param_array(vbi_nr, int, NULL, 0444);
42964diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
42965index c08ae3e..eb59af1 100644
42966--- a/drivers/media/pci/ivtv/ivtv-driver.c
42967+++ b/drivers/media/pci/ivtv/ivtv-driver.c
42968@@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
42969 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
42970
42971 /* ivtv instance counter */
42972-static atomic_t ivtv_instance = ATOMIC_INIT(0);
42973+static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
42974
42975 /* Parameter declarations */
42976 static int cardtype[IVTV_MAX_CARDS];
42977diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
42978index dfd0a21..6bbb465 100644
42979--- a/drivers/media/platform/omap/omap_vout.c
42980+++ b/drivers/media/platform/omap/omap_vout.c
42981@@ -63,7 +63,6 @@ enum omap_vout_channels {
42982 OMAP_VIDEO2,
42983 };
42984
42985-static struct videobuf_queue_ops video_vbq_ops;
42986 /* Variables configurable through module params*/
42987 static u32 video1_numbuffers = 3;
42988 static u32 video2_numbuffers = 3;
42989@@ -1014,6 +1013,12 @@ static int omap_vout_open(struct file *file)
42990 {
42991 struct videobuf_queue *q;
42992 struct omap_vout_device *vout = NULL;
42993+ static struct videobuf_queue_ops video_vbq_ops = {
42994+ .buf_setup = omap_vout_buffer_setup,
42995+ .buf_prepare = omap_vout_buffer_prepare,
42996+ .buf_release = omap_vout_buffer_release,
42997+ .buf_queue = omap_vout_buffer_queue,
42998+ };
42999
43000 vout = video_drvdata(file);
43001 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
43002@@ -1031,10 +1036,6 @@ static int omap_vout_open(struct file *file)
43003 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
43004
43005 q = &vout->vbq;
43006- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
43007- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
43008- video_vbq_ops.buf_release = omap_vout_buffer_release;
43009- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
43010 spin_lock_init(&vout->vbq_lock);
43011
43012 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
43013diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
43014index 04e6490..2df65bf 100644
43015--- a/drivers/media/platform/s5p-tv/mixer.h
43016+++ b/drivers/media/platform/s5p-tv/mixer.h
43017@@ -156,7 +156,7 @@ struct mxr_layer {
43018 /** layer index (unique identifier) */
43019 int idx;
43020 /** callbacks for layer methods */
43021- struct mxr_layer_ops ops;
43022+ struct mxr_layer_ops *ops;
43023 /** format array */
43024 const struct mxr_format **fmt_array;
43025 /** size of format array */
43026diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
43027index b93a21f..2535195 100644
43028--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
43029+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
43030@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
43031 {
43032 struct mxr_layer *layer;
43033 int ret;
43034- struct mxr_layer_ops ops = {
43035+ static struct mxr_layer_ops ops = {
43036 .release = mxr_graph_layer_release,
43037 .buffer_set = mxr_graph_buffer_set,
43038 .stream_set = mxr_graph_stream_set,
43039diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
43040index b713403..53cb5ad 100644
43041--- a/drivers/media/platform/s5p-tv/mixer_reg.c
43042+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
43043@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
43044 layer->update_buf = next;
43045 }
43046
43047- layer->ops.buffer_set(layer, layer->update_buf);
43048+ layer->ops->buffer_set(layer, layer->update_buf);
43049
43050 if (done && done != layer->shadow_buf)
43051 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
43052diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
43053index 641b1f0..49cff30 100644
43054--- a/drivers/media/platform/s5p-tv/mixer_video.c
43055+++ b/drivers/media/platform/s5p-tv/mixer_video.c
43056@@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
43057 layer->geo.src.height = layer->geo.src.full_height;
43058
43059 mxr_geometry_dump(mdev, &layer->geo);
43060- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
43061+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
43062 mxr_geometry_dump(mdev, &layer->geo);
43063 }
43064
43065@@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
43066 layer->geo.dst.full_width = mbus_fmt.width;
43067 layer->geo.dst.full_height = mbus_fmt.height;
43068 layer->geo.dst.field = mbus_fmt.field;
43069- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
43070+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
43071
43072 mxr_geometry_dump(mdev, &layer->geo);
43073 }
43074@@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
43075 /* set source size to highest accepted value */
43076 geo->src.full_width = max(geo->dst.full_width, pix->width);
43077 geo->src.full_height = max(geo->dst.full_height, pix->height);
43078- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
43079+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
43080 mxr_geometry_dump(mdev, &layer->geo);
43081 /* set cropping to total visible screen */
43082 geo->src.width = pix->width;
43083@@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
43084 geo->src.x_offset = 0;
43085 geo->src.y_offset = 0;
43086 /* assure consistency of geometry */
43087- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
43088+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
43089 mxr_geometry_dump(mdev, &layer->geo);
43090 /* set full size to lowest possible value */
43091 geo->src.full_width = 0;
43092 geo->src.full_height = 0;
43093- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
43094+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
43095 mxr_geometry_dump(mdev, &layer->geo);
43096
43097 /* returning results */
43098@@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
43099 target->width = s->r.width;
43100 target->height = s->r.height;
43101
43102- layer->ops.fix_geometry(layer, stage, s->flags);
43103+ layer->ops->fix_geometry(layer, stage, s->flags);
43104
43105 /* retrieve update selection rectangle */
43106 res.left = target->x_offset;
43107@@ -955,13 +955,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
43108 mxr_output_get(mdev);
43109
43110 mxr_layer_update_output(layer);
43111- layer->ops.format_set(layer);
43112+ layer->ops->format_set(layer);
43113 /* enabling layer in hardware */
43114 spin_lock_irqsave(&layer->enq_slock, flags);
43115 layer->state = MXR_LAYER_STREAMING;
43116 spin_unlock_irqrestore(&layer->enq_slock, flags);
43117
43118- layer->ops.stream_set(layer, MXR_ENABLE);
43119+ layer->ops->stream_set(layer, MXR_ENABLE);
43120 mxr_streamer_get(mdev);
43121
43122 return 0;
43123@@ -1031,7 +1031,7 @@ static int stop_streaming(struct vb2_queue *vq)
43124 spin_unlock_irqrestore(&layer->enq_slock, flags);
43125
43126 /* disabling layer in hardware */
43127- layer->ops.stream_set(layer, MXR_DISABLE);
43128+ layer->ops->stream_set(layer, MXR_DISABLE);
43129 /* remove one streamer */
43130 mxr_streamer_put(mdev);
43131 /* allow changes in output configuration */
43132@@ -1070,8 +1070,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
43133
43134 void mxr_layer_release(struct mxr_layer *layer)
43135 {
43136- if (layer->ops.release)
43137- layer->ops.release(layer);
43138+ if (layer->ops->release)
43139+ layer->ops->release(layer);
43140 }
43141
43142 void mxr_base_layer_release(struct mxr_layer *layer)
43143@@ -1097,7 +1097,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
43144
43145 layer->mdev = mdev;
43146 layer->idx = idx;
43147- layer->ops = *ops;
43148+ layer->ops = ops;
43149
43150 spin_lock_init(&layer->enq_slock);
43151 INIT_LIST_HEAD(&layer->enq_list);
43152diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
43153index 3d13a63..da31bf1 100644
43154--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
43155+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
43156@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
43157 {
43158 struct mxr_layer *layer;
43159 int ret;
43160- struct mxr_layer_ops ops = {
43161+ static struct mxr_layer_ops ops = {
43162 .release = mxr_vp_layer_release,
43163 .buffer_set = mxr_vp_buffer_set,
43164 .stream_set = mxr_vp_stream_set,
43165diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
43166index 545c04c..a14bded 100644
43167--- a/drivers/media/radio/radio-cadet.c
43168+++ b/drivers/media/radio/radio-cadet.c
43169@@ -324,6 +324,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
43170 unsigned char readbuf[RDS_BUFFER];
43171 int i = 0;
43172
43173+ if (count > RDS_BUFFER)
43174+ return -EFAULT;
43175 mutex_lock(&dev->lock);
43176 if (dev->rdsstat == 0)
43177 cadet_start_rds(dev);
43178@@ -339,7 +341,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
43179 while (i < count && dev->rdsin != dev->rdsout)
43180 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
43181
43182- if (i && copy_to_user(data, readbuf, i))
43183+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
43184 i = -EFAULT;
43185 unlock:
43186 mutex_unlock(&dev->lock);
43187diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
43188index bd4d3a7..ffc0b9d 100644
43189--- a/drivers/media/radio/radio-maxiradio.c
43190+++ b/drivers/media/radio/radio-maxiradio.c
43191@@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
43192 /* TEA5757 pin mappings */
43193 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
43194
43195-static atomic_t maxiradio_instance = ATOMIC_INIT(0);
43196+static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
43197
43198 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
43199 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
43200diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
43201index 8fa18ab..caee70f 100644
43202--- a/drivers/media/radio/radio-shark.c
43203+++ b/drivers/media/radio/radio-shark.c
43204@@ -79,7 +79,7 @@ struct shark_device {
43205 u32 last_val;
43206 };
43207
43208-static atomic_t shark_instance = ATOMIC_INIT(0);
43209+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
43210
43211 static void shark_write_val(struct snd_tea575x *tea, u32 val)
43212 {
43213diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
43214index 9fb6697..f167415 100644
43215--- a/drivers/media/radio/radio-shark2.c
43216+++ b/drivers/media/radio/radio-shark2.c
43217@@ -74,7 +74,7 @@ struct shark_device {
43218 u8 *transfer_buffer;
43219 };
43220
43221-static atomic_t shark_instance = ATOMIC_INIT(0);
43222+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
43223
43224 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
43225 {
43226diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
43227index 9c9084c..a9e8dfb 100644
43228--- a/drivers/media/radio/radio-si476x.c
43229+++ b/drivers/media/radio/radio-si476x.c
43230@@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
43231 struct si476x_radio *radio;
43232 struct v4l2_ctrl *ctrl;
43233
43234- static atomic_t instance = ATOMIC_INIT(0);
43235+ static atomic_unchecked_t instance = ATOMIC_INIT(0);
43236
43237 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
43238 if (!radio)
43239diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
43240index 1cf382a..c22998c 100644
43241--- a/drivers/media/rc/rc-main.c
43242+++ b/drivers/media/rc/rc-main.c
43243@@ -1030,7 +1030,7 @@ EXPORT_SYMBOL_GPL(rc_free_device);
43244 int rc_register_device(struct rc_dev *dev)
43245 {
43246 static bool raw_init = false; /* raw decoders loaded? */
43247- static atomic_t devno = ATOMIC_INIT(0);
43248+ static atomic_unchecked_t devno = ATOMIC_INIT(0);
43249 struct rc_map *rc_map;
43250 const char *path;
43251 int rc;
43252@@ -1061,7 +1061,7 @@ int rc_register_device(struct rc_dev *dev)
43253 */
43254 mutex_lock(&dev->lock);
43255
43256- dev->devno = (unsigned long)(atomic_inc_return(&devno) - 1);
43257+ dev->devno = (unsigned long)(atomic_inc_return_unchecked(&devno) - 1);
43258 dev_set_name(&dev->dev, "rc%ld", dev->devno);
43259 dev_set_drvdata(&dev->dev, dev);
43260 rc = device_add(&dev->dev);
43261diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
43262index 3940bb0..fb3952a 100644
43263--- a/drivers/media/usb/dvb-usb/cxusb.c
43264+++ b/drivers/media/usb/dvb-usb/cxusb.c
43265@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
43266
43267 struct dib0700_adapter_state {
43268 int (*set_param_save) (struct dvb_frontend *);
43269-};
43270+} __no_const;
43271
43272 static int dib7070_set_param_override(struct dvb_frontend *fe)
43273 {
43274diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
43275index 6e237b6..dc25556 100644
43276--- a/drivers/media/usb/dvb-usb/dw2102.c
43277+++ b/drivers/media/usb/dvb-usb/dw2102.c
43278@@ -118,7 +118,7 @@ struct su3000_state {
43279
43280 struct s6x0_state {
43281 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
43282-};
43283+} __no_const;
43284
43285 /* debug */
43286 static int dvb_usb_dw2102_debug;
43287diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
43288index 8f7a6a4..59502dd 100644
43289--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
43290+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
43291@@ -326,7 +326,7 @@ struct v4l2_buffer32 {
43292 __u32 reserved;
43293 };
43294
43295-static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
43296+static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
43297 enum v4l2_memory memory)
43298 {
43299 void __user *up_pln;
43300@@ -355,7 +355,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
43301 return 0;
43302 }
43303
43304-static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
43305+static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
43306 enum v4l2_memory memory)
43307 {
43308 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
43309@@ -772,7 +772,7 @@ static int put_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subde
43310 put_user(kp->start_block, &up->start_block) ||
43311 put_user(kp->blocks, &up->blocks) ||
43312 put_user(tmp, &up->edid) ||
43313- copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
43314+ copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
43315 return -EFAULT;
43316 return 0;
43317 }
43318diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
43319index 02d1b63..5fd6b16 100644
43320--- a/drivers/media/v4l2-core/v4l2-device.c
43321+++ b/drivers/media/v4l2-core/v4l2-device.c
43322@@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
43323 EXPORT_SYMBOL_GPL(v4l2_device_put);
43324
43325 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
43326- atomic_t *instance)
43327+ atomic_unchecked_t *instance)
43328 {
43329- int num = atomic_inc_return(instance) - 1;
43330+ int num = atomic_inc_return_unchecked(instance) - 1;
43331 int len = strlen(basename);
43332
43333 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
43334diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
43335index 68e6b5e..d8b923e 100644
43336--- a/drivers/media/v4l2-core/v4l2-ioctl.c
43337+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
43338@@ -1939,7 +1939,8 @@ struct v4l2_ioctl_info {
43339 struct file *file, void *fh, void *p);
43340 } u;
43341 void (*debug)(const void *arg, bool write_only);
43342-};
43343+} __do_const;
43344+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
43345
43346 /* This control needs a priority check */
43347 #define INFO_FL_PRIO (1 << 0)
43348@@ -2120,7 +2121,7 @@ static long __video_do_ioctl(struct file *file,
43349 struct video_device *vfd = video_devdata(file);
43350 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
43351 bool write_only = false;
43352- struct v4l2_ioctl_info default_info;
43353+ v4l2_ioctl_info_no_const default_info;
43354 const struct v4l2_ioctl_info *info;
43355 void *fh = file->private_data;
43356 struct v4l2_fh *vfh = NULL;
43357@@ -2194,7 +2195,7 @@ done:
43358 }
43359
43360 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
43361- void * __user *user_ptr, void ***kernel_ptr)
43362+ void __user **user_ptr, void ***kernel_ptr)
43363 {
43364 int ret = 0;
43365
43366@@ -2210,7 +2211,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
43367 ret = -EINVAL;
43368 break;
43369 }
43370- *user_ptr = (void __user *)buf->m.planes;
43371+ *user_ptr = (void __force_user *)buf->m.planes;
43372 *kernel_ptr = (void *)&buf->m.planes;
43373 *array_size = sizeof(struct v4l2_plane) * buf->length;
43374 ret = 1;
43375@@ -2245,7 +2246,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
43376 ret = -EINVAL;
43377 break;
43378 }
43379- *user_ptr = (void __user *)ctrls->controls;
43380+ *user_ptr = (void __force_user *)ctrls->controls;
43381 *kernel_ptr = (void *)&ctrls->controls;
43382 *array_size = sizeof(struct v4l2_ext_control)
43383 * ctrls->count;
43384diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
43385index 767ff4d..c69d259 100644
43386--- a/drivers/message/fusion/mptbase.c
43387+++ b/drivers/message/fusion/mptbase.c
43388@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
43389 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
43390 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
43391
43392+#ifdef CONFIG_GRKERNSEC_HIDESYM
43393+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
43394+#else
43395 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
43396 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
43397+#endif
43398+
43399 /*
43400 * Rounding UP to nearest 4-kB boundary here...
43401 */
43402@@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
43403 ioc->facts.GlobalCredits);
43404
43405 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
43406+#ifdef CONFIG_GRKERNSEC_HIDESYM
43407+ NULL, NULL);
43408+#else
43409 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
43410+#endif
43411 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
43412 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
43413 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
43414diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
43415index dd239bd..689c4f7 100644
43416--- a/drivers/message/fusion/mptsas.c
43417+++ b/drivers/message/fusion/mptsas.c
43418@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
43419 return 0;
43420 }
43421
43422+static inline void
43423+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
43424+{
43425+ if (phy_info->port_details) {
43426+ phy_info->port_details->rphy = rphy;
43427+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
43428+ ioc->name, rphy));
43429+ }
43430+
43431+ if (rphy) {
43432+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
43433+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
43434+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
43435+ ioc->name, rphy, rphy->dev.release));
43436+ }
43437+}
43438+
43439 /* no mutex */
43440 static void
43441 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
43442@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
43443 return NULL;
43444 }
43445
43446-static inline void
43447-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
43448-{
43449- if (phy_info->port_details) {
43450- phy_info->port_details->rphy = rphy;
43451- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
43452- ioc->name, rphy));
43453- }
43454-
43455- if (rphy) {
43456- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
43457- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
43458- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
43459- ioc->name, rphy, rphy->dev.release));
43460- }
43461-}
43462-
43463 static inline struct sas_port *
43464 mptsas_get_port(struct mptsas_phyinfo *phy_info)
43465 {
43466diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
43467index 727819c..ad74694 100644
43468--- a/drivers/message/fusion/mptscsih.c
43469+++ b/drivers/message/fusion/mptscsih.c
43470@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
43471
43472 h = shost_priv(SChost);
43473
43474- if (h) {
43475- if (h->info_kbuf == NULL)
43476- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
43477- return h->info_kbuf;
43478- h->info_kbuf[0] = '\0';
43479+ if (!h)
43480+ return NULL;
43481
43482- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
43483- h->info_kbuf[size-1] = '\0';
43484- }
43485+ if (h->info_kbuf == NULL)
43486+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
43487+ return h->info_kbuf;
43488+ h->info_kbuf[0] = '\0';
43489+
43490+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
43491+ h->info_kbuf[size-1] = '\0';
43492
43493 return h->info_kbuf;
43494 }
43495diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
43496index b7d87cd..9890039 100644
43497--- a/drivers/message/i2o/i2o_proc.c
43498+++ b/drivers/message/i2o/i2o_proc.c
43499@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
43500 "Array Controller Device"
43501 };
43502
43503-static char *chtostr(char *tmp, u8 *chars, int n)
43504-{
43505- tmp[0] = 0;
43506- return strncat(tmp, (char *)chars, n);
43507-}
43508-
43509 static int i2o_report_query_status(struct seq_file *seq, int block_status,
43510 char *group)
43511 {
43512@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
43513 } *result;
43514
43515 i2o_exec_execute_ddm_table ddm_table;
43516- char tmp[28 + 1];
43517
43518 result = kmalloc(sizeof(*result), GFP_KERNEL);
43519 if (!result)
43520@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
43521
43522 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
43523 seq_printf(seq, "%-#8x", ddm_table.module_id);
43524- seq_printf(seq, "%-29s",
43525- chtostr(tmp, ddm_table.module_name_version, 28));
43526+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
43527 seq_printf(seq, "%9d ", ddm_table.data_size);
43528 seq_printf(seq, "%8d", ddm_table.code_size);
43529
43530@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
43531
43532 i2o_driver_result_table *result;
43533 i2o_driver_store_table *dst;
43534- char tmp[28 + 1];
43535
43536 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
43537 if (result == NULL)
43538@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
43539
43540 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
43541 seq_printf(seq, "%-#8x", dst->module_id);
43542- seq_printf(seq, "%-29s",
43543- chtostr(tmp, dst->module_name_version, 28));
43544- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
43545+ seq_printf(seq, "%-.28s", dst->module_name_version);
43546+ seq_printf(seq, "%-.8s", dst->date);
43547 seq_printf(seq, "%8d ", dst->module_size);
43548 seq_printf(seq, "%8d ", dst->mpb_size);
43549 seq_printf(seq, "0x%04x", dst->module_flags);
43550@@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
43551 // == (allow) 512d bytes (max)
43552 static u16 *work16 = (u16 *) work32;
43553 int token;
43554- char tmp[16 + 1];
43555
43556 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
43557
43558@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
43559 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
43560 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
43561 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
43562- seq_printf(seq, "Vendor info : %s\n",
43563- chtostr(tmp, (u8 *) (work32 + 2), 16));
43564- seq_printf(seq, "Product info : %s\n",
43565- chtostr(tmp, (u8 *) (work32 + 6), 16));
43566- seq_printf(seq, "Description : %s\n",
43567- chtostr(tmp, (u8 *) (work32 + 10), 16));
43568- seq_printf(seq, "Product rev. : %s\n",
43569- chtostr(tmp, (u8 *) (work32 + 14), 8));
43570+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
43571+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
43572+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
43573+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
43574
43575 seq_printf(seq, "Serial number : ");
43576 print_serial_number(seq, (u8 *) (work32 + 16),
43577@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
43578 u8 pad[256]; // allow up to 256 byte (max) serial number
43579 } result;
43580
43581- char tmp[24 + 1];
43582-
43583 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
43584
43585 if (token < 0) {
43586@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
43587 }
43588
43589 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
43590- seq_printf(seq, "Module name : %s\n",
43591- chtostr(tmp, result.module_name, 24));
43592- seq_printf(seq, "Module revision : %s\n",
43593- chtostr(tmp, result.module_rev, 8));
43594+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
43595+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
43596
43597 seq_printf(seq, "Serial number : ");
43598 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
43599@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
43600 u8 instance_number[4];
43601 } result;
43602
43603- char tmp[64 + 1];
43604-
43605 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
43606
43607 if (token < 0) {
43608@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
43609 return 0;
43610 }
43611
43612- seq_printf(seq, "Device name : %s\n",
43613- chtostr(tmp, result.device_name, 64));
43614- seq_printf(seq, "Service name : %s\n",
43615- chtostr(tmp, result.service_name, 64));
43616- seq_printf(seq, "Physical name : %s\n",
43617- chtostr(tmp, result.physical_location, 64));
43618- seq_printf(seq, "Instance number : %s\n",
43619- chtostr(tmp, result.instance_number, 4));
43620+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
43621+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
43622+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
43623+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
43624
43625 return 0;
43626 }
43627diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
43628index a8c08f3..155fe3d 100644
43629--- a/drivers/message/i2o/iop.c
43630+++ b/drivers/message/i2o/iop.c
43631@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
43632
43633 spin_lock_irqsave(&c->context_list_lock, flags);
43634
43635- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
43636- atomic_inc(&c->context_list_counter);
43637+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
43638+ atomic_inc_unchecked(&c->context_list_counter);
43639
43640- entry->context = atomic_read(&c->context_list_counter);
43641+ entry->context = atomic_read_unchecked(&c->context_list_counter);
43642
43643 list_add(&entry->list, &c->context_list);
43644
43645@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
43646
43647 #if BITS_PER_LONG == 64
43648 spin_lock_init(&c->context_list_lock);
43649- atomic_set(&c->context_list_counter, 0);
43650+ atomic_set_unchecked(&c->context_list_counter, 0);
43651 INIT_LIST_HEAD(&c->context_list);
43652 #endif
43653
43654diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
43655index fcbb2e9..2635e11 100644
43656--- a/drivers/mfd/janz-cmodio.c
43657+++ b/drivers/mfd/janz-cmodio.c
43658@@ -13,6 +13,7 @@
43659
43660 #include <linux/kernel.h>
43661 #include <linux/module.h>
43662+#include <linux/slab.h>
43663 #include <linux/init.h>
43664 #include <linux/pci.h>
43665 #include <linux/interrupt.h>
43666diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
43667index 9aa6d1e..1631bfc 100644
43668--- a/drivers/mfd/twl4030-irq.c
43669+++ b/drivers/mfd/twl4030-irq.c
43670@@ -35,6 +35,7 @@
43671 #include <linux/of.h>
43672 #include <linux/irqdomain.h>
43673 #include <linux/i2c/twl.h>
43674+#include <asm/pgtable.h>
43675
43676 #include "twl-core.h"
43677
43678@@ -726,10 +727,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
43679 * Install an irq handler for each of the SIH modules;
43680 * clone dummy irq_chip since PIH can't *do* anything
43681 */
43682- twl4030_irq_chip = dummy_irq_chip;
43683- twl4030_irq_chip.name = "twl4030";
43684+ pax_open_kernel();
43685+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
43686+ *(const char **)&twl4030_irq_chip.name = "twl4030";
43687
43688- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
43689+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
43690+ pax_close_kernel();
43691
43692 for (i = irq_base; i < irq_end; i++) {
43693 irq_set_chip_and_handler(i, &twl4030_irq_chip,
43694diff --git a/drivers/mfd/twl6030-irq.c b/drivers/mfd/twl6030-irq.c
43695index 277a8db..0e0b754 100644
43696--- a/drivers/mfd/twl6030-irq.c
43697+++ b/drivers/mfd/twl6030-irq.c
43698@@ -387,10 +387,12 @@ int twl6030_init_irq(struct device *dev, int irq_num)
43699 * install an irq handler for each of the modules;
43700 * clone dummy irq_chip since PIH can't *do* anything
43701 */
43702- twl6030_irq_chip = dummy_irq_chip;
43703- twl6030_irq_chip.name = "twl6030";
43704- twl6030_irq_chip.irq_set_type = NULL;
43705- twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
43706+ pax_open_kernel();
43707+ memcpy((void *)&twl6030_irq_chip, &dummy_irq_chip, sizeof twl6030_irq_chip);
43708+ *(const char **)&twl6030_irq_chip.name = "twl6030";
43709+ *(void **)&twl6030_irq_chip.irq_set_type = NULL;
43710+ *(void **)&twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
43711+ pax_close_kernel();
43712
43713 for (i = irq_base; i < irq_end; i++) {
43714 irq_set_chip_and_handler(i, &twl6030_irq_chip,
43715diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
43716index f32550a..e3e52a2 100644
43717--- a/drivers/misc/c2port/core.c
43718+++ b/drivers/misc/c2port/core.c
43719@@ -920,7 +920,9 @@ struct c2port_device *c2port_device_register(char *name,
43720 mutex_init(&c2dev->mutex);
43721
43722 /* Create binary file */
43723- c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
43724+ pax_open_kernel();
43725+ *(size_t *)&c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
43726+ pax_close_kernel();
43727 ret = device_create_bin_file(c2dev->dev, &c2port_bin_attrs);
43728 if (unlikely(ret))
43729 goto error_device_create_bin_file;
43730diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
43731index 36f5d52..32311c3 100644
43732--- a/drivers/misc/kgdbts.c
43733+++ b/drivers/misc/kgdbts.c
43734@@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
43735 char before[BREAK_INSTR_SIZE];
43736 char after[BREAK_INSTR_SIZE];
43737
43738- probe_kernel_read(before, (char *)kgdbts_break_test,
43739+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
43740 BREAK_INSTR_SIZE);
43741 init_simple_test();
43742 ts.tst = plant_and_detach_test;
43743@@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
43744 /* Activate test with initial breakpoint */
43745 if (!is_early)
43746 kgdb_breakpoint();
43747- probe_kernel_read(after, (char *)kgdbts_break_test,
43748+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
43749 BREAK_INSTR_SIZE);
43750 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
43751 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
43752diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
43753index 036effe..b3a6336 100644
43754--- a/drivers/misc/lis3lv02d/lis3lv02d.c
43755+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
43756@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
43757 * the lid is closed. This leads to interrupts as soon as a little move
43758 * is done.
43759 */
43760- atomic_inc(&lis3->count);
43761+ atomic_inc_unchecked(&lis3->count);
43762
43763 wake_up_interruptible(&lis3->misc_wait);
43764 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
43765@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
43766 if (lis3->pm_dev)
43767 pm_runtime_get_sync(lis3->pm_dev);
43768
43769- atomic_set(&lis3->count, 0);
43770+ atomic_set_unchecked(&lis3->count, 0);
43771 return 0;
43772 }
43773
43774@@ -616,7 +616,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
43775 add_wait_queue(&lis3->misc_wait, &wait);
43776 while (true) {
43777 set_current_state(TASK_INTERRUPTIBLE);
43778- data = atomic_xchg(&lis3->count, 0);
43779+ data = atomic_xchg_unchecked(&lis3->count, 0);
43780 if (data)
43781 break;
43782
43783@@ -657,7 +657,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
43784 struct lis3lv02d, miscdev);
43785
43786 poll_wait(file, &lis3->misc_wait, wait);
43787- if (atomic_read(&lis3->count))
43788+ if (atomic_read_unchecked(&lis3->count))
43789 return POLLIN | POLLRDNORM;
43790 return 0;
43791 }
43792diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
43793index c439c82..1f20f57 100644
43794--- a/drivers/misc/lis3lv02d/lis3lv02d.h
43795+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
43796@@ -297,7 +297,7 @@ struct lis3lv02d {
43797 struct input_polled_dev *idev; /* input device */
43798 struct platform_device *pdev; /* platform device */
43799 struct regulator_bulk_data regulators[2];
43800- atomic_t count; /* interrupt count after last read */
43801+ atomic_unchecked_t count; /* interrupt count after last read */
43802 union axis_conversion ac; /* hw -> logical axis */
43803 int mapped_btns[3];
43804
43805diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
43806index 2f30bad..c4c13d0 100644
43807--- a/drivers/misc/sgi-gru/gruhandles.c
43808+++ b/drivers/misc/sgi-gru/gruhandles.c
43809@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
43810 unsigned long nsec;
43811
43812 nsec = CLKS2NSEC(clks);
43813- atomic_long_inc(&mcs_op_statistics[op].count);
43814- atomic_long_add(nsec, &mcs_op_statistics[op].total);
43815+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
43816+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
43817 if (mcs_op_statistics[op].max < nsec)
43818 mcs_op_statistics[op].max = nsec;
43819 }
43820diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
43821index 4f76359..cdfcb2e 100644
43822--- a/drivers/misc/sgi-gru/gruprocfs.c
43823+++ b/drivers/misc/sgi-gru/gruprocfs.c
43824@@ -32,9 +32,9 @@
43825
43826 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
43827
43828-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
43829+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
43830 {
43831- unsigned long val = atomic_long_read(v);
43832+ unsigned long val = atomic_long_read_unchecked(v);
43833
43834 seq_printf(s, "%16lu %s\n", val, id);
43835 }
43836@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
43837
43838 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
43839 for (op = 0; op < mcsop_last; op++) {
43840- count = atomic_long_read(&mcs_op_statistics[op].count);
43841- total = atomic_long_read(&mcs_op_statistics[op].total);
43842+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
43843+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
43844 max = mcs_op_statistics[op].max;
43845 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
43846 count ? total / count : 0, max);
43847diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
43848index 5c3ce24..4915ccb 100644
43849--- a/drivers/misc/sgi-gru/grutables.h
43850+++ b/drivers/misc/sgi-gru/grutables.h
43851@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
43852 * GRU statistics.
43853 */
43854 struct gru_stats_s {
43855- atomic_long_t vdata_alloc;
43856- atomic_long_t vdata_free;
43857- atomic_long_t gts_alloc;
43858- atomic_long_t gts_free;
43859- atomic_long_t gms_alloc;
43860- atomic_long_t gms_free;
43861- atomic_long_t gts_double_allocate;
43862- atomic_long_t assign_context;
43863- atomic_long_t assign_context_failed;
43864- atomic_long_t free_context;
43865- atomic_long_t load_user_context;
43866- atomic_long_t load_kernel_context;
43867- atomic_long_t lock_kernel_context;
43868- atomic_long_t unlock_kernel_context;
43869- atomic_long_t steal_user_context;
43870- atomic_long_t steal_kernel_context;
43871- atomic_long_t steal_context_failed;
43872- atomic_long_t nopfn;
43873- atomic_long_t asid_new;
43874- atomic_long_t asid_next;
43875- atomic_long_t asid_wrap;
43876- atomic_long_t asid_reuse;
43877- atomic_long_t intr;
43878- atomic_long_t intr_cbr;
43879- atomic_long_t intr_tfh;
43880- atomic_long_t intr_spurious;
43881- atomic_long_t intr_mm_lock_failed;
43882- atomic_long_t call_os;
43883- atomic_long_t call_os_wait_queue;
43884- atomic_long_t user_flush_tlb;
43885- atomic_long_t user_unload_context;
43886- atomic_long_t user_exception;
43887- atomic_long_t set_context_option;
43888- atomic_long_t check_context_retarget_intr;
43889- atomic_long_t check_context_unload;
43890- atomic_long_t tlb_dropin;
43891- atomic_long_t tlb_preload_page;
43892- atomic_long_t tlb_dropin_fail_no_asid;
43893- atomic_long_t tlb_dropin_fail_upm;
43894- atomic_long_t tlb_dropin_fail_invalid;
43895- atomic_long_t tlb_dropin_fail_range_active;
43896- atomic_long_t tlb_dropin_fail_idle;
43897- atomic_long_t tlb_dropin_fail_fmm;
43898- atomic_long_t tlb_dropin_fail_no_exception;
43899- atomic_long_t tfh_stale_on_fault;
43900- atomic_long_t mmu_invalidate_range;
43901- atomic_long_t mmu_invalidate_page;
43902- atomic_long_t flush_tlb;
43903- atomic_long_t flush_tlb_gru;
43904- atomic_long_t flush_tlb_gru_tgh;
43905- atomic_long_t flush_tlb_gru_zero_asid;
43906+ atomic_long_unchecked_t vdata_alloc;
43907+ atomic_long_unchecked_t vdata_free;
43908+ atomic_long_unchecked_t gts_alloc;
43909+ atomic_long_unchecked_t gts_free;
43910+ atomic_long_unchecked_t gms_alloc;
43911+ atomic_long_unchecked_t gms_free;
43912+ atomic_long_unchecked_t gts_double_allocate;
43913+ atomic_long_unchecked_t assign_context;
43914+ atomic_long_unchecked_t assign_context_failed;
43915+ atomic_long_unchecked_t free_context;
43916+ atomic_long_unchecked_t load_user_context;
43917+ atomic_long_unchecked_t load_kernel_context;
43918+ atomic_long_unchecked_t lock_kernel_context;
43919+ atomic_long_unchecked_t unlock_kernel_context;
43920+ atomic_long_unchecked_t steal_user_context;
43921+ atomic_long_unchecked_t steal_kernel_context;
43922+ atomic_long_unchecked_t steal_context_failed;
43923+ atomic_long_unchecked_t nopfn;
43924+ atomic_long_unchecked_t asid_new;
43925+ atomic_long_unchecked_t asid_next;
43926+ atomic_long_unchecked_t asid_wrap;
43927+ atomic_long_unchecked_t asid_reuse;
43928+ atomic_long_unchecked_t intr;
43929+ atomic_long_unchecked_t intr_cbr;
43930+ atomic_long_unchecked_t intr_tfh;
43931+ atomic_long_unchecked_t intr_spurious;
43932+ atomic_long_unchecked_t intr_mm_lock_failed;
43933+ atomic_long_unchecked_t call_os;
43934+ atomic_long_unchecked_t call_os_wait_queue;
43935+ atomic_long_unchecked_t user_flush_tlb;
43936+ atomic_long_unchecked_t user_unload_context;
43937+ atomic_long_unchecked_t user_exception;
43938+ atomic_long_unchecked_t set_context_option;
43939+ atomic_long_unchecked_t check_context_retarget_intr;
43940+ atomic_long_unchecked_t check_context_unload;
43941+ atomic_long_unchecked_t tlb_dropin;
43942+ atomic_long_unchecked_t tlb_preload_page;
43943+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
43944+ atomic_long_unchecked_t tlb_dropin_fail_upm;
43945+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
43946+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
43947+ atomic_long_unchecked_t tlb_dropin_fail_idle;
43948+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
43949+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
43950+ atomic_long_unchecked_t tfh_stale_on_fault;
43951+ atomic_long_unchecked_t mmu_invalidate_range;
43952+ atomic_long_unchecked_t mmu_invalidate_page;
43953+ atomic_long_unchecked_t flush_tlb;
43954+ atomic_long_unchecked_t flush_tlb_gru;
43955+ atomic_long_unchecked_t flush_tlb_gru_tgh;
43956+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
43957
43958- atomic_long_t copy_gpa;
43959- atomic_long_t read_gpa;
43960+ atomic_long_unchecked_t copy_gpa;
43961+ atomic_long_unchecked_t read_gpa;
43962
43963- atomic_long_t mesq_receive;
43964- atomic_long_t mesq_receive_none;
43965- atomic_long_t mesq_send;
43966- atomic_long_t mesq_send_failed;
43967- atomic_long_t mesq_noop;
43968- atomic_long_t mesq_send_unexpected_error;
43969- atomic_long_t mesq_send_lb_overflow;
43970- atomic_long_t mesq_send_qlimit_reached;
43971- atomic_long_t mesq_send_amo_nacked;
43972- atomic_long_t mesq_send_put_nacked;
43973- atomic_long_t mesq_page_overflow;
43974- atomic_long_t mesq_qf_locked;
43975- atomic_long_t mesq_qf_noop_not_full;
43976- atomic_long_t mesq_qf_switch_head_failed;
43977- atomic_long_t mesq_qf_unexpected_error;
43978- atomic_long_t mesq_noop_unexpected_error;
43979- atomic_long_t mesq_noop_lb_overflow;
43980- atomic_long_t mesq_noop_qlimit_reached;
43981- atomic_long_t mesq_noop_amo_nacked;
43982- atomic_long_t mesq_noop_put_nacked;
43983- atomic_long_t mesq_noop_page_overflow;
43984+ atomic_long_unchecked_t mesq_receive;
43985+ atomic_long_unchecked_t mesq_receive_none;
43986+ atomic_long_unchecked_t mesq_send;
43987+ atomic_long_unchecked_t mesq_send_failed;
43988+ atomic_long_unchecked_t mesq_noop;
43989+ atomic_long_unchecked_t mesq_send_unexpected_error;
43990+ atomic_long_unchecked_t mesq_send_lb_overflow;
43991+ atomic_long_unchecked_t mesq_send_qlimit_reached;
43992+ atomic_long_unchecked_t mesq_send_amo_nacked;
43993+ atomic_long_unchecked_t mesq_send_put_nacked;
43994+ atomic_long_unchecked_t mesq_page_overflow;
43995+ atomic_long_unchecked_t mesq_qf_locked;
43996+ atomic_long_unchecked_t mesq_qf_noop_not_full;
43997+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
43998+ atomic_long_unchecked_t mesq_qf_unexpected_error;
43999+ atomic_long_unchecked_t mesq_noop_unexpected_error;
44000+ atomic_long_unchecked_t mesq_noop_lb_overflow;
44001+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
44002+ atomic_long_unchecked_t mesq_noop_amo_nacked;
44003+ atomic_long_unchecked_t mesq_noop_put_nacked;
44004+ atomic_long_unchecked_t mesq_noop_page_overflow;
44005
44006 };
44007
44008@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
44009 tghop_invalidate, mcsop_last};
44010
44011 struct mcs_op_statistic {
44012- atomic_long_t count;
44013- atomic_long_t total;
44014+ atomic_long_unchecked_t count;
44015+ atomic_long_unchecked_t total;
44016 unsigned long max;
44017 };
44018
44019@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
44020
44021 #define STAT(id) do { \
44022 if (gru_options & OPT_STATS) \
44023- atomic_long_inc(&gru_stats.id); \
44024+ atomic_long_inc_unchecked(&gru_stats.id); \
44025 } while (0)
44026
44027 #ifdef CONFIG_SGI_GRU_DEBUG
44028diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
44029index c862cd4..0d176fe 100644
44030--- a/drivers/misc/sgi-xp/xp.h
44031+++ b/drivers/misc/sgi-xp/xp.h
44032@@ -288,7 +288,7 @@ struct xpc_interface {
44033 xpc_notify_func, void *);
44034 void (*received) (short, int, void *);
44035 enum xp_retval (*partid_to_nasids) (short, void *);
44036-};
44037+} __no_const;
44038
44039 extern struct xpc_interface xpc_interface;
44040
44041diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
44042index b94d5f7..7f494c5 100644
44043--- a/drivers/misc/sgi-xp/xpc.h
44044+++ b/drivers/misc/sgi-xp/xpc.h
44045@@ -835,6 +835,7 @@ struct xpc_arch_operations {
44046 void (*received_payload) (struct xpc_channel *, void *);
44047 void (*notify_senders_of_disconnect) (struct xpc_channel *);
44048 };
44049+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
44050
44051 /* struct xpc_partition act_state values (for XPC HB) */
44052
44053@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
44054 /* found in xpc_main.c */
44055 extern struct device *xpc_part;
44056 extern struct device *xpc_chan;
44057-extern struct xpc_arch_operations xpc_arch_ops;
44058+extern xpc_arch_operations_no_const xpc_arch_ops;
44059 extern int xpc_disengage_timelimit;
44060 extern int xpc_disengage_timedout;
44061 extern int xpc_activate_IRQ_rcvd;
44062diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
44063index 82dc574..8539ab2 100644
44064--- a/drivers/misc/sgi-xp/xpc_main.c
44065+++ b/drivers/misc/sgi-xp/xpc_main.c
44066@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
44067 .notifier_call = xpc_system_die,
44068 };
44069
44070-struct xpc_arch_operations xpc_arch_ops;
44071+xpc_arch_operations_no_const xpc_arch_ops;
44072
44073 /*
44074 * Timer function to enforce the timelimit on the partition disengage.
44075@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
44076
44077 if (((die_args->trapnr == X86_TRAP_MF) ||
44078 (die_args->trapnr == X86_TRAP_XF)) &&
44079- !user_mode_vm(die_args->regs))
44080+ !user_mode(die_args->regs))
44081 xpc_die_deactivate();
44082
44083 break;
44084diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
44085index 837fc73..acb5862 100644
44086--- a/drivers/mmc/core/mmc_ops.c
44087+++ b/drivers/mmc/core/mmc_ops.c
44088@@ -213,7 +213,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
44089 void *data_buf;
44090 int is_on_stack;
44091
44092- is_on_stack = object_is_on_stack(buf);
44093+ is_on_stack = object_starts_on_stack(buf);
44094 if (is_on_stack) {
44095 /*
44096 * dma onto stack is unsafe/nonportable, but callers to this
44097diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
44098index 81b2994..dce857e 100644
44099--- a/drivers/mmc/host/dw_mmc.h
44100+++ b/drivers/mmc/host/dw_mmc.h
44101@@ -203,5 +203,5 @@ struct dw_mci_drv_data {
44102 void (*prepare_command)(struct dw_mci *host, u32 *cmdr);
44103 void (*set_ios)(struct dw_mci *host, struct mmc_ios *ios);
44104 int (*parse_dt)(struct dw_mci *host);
44105-};
44106+} __do_const;
44107 #endif /* _DW_MMC_H_ */
44108diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
44109index c3785ed..1984c44 100644
44110--- a/drivers/mmc/host/mmci.c
44111+++ b/drivers/mmc/host/mmci.c
44112@@ -1482,7 +1482,9 @@ static int mmci_probe(struct amba_device *dev,
44113 }
44114
44115 if (variant->busy_detect) {
44116- mmci_ops.card_busy = mmci_card_busy;
44117+ pax_open_kernel();
44118+ *(void **)&mmci_ops.card_busy = mmci_card_busy;
44119+ pax_close_kernel();
44120 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
44121 }
44122
44123diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
44124index 926aaf6..8e153e2 100644
44125--- a/drivers/mmc/host/sdhci-s3c.c
44126+++ b/drivers/mmc/host/sdhci-s3c.c
44127@@ -664,9 +664,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
44128 * we can use overriding functions instead of default.
44129 */
44130 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
44131- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
44132- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
44133- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
44134+ pax_open_kernel();
44135+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
44136+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
44137+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
44138+ pax_close_kernel();
44139 }
44140
44141 /* It supports additional host capabilities if needed */
44142diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
44143index 0c8bb6b..6f35deb 100644
44144--- a/drivers/mtd/nand/denali.c
44145+++ b/drivers/mtd/nand/denali.c
44146@@ -24,6 +24,7 @@
44147 #include <linux/slab.h>
44148 #include <linux/mtd/mtd.h>
44149 #include <linux/module.h>
44150+#include <linux/slab.h>
44151
44152 #include "denali.h"
44153
44154diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
44155index 51b9d6a..52af9a7 100644
44156--- a/drivers/mtd/nftlmount.c
44157+++ b/drivers/mtd/nftlmount.c
44158@@ -24,6 +24,7 @@
44159 #include <asm/errno.h>
44160 #include <linux/delay.h>
44161 #include <linux/slab.h>
44162+#include <linux/sched.h>
44163 #include <linux/mtd/mtd.h>
44164 #include <linux/mtd/nand.h>
44165 #include <linux/mtd/nftl.h>
44166diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
44167index f9d5615..99dd95f 100644
44168--- a/drivers/mtd/sm_ftl.c
44169+++ b/drivers/mtd/sm_ftl.c
44170@@ -56,7 +56,7 @@ ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
44171 #define SM_CIS_VENDOR_OFFSET 0x59
44172 struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
44173 {
44174- struct attribute_group *attr_group;
44175+ attribute_group_no_const *attr_group;
44176 struct attribute **attributes;
44177 struct sm_sysfs_attribute *vendor_attribute;
44178
44179diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
44180index e48cb33..72e73fc 100644
44181--- a/drivers/net/bonding/bond_main.c
44182+++ b/drivers/net/bonding/bond_main.c
44183@@ -4832,7 +4832,7 @@ static unsigned int bond_get_num_tx_queues(void)
44184 return tx_queues;
44185 }
44186
44187-static struct rtnl_link_ops bond_link_ops __read_mostly = {
44188+static struct rtnl_link_ops bond_link_ops = {
44189 .kind = "bond",
44190 .priv_size = sizeof(struct bonding),
44191 .setup = bond_setup,
44192@@ -4957,8 +4957,8 @@ static void __exit bonding_exit(void)
44193
44194 bond_destroy_debugfs();
44195
44196- rtnl_link_unregister(&bond_link_ops);
44197 unregister_pernet_subsys(&bond_net_ops);
44198+ rtnl_link_unregister(&bond_link_ops);
44199
44200 #ifdef CONFIG_NET_POLL_CONTROLLER
44201 /*
44202diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
44203index e1d2643..7f4133b 100644
44204--- a/drivers/net/ethernet/8390/ax88796.c
44205+++ b/drivers/net/ethernet/8390/ax88796.c
44206@@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
44207 if (ax->plat->reg_offsets)
44208 ei_local->reg_offset = ax->plat->reg_offsets;
44209 else {
44210+ resource_size_t _mem_size = mem_size;
44211+ do_div(_mem_size, 0x18);
44212 ei_local->reg_offset = ax->reg_offsets;
44213 for (ret = 0; ret < 0x18; ret++)
44214- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
44215+ ax->reg_offsets[ret] = _mem_size * ret;
44216 }
44217
44218 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
44219diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
44220index c07a6d0..ca88c45 100644
44221--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
44222+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
44223@@ -1137,7 +1137,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
44224 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
44225 {
44226 /* RX_MODE controlling object */
44227- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
44228+ bnx2x_init_rx_mode_obj(bp);
44229
44230 /* multicast configuration controlling object */
44231 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
44232diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
44233index 8f03c98..dd0ef10 100644
44234--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
44235+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
44236@@ -2345,15 +2345,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
44237 return rc;
44238 }
44239
44240-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
44241- struct bnx2x_rx_mode_obj *o)
44242+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
44243 {
44244 if (CHIP_IS_E1x(bp)) {
44245- o->wait_comp = bnx2x_empty_rx_mode_wait;
44246- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
44247+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
44248+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
44249 } else {
44250- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
44251- o->config_rx_mode = bnx2x_set_rx_mode_e2;
44252+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
44253+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
44254 }
44255 }
44256
44257diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
44258index 798dfe9..05d0a44 100644
44259--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
44260+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
44261@@ -1311,8 +1311,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
44262
44263 /********************* RX MODE ****************/
44264
44265-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
44266- struct bnx2x_rx_mode_obj *o);
44267+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
44268
44269 /**
44270 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
44271diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
44272index cd63d11..b67dd78 100644
44273--- a/drivers/net/ethernet/broadcom/tg3.h
44274+++ b/drivers/net/ethernet/broadcom/tg3.h
44275@@ -147,6 +147,7 @@
44276 #define CHIPREV_ID_5750_A0 0x4000
44277 #define CHIPREV_ID_5750_A1 0x4001
44278 #define CHIPREV_ID_5750_A3 0x4003
44279+#define CHIPREV_ID_5750_C1 0x4201
44280 #define CHIPREV_ID_5750_C2 0x4202
44281 #define CHIPREV_ID_5752_A0_HW 0x5000
44282 #define CHIPREV_ID_5752_A0 0x6000
44283diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
44284index 8cffcdf..aadf043 100644
44285--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
44286+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
44287@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
44288 */
44289 struct l2t_skb_cb {
44290 arp_failure_handler_func arp_failure_handler;
44291-};
44292+} __no_const;
44293
44294 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
44295
44296diff --git a/drivers/net/ethernet/chelsio/cxgb3/sge.c b/drivers/net/ethernet/chelsio/cxgb3/sge.c
44297index 9c89dc8..725ecc3 100644
44298--- a/drivers/net/ethernet/chelsio/cxgb3/sge.c
44299+++ b/drivers/net/ethernet/chelsio/cxgb3/sge.c
44300@@ -1599,7 +1599,7 @@ static void write_ofld_wr(struct adapter *adap, struct sk_buff *skb,
44301 flits = skb_transport_offset(skb) / 8;
44302 sgp = ndesc == 1 ? (struct sg_ent *)&d->flit[flits] : sgl;
44303 sgl_flits = make_sgl(skb, sgp, skb_transport_header(skb),
44304- skb->tail - skb->transport_header,
44305+ skb_tail_pointer(skb) - skb_transport_header(skb),
44306 adap->pdev);
44307 if (need_skb_unmap()) {
44308 setup_deferred_unmapping(skb, adap->pdev, sgp, sgl_flits);
44309diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
44310index 4c83003..2a2a5b9 100644
44311--- a/drivers/net/ethernet/dec/tulip/de4x5.c
44312+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
44313@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
44314 for (i=0; i<ETH_ALEN; i++) {
44315 tmp.addr[i] = dev->dev_addr[i];
44316 }
44317- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
44318+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
44319 break;
44320
44321 case DE4X5_SET_HWADDR: /* Set the hardware address */
44322@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
44323 spin_lock_irqsave(&lp->lock, flags);
44324 memcpy(&statbuf, &lp->pktStats, ioc->len);
44325 spin_unlock_irqrestore(&lp->lock, flags);
44326- if (copy_to_user(ioc->data, &statbuf, ioc->len))
44327+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
44328 return -EFAULT;
44329 break;
44330 }
44331diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
44332index 3d91a5e..1014702 100644
44333--- a/drivers/net/ethernet/emulex/benet/be_main.c
44334+++ b/drivers/net/ethernet/emulex/benet/be_main.c
44335@@ -469,7 +469,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
44336
44337 if (wrapped)
44338 newacc += 65536;
44339- ACCESS_ONCE(*acc) = newacc;
44340+ ACCESS_ONCE_RW(*acc) = newacc;
44341 }
44342
44343 void populate_erx_stats(struct be_adapter *adapter,
44344diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
44345index 934e1ae..b262e6b 100644
44346--- a/drivers/net/ethernet/faraday/ftgmac100.c
44347+++ b/drivers/net/ethernet/faraday/ftgmac100.c
44348@@ -31,6 +31,8 @@
44349 #include <linux/netdevice.h>
44350 #include <linux/phy.h>
44351 #include <linux/platform_device.h>
44352+#include <linux/interrupt.h>
44353+#include <linux/irqreturn.h>
44354 #include <net/ip.h>
44355
44356 #include "ftgmac100.h"
44357diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
44358index 4658f4c..407d155 100644
44359--- a/drivers/net/ethernet/faraday/ftmac100.c
44360+++ b/drivers/net/ethernet/faraday/ftmac100.c
44361@@ -31,6 +31,8 @@
44362 #include <linux/module.h>
44363 #include <linux/netdevice.h>
44364 #include <linux/platform_device.h>
44365+#include <linux/interrupt.h>
44366+#include <linux/irqreturn.h>
44367
44368 #include "ftmac100.h"
44369
44370diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
44371index 331987d..3be1135 100644
44372--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
44373+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
44374@@ -776,7 +776,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
44375 }
44376
44377 /* update the base incval used to calculate frequency adjustment */
44378- ACCESS_ONCE(adapter->base_incval) = incval;
44379+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
44380 smp_mb();
44381
44382 /* need lock to prevent incorrect read while modifying cyclecounter */
44383diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
44384index fbe5363..266b4e3 100644
44385--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
44386+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
44387@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
44388 struct __vxge_hw_fifo *fifo;
44389 struct vxge_hw_fifo_config *config;
44390 u32 txdl_size, txdl_per_memblock;
44391- struct vxge_hw_mempool_cbs fifo_mp_callback;
44392+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
44393+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
44394+ };
44395+
44396 struct __vxge_hw_virtualpath *vpath;
44397
44398 if ((vp == NULL) || (attr == NULL)) {
44399@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
44400 goto exit;
44401 }
44402
44403- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
44404-
44405 fifo->mempool =
44406 __vxge_hw_mempool_create(vpath->hldev,
44407 fifo->config->memblock_size,
44408diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
44409index 345d987..af69721 100644
44410--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
44411+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
44412@@ -2011,7 +2011,9 @@ int qlcnic_83xx_config_default_opmode(struct qlcnic_adapter *adapter)
44413 op_mode = QLC_83XX_DEFAULT_OPMODE;
44414
44415 if (op_mode == QLC_83XX_DEFAULT_OPMODE) {
44416- adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
44417+ pax_open_kernel();
44418+ *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
44419+ pax_close_kernel();
44420 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
44421 } else {
44422 return -EIO;
44423diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
44424index 599d1fd..59868fe 100644
44425--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
44426+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
44427@@ -191,17 +191,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
44428 case QLCNIC_NON_PRIV_FUNC:
44429 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
44430 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
44431- nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
44432+ pax_open_kernel();
44433+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
44434+ pax_close_kernel();
44435 break;
44436 case QLCNIC_PRIV_FUNC:
44437 ahw->op_mode = QLCNIC_PRIV_FUNC;
44438 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
44439- nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
44440+ pax_open_kernel();
44441+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
44442+ pax_close_kernel();
44443 break;
44444 case QLCNIC_MGMT_FUNC:
44445 ahw->op_mode = QLCNIC_MGMT_FUNC;
44446 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
44447- nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
44448+ pax_open_kernel();
44449+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
44450+ pax_close_kernel();
44451 break;
44452 default:
44453 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
44454diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
44455index 85e5c97..76f97ec 100644
44456--- a/drivers/net/ethernet/realtek/r8169.c
44457+++ b/drivers/net/ethernet/realtek/r8169.c
44458@@ -759,22 +759,22 @@ struct rtl8169_private {
44459 struct mdio_ops {
44460 void (*write)(struct rtl8169_private *, int, int);
44461 int (*read)(struct rtl8169_private *, int);
44462- } mdio_ops;
44463+ } __no_const mdio_ops;
44464
44465 struct pll_power_ops {
44466 void (*down)(struct rtl8169_private *);
44467 void (*up)(struct rtl8169_private *);
44468- } pll_power_ops;
44469+ } __no_const pll_power_ops;
44470
44471 struct jumbo_ops {
44472 void (*enable)(struct rtl8169_private *);
44473 void (*disable)(struct rtl8169_private *);
44474- } jumbo_ops;
44475+ } __no_const jumbo_ops;
44476
44477 struct csi_ops {
44478 void (*write)(struct rtl8169_private *, int, int);
44479 u32 (*read)(struct rtl8169_private *, int);
44480- } csi_ops;
44481+ } __no_const csi_ops;
44482
44483 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
44484 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
44485diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
44486index b495394..0748c54 100644
44487--- a/drivers/net/ethernet/sfc/ptp.c
44488+++ b/drivers/net/ethernet/sfc/ptp.c
44489@@ -535,7 +535,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
44490 (u32)((u64)ptp->start.dma_addr >> 32));
44491
44492 /* Clear flag that signals MC ready */
44493- ACCESS_ONCE(*start) = 0;
44494+ ACCESS_ONCE_RW(*start) = 0;
44495 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
44496 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
44497
44498diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
44499index 50617c5..b13724c 100644
44500--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
44501+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
44502@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
44503
44504 writel(value, ioaddr + MMC_CNTRL);
44505
44506- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
44507- MMC_CNTRL, value);
44508+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
44509+// MMC_CNTRL, value);
44510 }
44511
44512 /* To mask all all interrupts.*/
44513diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
44514index e6fe0d8..2b7d752 100644
44515--- a/drivers/net/hyperv/hyperv_net.h
44516+++ b/drivers/net/hyperv/hyperv_net.h
44517@@ -101,7 +101,7 @@ struct rndis_device {
44518
44519 enum rndis_device_state state;
44520 bool link_state;
44521- atomic_t new_req_id;
44522+ atomic_unchecked_t new_req_id;
44523
44524 spinlock_t request_lock;
44525 struct list_head req_list;
44526diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
44527index 0775f0a..d4fb316 100644
44528--- a/drivers/net/hyperv/rndis_filter.c
44529+++ b/drivers/net/hyperv/rndis_filter.c
44530@@ -104,7 +104,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
44531 * template
44532 */
44533 set = &rndis_msg->msg.set_req;
44534- set->req_id = atomic_inc_return(&dev->new_req_id);
44535+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
44536
44537 /* Add to the request list */
44538 spin_lock_irqsave(&dev->request_lock, flags);
44539@@ -752,7 +752,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
44540
44541 /* Setup the rndis set */
44542 halt = &request->request_msg.msg.halt_req;
44543- halt->req_id = atomic_inc_return(&dev->new_req_id);
44544+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
44545
44546 /* Ignore return since this msg is optional. */
44547 rndis_filter_send_request(dev, request);
44548diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
44549index bf0d55e..82bcfbd1 100644
44550--- a/drivers/net/ieee802154/fakehard.c
44551+++ b/drivers/net/ieee802154/fakehard.c
44552@@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
44553 phy->transmit_power = 0xbf;
44554
44555 dev->netdev_ops = &fake_ops;
44556- dev->ml_priv = &fake_mlme;
44557+ dev->ml_priv = (void *)&fake_mlme;
44558
44559 priv = netdev_priv(dev);
44560 priv->phy = phy;
44561diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
44562index 16b43bf..ead0c35 100644
44563--- a/drivers/net/macvlan.c
44564+++ b/drivers/net/macvlan.c
44565@@ -934,13 +934,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
44566 int macvlan_link_register(struct rtnl_link_ops *ops)
44567 {
44568 /* common fields */
44569- ops->priv_size = sizeof(struct macvlan_dev);
44570- ops->validate = macvlan_validate;
44571- ops->maxtype = IFLA_MACVLAN_MAX;
44572- ops->policy = macvlan_policy;
44573- ops->changelink = macvlan_changelink;
44574- ops->get_size = macvlan_get_size;
44575- ops->fill_info = macvlan_fill_info;
44576+ pax_open_kernel();
44577+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
44578+ *(void **)&ops->validate = macvlan_validate;
44579+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
44580+ *(const void **)&ops->policy = macvlan_policy;
44581+ *(void **)&ops->changelink = macvlan_changelink;
44582+ *(void **)&ops->get_size = macvlan_get_size;
44583+ *(void **)&ops->fill_info = macvlan_fill_info;
44584+ pax_close_kernel();
44585
44586 return rtnl_link_register(ops);
44587 };
44588@@ -996,7 +998,7 @@ static int macvlan_device_event(struct notifier_block *unused,
44589 return NOTIFY_DONE;
44590 }
44591
44592-static struct notifier_block macvlan_notifier_block __read_mostly = {
44593+static struct notifier_block macvlan_notifier_block = {
44594 .notifier_call = macvlan_device_event,
44595 };
44596
44597diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
44598index ea53abb..2e4d087 100644
44599--- a/drivers/net/macvtap.c
44600+++ b/drivers/net/macvtap.c
44601@@ -1286,7 +1286,7 @@ static int macvtap_device_event(struct notifier_block *unused,
44602 return NOTIFY_DONE;
44603 }
44604
44605-static struct notifier_block macvtap_notifier_block __read_mostly = {
44606+static struct notifier_block macvtap_notifier_block = {
44607 .notifier_call = macvtap_device_event,
44608 };
44609
44610diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
44611index daec9b0..6428fcb 100644
44612--- a/drivers/net/phy/mdio-bitbang.c
44613+++ b/drivers/net/phy/mdio-bitbang.c
44614@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
44615 struct mdiobb_ctrl *ctrl = bus->priv;
44616
44617 module_put(ctrl->ops->owner);
44618+ mdiobus_unregister(bus);
44619 mdiobus_free(bus);
44620 }
44621 EXPORT_SYMBOL(free_mdio_bitbang);
44622diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
44623index 72ff14b..11d442d 100644
44624--- a/drivers/net/ppp/ppp_generic.c
44625+++ b/drivers/net/ppp/ppp_generic.c
44626@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44627 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
44628 struct ppp_stats stats;
44629 struct ppp_comp_stats cstats;
44630- char *vers;
44631
44632 switch (cmd) {
44633 case SIOCGPPPSTATS:
44634@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44635 break;
44636
44637 case SIOCGPPPVER:
44638- vers = PPP_VERSION;
44639- if (copy_to_user(addr, vers, strlen(vers) + 1))
44640+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
44641 break;
44642 err = 0;
44643 break;
44644diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
44645index 1252d9c..80e660b 100644
44646--- a/drivers/net/slip/slhc.c
44647+++ b/drivers/net/slip/slhc.c
44648@@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
44649 register struct tcphdr *thp;
44650 register struct iphdr *ip;
44651 register struct cstate *cs;
44652- int len, hdrlen;
44653+ long len, hdrlen;
44654 unsigned char *cp = icp;
44655
44656 /* We've got a compressed packet; read the change byte */
44657diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
44658index bff7e0b..7315137 100644
44659--- a/drivers/net/team/team.c
44660+++ b/drivers/net/team/team.c
44661@@ -2702,7 +2702,7 @@ static int team_device_event(struct notifier_block *unused,
44662 return NOTIFY_DONE;
44663 }
44664
44665-static struct notifier_block team_notifier_block __read_mostly = {
44666+static struct notifier_block team_notifier_block = {
44667 .notifier_call = team_device_event,
44668 };
44669
44670diff --git a/drivers/net/tun.c b/drivers/net/tun.c
44671index 71af122..b3c20f3 100644
44672--- a/drivers/net/tun.c
44673+++ b/drivers/net/tun.c
44674@@ -1691,11 +1691,11 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
44675 INIT_LIST_HEAD(&tun->disabled);
44676 err = tun_attach(tun, file);
44677 if (err < 0)
44678- goto err_free_dev;
44679+ goto err_free_flow;
44680
44681 err = register_netdevice(tun->dev);
44682 if (err < 0)
44683- goto err_free_dev;
44684+ goto err_detach;
44685
44686 if (device_create_file(&tun->dev->dev, &dev_attr_tun_flags) ||
44687 device_create_file(&tun->dev->dev, &dev_attr_owner) ||
44688@@ -1739,7 +1739,12 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr)
44689 strcpy(ifr->ifr_name, tun->dev->name);
44690 return 0;
44691
44692- err_free_dev:
44693+err_detach:
44694+ tun_detach_all(dev);
44695+err_free_flow:
44696+ tun_flow_uninit(tun);
44697+ security_tun_dev_free_security(tun->security);
44698+err_free_dev:
44699 free_netdev(dev);
44700 return err;
44701 }
44702@@ -1869,7 +1874,7 @@ unlock:
44703 }
44704
44705 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
44706- unsigned long arg, int ifreq_len)
44707+ unsigned long arg, size_t ifreq_len)
44708 {
44709 struct tun_file *tfile = file->private_data;
44710 struct tun_struct *tun;
44711@@ -1881,6 +1886,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
44712 int vnet_hdr_sz;
44713 int ret;
44714
44715+ if (ifreq_len > sizeof ifr)
44716+ return -EFAULT;
44717+
44718 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
44719 if (copy_from_user(&ifr, argp, ifreq_len))
44720 return -EFAULT;
44721diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
44722index 86292e6..8d34433 100644
44723--- a/drivers/net/usb/hso.c
44724+++ b/drivers/net/usb/hso.c
44725@@ -71,7 +71,7 @@
44726 #include <asm/byteorder.h>
44727 #include <linux/serial_core.h>
44728 #include <linux/serial.h>
44729-
44730+#include <asm/local.h>
44731
44732 #define MOD_AUTHOR "Option Wireless"
44733 #define MOD_DESCRIPTION "USB High Speed Option driver"
44734@@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
44735 struct urb *urb;
44736
44737 urb = serial->rx_urb[0];
44738- if (serial->port.count > 0) {
44739+ if (atomic_read(&serial->port.count) > 0) {
44740 count = put_rxbuf_data(urb, serial);
44741 if (count == -1)
44742 return;
44743@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
44744 DUMP1(urb->transfer_buffer, urb->actual_length);
44745
44746 /* Anyone listening? */
44747- if (serial->port.count == 0)
44748+ if (atomic_read(&serial->port.count) == 0)
44749 return;
44750
44751 if (status == 0) {
44752@@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
44753 tty_port_tty_set(&serial->port, tty);
44754
44755 /* check for port already opened, if not set the termios */
44756- serial->port.count++;
44757- if (serial->port.count == 1) {
44758+ if (atomic_inc_return(&serial->port.count) == 1) {
44759 serial->rx_state = RX_IDLE;
44760 /* Force default termio settings */
44761 _hso_serial_set_termios(tty, NULL);
44762@@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
44763 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
44764 if (result) {
44765 hso_stop_serial_device(serial->parent);
44766- serial->port.count--;
44767+ atomic_dec(&serial->port.count);
44768 kref_put(&serial->parent->ref, hso_serial_ref_free);
44769 }
44770 } else {
44771@@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
44772
44773 /* reset the rts and dtr */
44774 /* do the actual close */
44775- serial->port.count--;
44776+ atomic_dec(&serial->port.count);
44777
44778- if (serial->port.count <= 0) {
44779- serial->port.count = 0;
44780+ if (atomic_read(&serial->port.count) <= 0) {
44781+ atomic_set(&serial->port.count, 0);
44782 tty_port_tty_set(&serial->port, NULL);
44783 if (!usb_gone)
44784 hso_stop_serial_device(serial->parent);
44785@@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
44786
44787 /* the actual setup */
44788 spin_lock_irqsave(&serial->serial_lock, flags);
44789- if (serial->port.count)
44790+ if (atomic_read(&serial->port.count))
44791 _hso_serial_set_termios(tty, old);
44792 else
44793 tty->termios = *old;
44794@@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
44795 D1("Pending read interrupt on port %d\n", i);
44796 spin_lock(&serial->serial_lock);
44797 if (serial->rx_state == RX_IDLE &&
44798- serial->port.count > 0) {
44799+ atomic_read(&serial->port.count) > 0) {
44800 /* Setup and send a ctrl req read on
44801 * port i */
44802 if (!serial->rx_urb_filled[0]) {
44803@@ -3062,7 +3061,7 @@ static int hso_resume(struct usb_interface *iface)
44804 /* Start all serial ports */
44805 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
44806 if (serial_table[i] && (serial_table[i]->interface == iface)) {
44807- if (dev2ser(serial_table[i])->port.count) {
44808+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
44809 result =
44810 hso_start_serial_device(serial_table[i], GFP_NOIO);
44811 hso_kick_transmit(dev2ser(serial_table[i]));
44812diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
44813index a79e9d3..78cd4fa 100644
44814--- a/drivers/net/usb/sierra_net.c
44815+++ b/drivers/net/usb/sierra_net.c
44816@@ -52,7 +52,7 @@ static const char driver_name[] = "sierra_net";
44817 /* atomic counter partially included in MAC address to make sure 2 devices
44818 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
44819 */
44820-static atomic_t iface_counter = ATOMIC_INIT(0);
44821+static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
44822
44823 /*
44824 * SYNC Timer Delay definition used to set the expiry time
44825@@ -698,7 +698,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
44826 dev->net->netdev_ops = &sierra_net_device_ops;
44827
44828 /* change MAC addr to include, ifacenum, and to be unique */
44829- dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
44830+ dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
44831 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
44832
44833 /* we will have to manufacture ethernet headers, prepare template */
44834diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
44835index 767f7af..8162b9d 100644
44836--- a/drivers/net/vxlan.c
44837+++ b/drivers/net/vxlan.c
44838@@ -1868,7 +1868,7 @@ nla_put_failure:
44839 return -EMSGSIZE;
44840 }
44841
44842-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
44843+static struct rtnl_link_ops vxlan_link_ops = {
44844 .kind = "vxlan",
44845 .maxtype = IFLA_VXLAN_MAX,
44846 .policy = vxlan_policy,
44847diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
44848index 0b60295..b8bfa5b 100644
44849--- a/drivers/net/wimax/i2400m/rx.c
44850+++ b/drivers/net/wimax/i2400m/rx.c
44851@@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
44852 if (i2400m->rx_roq == NULL)
44853 goto error_roq_alloc;
44854
44855- rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
44856+ rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
44857 GFP_KERNEL);
44858 if (rd == NULL) {
44859 result = -ENOMEM;
44860diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
44861index 34c8a33..3261fdc 100644
44862--- a/drivers/net/wireless/at76c50x-usb.c
44863+++ b/drivers/net/wireless/at76c50x-usb.c
44864@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
44865 }
44866
44867 /* Convert timeout from the DFU status to jiffies */
44868-static inline unsigned long at76_get_timeout(struct dfu_status *s)
44869+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
44870 {
44871 return msecs_to_jiffies((s->poll_timeout[2] << 16)
44872 | (s->poll_timeout[1] << 8)
44873diff --git a/drivers/net/wireless/ath/ath10k/core.c b/drivers/net/wireless/ath/ath10k/core.c
44874index 2b3426b..1f564be 100644
44875--- a/drivers/net/wireless/ath/ath10k/core.c
44876+++ b/drivers/net/wireless/ath/ath10k/core.c
44877@@ -507,7 +507,9 @@ EXPORT_SYMBOL(ath10k_core_destroy);
44878
44879 int ath10k_core_register(struct ath10k *ar)
44880 {
44881- struct ath10k_htc_ops htc_ops;
44882+ static struct ath10k_htc_ops htc_ops = {
44883+ .target_send_suspend_complete = ath10k_send_suspend_complete,
44884+ };
44885 struct bmi_target_info target_info;
44886 int status;
44887
44888@@ -536,8 +538,6 @@ int ath10k_core_register(struct ath10k *ar)
44889 if (status)
44890 goto err;
44891
44892- htc_ops.target_send_suspend_complete = ath10k_send_suspend_complete;
44893-
44894 ar->htc = ath10k_htc_create(ar, &htc_ops);
44895 if (IS_ERR(ar->htc)) {
44896 status = PTR_ERR(ar->htc);
44897diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
44898index 74363c9..237b926 100644
44899--- a/drivers/net/wireless/ath/ath10k/htc.c
44900+++ b/drivers/net/wireless/ath/ath10k/htc.c
44901@@ -963,7 +963,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
44902 struct ath10k_htc *ath10k_htc_create(struct ath10k *ar,
44903 struct ath10k_htc_ops *htc_ops)
44904 {
44905- struct ath10k_hif_cb htc_callbacks;
44906+ static struct ath10k_hif_cb htc_callbacks = {
44907+ .rx_completion = ath10k_htc_rx_completion_handler,
44908+ .tx_completion = ath10k_htc_tx_completion_handler,
44909+ };
44910 struct ath10k_htc_ep *ep = NULL;
44911 struct ath10k_htc *htc = NULL;
44912
44913@@ -979,8 +982,6 @@ struct ath10k_htc *ath10k_htc_create(struct ath10k *ar,
44914 ath10k_htc_reset_endpoint_states(htc);
44915
44916 /* setup HIF layer callbacks */
44917- htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
44918- htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
44919 htc->ar = ar;
44920
44921 /* Get HIF default pipe for HTC message exchange */
44922diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
44923index 8d78253..bebbb68 100644
44924--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
44925+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
44926@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44927 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
44928 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
44929
44930- ACCESS_ONCE(ads->ds_link) = i->link;
44931- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
44932+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
44933+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
44934
44935 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
44936 ctl6 = SM(i->keytype, AR_EncrType);
44937@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44938
44939 if ((i->is_first || i->is_last) &&
44940 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
44941- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
44942+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
44943 | set11nTries(i->rates, 1)
44944 | set11nTries(i->rates, 2)
44945 | set11nTries(i->rates, 3)
44946 | (i->dur_update ? AR_DurUpdateEna : 0)
44947 | SM(0, AR_BurstDur);
44948
44949- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
44950+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
44951 | set11nRate(i->rates, 1)
44952 | set11nRate(i->rates, 2)
44953 | set11nRate(i->rates, 3);
44954 } else {
44955- ACCESS_ONCE(ads->ds_ctl2) = 0;
44956- ACCESS_ONCE(ads->ds_ctl3) = 0;
44957+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
44958+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
44959 }
44960
44961 if (!i->is_first) {
44962- ACCESS_ONCE(ads->ds_ctl0) = 0;
44963- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
44964- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
44965+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
44966+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
44967+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
44968 return;
44969 }
44970
44971@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44972 break;
44973 }
44974
44975- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
44976+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
44977 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
44978 | SM(i->txpower, AR_XmitPower)
44979 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
44980@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
44981 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
44982 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
44983
44984- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
44985- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
44986+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
44987+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
44988
44989 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
44990 return;
44991
44992- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
44993+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
44994 | set11nPktDurRTSCTS(i->rates, 1);
44995
44996- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
44997+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
44998 | set11nPktDurRTSCTS(i->rates, 3);
44999
45000- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
45001+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
45002 | set11nRateFlags(i->rates, 1)
45003 | set11nRateFlags(i->rates, 2)
45004 | set11nRateFlags(i->rates, 3)
45005diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
45006index 5163abd..3ada4c2 100644
45007--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
45008+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
45009@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
45010 (i->qcu << AR_TxQcuNum_S) | desc_len;
45011
45012 checksum += val;
45013- ACCESS_ONCE(ads->info) = val;
45014+ ACCESS_ONCE_RW(ads->info) = val;
45015
45016 checksum += i->link;
45017- ACCESS_ONCE(ads->link) = i->link;
45018+ ACCESS_ONCE_RW(ads->link) = i->link;
45019
45020 checksum += i->buf_addr[0];
45021- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
45022+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
45023 checksum += i->buf_addr[1];
45024- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
45025+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
45026 checksum += i->buf_addr[2];
45027- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
45028+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
45029 checksum += i->buf_addr[3];
45030- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
45031+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
45032
45033 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
45034- ACCESS_ONCE(ads->ctl3) = val;
45035+ ACCESS_ONCE_RW(ads->ctl3) = val;
45036 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
45037- ACCESS_ONCE(ads->ctl5) = val;
45038+ ACCESS_ONCE_RW(ads->ctl5) = val;
45039 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
45040- ACCESS_ONCE(ads->ctl7) = val;
45041+ ACCESS_ONCE_RW(ads->ctl7) = val;
45042 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
45043- ACCESS_ONCE(ads->ctl9) = val;
45044+ ACCESS_ONCE_RW(ads->ctl9) = val;
45045
45046 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
45047- ACCESS_ONCE(ads->ctl10) = checksum;
45048+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
45049
45050 if (i->is_first || i->is_last) {
45051- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
45052+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
45053 | set11nTries(i->rates, 1)
45054 | set11nTries(i->rates, 2)
45055 | set11nTries(i->rates, 3)
45056 | (i->dur_update ? AR_DurUpdateEna : 0)
45057 | SM(0, AR_BurstDur);
45058
45059- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
45060+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
45061 | set11nRate(i->rates, 1)
45062 | set11nRate(i->rates, 2)
45063 | set11nRate(i->rates, 3);
45064 } else {
45065- ACCESS_ONCE(ads->ctl13) = 0;
45066- ACCESS_ONCE(ads->ctl14) = 0;
45067+ ACCESS_ONCE_RW(ads->ctl13) = 0;
45068+ ACCESS_ONCE_RW(ads->ctl14) = 0;
45069 }
45070
45071 ads->ctl20 = 0;
45072@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
45073
45074 ctl17 = SM(i->keytype, AR_EncrType);
45075 if (!i->is_first) {
45076- ACCESS_ONCE(ads->ctl11) = 0;
45077- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
45078- ACCESS_ONCE(ads->ctl15) = 0;
45079- ACCESS_ONCE(ads->ctl16) = 0;
45080- ACCESS_ONCE(ads->ctl17) = ctl17;
45081- ACCESS_ONCE(ads->ctl18) = 0;
45082- ACCESS_ONCE(ads->ctl19) = 0;
45083+ ACCESS_ONCE_RW(ads->ctl11) = 0;
45084+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
45085+ ACCESS_ONCE_RW(ads->ctl15) = 0;
45086+ ACCESS_ONCE_RW(ads->ctl16) = 0;
45087+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
45088+ ACCESS_ONCE_RW(ads->ctl18) = 0;
45089+ ACCESS_ONCE_RW(ads->ctl19) = 0;
45090 return;
45091 }
45092
45093- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
45094+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
45095 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
45096 | SM(i->txpower, AR_XmitPower)
45097 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
45098@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
45099 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
45100 ctl12 |= SM(val, AR_PAPRDChainMask);
45101
45102- ACCESS_ONCE(ads->ctl12) = ctl12;
45103- ACCESS_ONCE(ads->ctl17) = ctl17;
45104+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
45105+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
45106
45107- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
45108+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
45109 | set11nPktDurRTSCTS(i->rates, 1);
45110
45111- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
45112+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
45113 | set11nPktDurRTSCTS(i->rates, 3);
45114
45115- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
45116+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
45117 | set11nRateFlags(i->rates, 1)
45118 | set11nRateFlags(i->rates, 2)
45119 | set11nRateFlags(i->rates, 3)
45120 | SM(i->rtscts_rate, AR_RTSCTSRate);
45121
45122- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
45123+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
45124 }
45125
45126 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
45127diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
45128index cd74b3a..6a28d24 100644
45129--- a/drivers/net/wireless/ath/ath9k/hw.h
45130+++ b/drivers/net/wireless/ath/ath9k/hw.h
45131@@ -652,7 +652,7 @@ struct ath_hw_private_ops {
45132
45133 /* ANI */
45134 void (*ani_cache_ini_regs)(struct ath_hw *ah);
45135-};
45136+} __no_const;
45137
45138 /**
45139 * struct ath_spec_scan - parameters for Atheros spectral scan
45140@@ -721,7 +721,7 @@ struct ath_hw_ops {
45141 struct ath_spec_scan *param);
45142 void (*spectral_scan_trigger)(struct ath_hw *ah);
45143 void (*spectral_scan_wait)(struct ath_hw *ah);
45144-};
45145+} __no_const;
45146
45147 struct ath_nf_limits {
45148 s16 max;
45149diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
45150index 9581d07..84f6a76 100644
45151--- a/drivers/net/wireless/iwlegacy/3945-mac.c
45152+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
45153@@ -3639,7 +3639,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
45154 */
45155 if (il3945_mod_params.disable_hw_scan) {
45156 D_INFO("Disabling hw_scan\n");
45157- il3945_mac_ops.hw_scan = NULL;
45158+ pax_open_kernel();
45159+ *(void **)&il3945_mac_ops.hw_scan = NULL;
45160+ pax_close_kernel();
45161 }
45162
45163 D_INFO("*** LOAD DRIVER ***\n");
45164diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
45165index d532948..e0d8bb1 100644
45166--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
45167+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
45168@@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
45169 {
45170 struct iwl_priv *priv = file->private_data;
45171 char buf[64];
45172- int buf_size;
45173+ size_t buf_size;
45174 u32 offset, len;
45175
45176 memset(buf, 0, sizeof(buf));
45177@@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
45178 struct iwl_priv *priv = file->private_data;
45179
45180 char buf[8];
45181- int buf_size;
45182+ size_t buf_size;
45183 u32 reset_flag;
45184
45185 memset(buf, 0, sizeof(buf));
45186@@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
45187 {
45188 struct iwl_priv *priv = file->private_data;
45189 char buf[8];
45190- int buf_size;
45191+ size_t buf_size;
45192 int ht40;
45193
45194 memset(buf, 0, sizeof(buf));
45195@@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
45196 {
45197 struct iwl_priv *priv = file->private_data;
45198 char buf[8];
45199- int buf_size;
45200+ size_t buf_size;
45201 int value;
45202
45203 memset(buf, 0, sizeof(buf));
45204@@ -698,10 +698,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
45205 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
45206 DEBUGFS_READ_FILE_OPS(current_sleep_command);
45207
45208-static const char *fmt_value = " %-30s %10u\n";
45209-static const char *fmt_hex = " %-30s 0x%02X\n";
45210-static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
45211-static const char *fmt_header =
45212+static const char fmt_value[] = " %-30s %10u\n";
45213+static const char fmt_hex[] = " %-30s 0x%02X\n";
45214+static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
45215+static const char fmt_header[] =
45216 "%-32s current cumulative delta max\n";
45217
45218 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
45219@@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
45220 {
45221 struct iwl_priv *priv = file->private_data;
45222 char buf[8];
45223- int buf_size;
45224+ size_t buf_size;
45225 int clear;
45226
45227 memset(buf, 0, sizeof(buf));
45228@@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
45229 {
45230 struct iwl_priv *priv = file->private_data;
45231 char buf[8];
45232- int buf_size;
45233+ size_t buf_size;
45234 int trace;
45235
45236 memset(buf, 0, sizeof(buf));
45237@@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
45238 {
45239 struct iwl_priv *priv = file->private_data;
45240 char buf[8];
45241- int buf_size;
45242+ size_t buf_size;
45243 int missed;
45244
45245 memset(buf, 0, sizeof(buf));
45246@@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
45247
45248 struct iwl_priv *priv = file->private_data;
45249 char buf[8];
45250- int buf_size;
45251+ size_t buf_size;
45252 int plcp;
45253
45254 memset(buf, 0, sizeof(buf));
45255@@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
45256
45257 struct iwl_priv *priv = file->private_data;
45258 char buf[8];
45259- int buf_size;
45260+ size_t buf_size;
45261 int flush;
45262
45263 memset(buf, 0, sizeof(buf));
45264@@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
45265
45266 struct iwl_priv *priv = file->private_data;
45267 char buf[8];
45268- int buf_size;
45269+ size_t buf_size;
45270 int rts;
45271
45272 if (!priv->cfg->ht_params)
45273@@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
45274 {
45275 struct iwl_priv *priv = file->private_data;
45276 char buf[8];
45277- int buf_size;
45278+ size_t buf_size;
45279
45280 memset(buf, 0, sizeof(buf));
45281 buf_size = min(count, sizeof(buf) - 1);
45282@@ -2254,7 +2254,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
45283 struct iwl_priv *priv = file->private_data;
45284 u32 event_log_flag;
45285 char buf[8];
45286- int buf_size;
45287+ size_t buf_size;
45288
45289 /* check that the interface is up */
45290 if (!iwl_is_ready(priv))
45291@@ -2308,7 +2308,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
45292 struct iwl_priv *priv = file->private_data;
45293 char buf[8];
45294 u32 calib_disabled;
45295- int buf_size;
45296+ size_t buf_size;
45297
45298 memset(buf, 0, sizeof(buf));
45299 buf_size = min(count, sizeof(buf) - 1);
45300diff --git a/drivers/net/wireless/iwlwifi/dvm/main.c b/drivers/net/wireless/iwlwifi/dvm/main.c
45301index 1531a4f..21d2641 100644
45302--- a/drivers/net/wireless/iwlwifi/dvm/main.c
45303+++ b/drivers/net/wireless/iwlwifi/dvm/main.c
45304@@ -1180,7 +1180,7 @@ static void iwl_option_config(struct iwl_priv *priv)
45305 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
45306 {
45307 struct iwl_nvm_data *data = priv->nvm_data;
45308- char *debug_msg;
45309+ static const char debug_msg[] = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
45310
45311 if (data->sku_cap_11n_enable &&
45312 !priv->cfg->ht_params) {
45313@@ -1194,7 +1194,6 @@ static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
45314 return -EINVAL;
45315 }
45316
45317- debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
45318 IWL_DEBUG_INFO(priv, debug_msg,
45319 data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
45320 data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
45321diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
45322index 390e2f0..75cfbaf 100644
45323--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
45324+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
45325@@ -1350,7 +1350,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
45326 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
45327
45328 char buf[8];
45329- int buf_size;
45330+ size_t buf_size;
45331 u32 reset_flag;
45332
45333 memset(buf, 0, sizeof(buf));
45334@@ -1371,7 +1371,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
45335 {
45336 struct iwl_trans *trans = file->private_data;
45337 char buf[8];
45338- int buf_size;
45339+ size_t buf_size;
45340 int csr;
45341
45342 memset(buf, 0, sizeof(buf));
45343diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
45344index cb34c78..9fec0dc 100644
45345--- a/drivers/net/wireless/mac80211_hwsim.c
45346+++ b/drivers/net/wireless/mac80211_hwsim.c
45347@@ -2195,25 +2195,19 @@ static int __init init_mac80211_hwsim(void)
45348
45349 if (channels > 1) {
45350 hwsim_if_comb.num_different_channels = channels;
45351- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
45352- mac80211_hwsim_ops.cancel_hw_scan =
45353- mac80211_hwsim_cancel_hw_scan;
45354- mac80211_hwsim_ops.sw_scan_start = NULL;
45355- mac80211_hwsim_ops.sw_scan_complete = NULL;
45356- mac80211_hwsim_ops.remain_on_channel =
45357- mac80211_hwsim_roc;
45358- mac80211_hwsim_ops.cancel_remain_on_channel =
45359- mac80211_hwsim_croc;
45360- mac80211_hwsim_ops.add_chanctx =
45361- mac80211_hwsim_add_chanctx;
45362- mac80211_hwsim_ops.remove_chanctx =
45363- mac80211_hwsim_remove_chanctx;
45364- mac80211_hwsim_ops.change_chanctx =
45365- mac80211_hwsim_change_chanctx;
45366- mac80211_hwsim_ops.assign_vif_chanctx =
45367- mac80211_hwsim_assign_vif_chanctx;
45368- mac80211_hwsim_ops.unassign_vif_chanctx =
45369- mac80211_hwsim_unassign_vif_chanctx;
45370+ pax_open_kernel();
45371+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
45372+ *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
45373+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
45374+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
45375+ *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
45376+ *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
45377+ *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
45378+ *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
45379+ *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
45380+ *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
45381+ *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
45382+ pax_close_kernel();
45383 }
45384
45385 spin_lock_init(&hwsim_radio_lock);
45386diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
45387index 8169a85..7fa3b47 100644
45388--- a/drivers/net/wireless/rndis_wlan.c
45389+++ b/drivers/net/wireless/rndis_wlan.c
45390@@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
45391
45392 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
45393
45394- if (rts_threshold < 0 || rts_threshold > 2347)
45395+ if (rts_threshold > 2347)
45396 rts_threshold = 2347;
45397
45398 tmp = cpu_to_le32(rts_threshold);
45399diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
45400index ee3fc57..ed5ddc9 100644
45401--- a/drivers/net/wireless/rt2x00/rt2x00.h
45402+++ b/drivers/net/wireless/rt2x00/rt2x00.h
45403@@ -386,7 +386,7 @@ struct rt2x00_intf {
45404 * for hardware which doesn't support hardware
45405 * sequence counting.
45406 */
45407- atomic_t seqno;
45408+ atomic_unchecked_t seqno;
45409 };
45410
45411 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
45412diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
45413index aa95c6c..a59dd67 100644
45414--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
45415+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
45416@@ -252,9 +252,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
45417 * sequence counter given by mac80211.
45418 */
45419 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
45420- seqno = atomic_add_return(0x10, &intf->seqno);
45421+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
45422 else
45423- seqno = atomic_read(&intf->seqno);
45424+ seqno = atomic_read_unchecked(&intf->seqno);
45425
45426 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
45427 hdr->seq_ctrl |= cpu_to_le16(seqno);
45428diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
45429index e2b3d9c..67a5184 100644
45430--- a/drivers/net/wireless/ti/wl1251/sdio.c
45431+++ b/drivers/net/wireless/ti/wl1251/sdio.c
45432@@ -271,13 +271,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
45433
45434 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
45435
45436- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
45437- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
45438+ pax_open_kernel();
45439+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
45440+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
45441+ pax_close_kernel();
45442
45443 wl1251_info("using dedicated interrupt line");
45444 } else {
45445- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
45446- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
45447+ pax_open_kernel();
45448+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
45449+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
45450+ pax_close_kernel();
45451
45452 wl1251_info("using SDIO interrupt");
45453 }
45454diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
45455index 1c627da..69f7d17 100644
45456--- a/drivers/net/wireless/ti/wl12xx/main.c
45457+++ b/drivers/net/wireless/ti/wl12xx/main.c
45458@@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
45459 sizeof(wl->conf.mem));
45460
45461 /* read data preparation is only needed by wl127x */
45462- wl->ops->prepare_read = wl127x_prepare_read;
45463+ pax_open_kernel();
45464+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
45465+ pax_close_kernel();
45466
45467 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
45468 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
45469@@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
45470 sizeof(wl->conf.mem));
45471
45472 /* read data preparation is only needed by wl127x */
45473- wl->ops->prepare_read = wl127x_prepare_read;
45474+ pax_open_kernel();
45475+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
45476+ pax_close_kernel();
45477
45478 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
45479 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
45480diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
45481index 7aa0eb8..5a9ef38 100644
45482--- a/drivers/net/wireless/ti/wl18xx/main.c
45483+++ b/drivers/net/wireless/ti/wl18xx/main.c
45484@@ -1730,8 +1730,10 @@ static int wl18xx_setup(struct wl1271 *wl)
45485 }
45486
45487 if (!checksum_param) {
45488- wl18xx_ops.set_rx_csum = NULL;
45489- wl18xx_ops.init_vif = NULL;
45490+ pax_open_kernel();
45491+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
45492+ *(void **)&wl18xx_ops.init_vif = NULL;
45493+ pax_close_kernel();
45494 }
45495
45496 /* Enable 11a Band only if we have 5G antennas */
45497diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
45498index 7ef0b4a..ff65c28 100644
45499--- a/drivers/net/wireless/zd1211rw/zd_usb.c
45500+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
45501@@ -386,7 +386,7 @@ static inline void handle_regs_int(struct urb *urb)
45502 {
45503 struct zd_usb *usb = urb->context;
45504 struct zd_usb_interrupt *intr = &usb->intr;
45505- int len;
45506+ unsigned int len;
45507 u16 int_num;
45508
45509 ZD_ASSERT(in_interrupt());
45510diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
45511index d93b2b6..ae50401 100644
45512--- a/drivers/oprofile/buffer_sync.c
45513+++ b/drivers/oprofile/buffer_sync.c
45514@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
45515 if (cookie == NO_COOKIE)
45516 offset = pc;
45517 if (cookie == INVALID_COOKIE) {
45518- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
45519+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
45520 offset = pc;
45521 }
45522 if (cookie != last_cookie) {
45523@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
45524 /* add userspace sample */
45525
45526 if (!mm) {
45527- atomic_inc(&oprofile_stats.sample_lost_no_mm);
45528+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
45529 return 0;
45530 }
45531
45532 cookie = lookup_dcookie(mm, s->eip, &offset);
45533
45534 if (cookie == INVALID_COOKIE) {
45535- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
45536+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
45537 return 0;
45538 }
45539
45540@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
45541 /* ignore backtraces if failed to add a sample */
45542 if (state == sb_bt_start) {
45543 state = sb_bt_ignore;
45544- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
45545+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
45546 }
45547 }
45548 release_mm(mm);
45549diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
45550index c0cc4e7..44d4e54 100644
45551--- a/drivers/oprofile/event_buffer.c
45552+++ b/drivers/oprofile/event_buffer.c
45553@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
45554 }
45555
45556 if (buffer_pos == buffer_size) {
45557- atomic_inc(&oprofile_stats.event_lost_overflow);
45558+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
45559 return;
45560 }
45561
45562diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
45563index ed2c3ec..deda85a 100644
45564--- a/drivers/oprofile/oprof.c
45565+++ b/drivers/oprofile/oprof.c
45566@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
45567 if (oprofile_ops.switch_events())
45568 return;
45569
45570- atomic_inc(&oprofile_stats.multiplex_counter);
45571+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
45572 start_switch_worker();
45573 }
45574
45575diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
45576index 84a208d..d61b0a1 100644
45577--- a/drivers/oprofile/oprofile_files.c
45578+++ b/drivers/oprofile/oprofile_files.c
45579@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
45580
45581 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
45582
45583-static ssize_t timeout_read(struct file *file, char __user *buf,
45584+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
45585 size_t count, loff_t *offset)
45586 {
45587 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
45588diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
45589index 917d28e..d62d981 100644
45590--- a/drivers/oprofile/oprofile_stats.c
45591+++ b/drivers/oprofile/oprofile_stats.c
45592@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
45593 cpu_buf->sample_invalid_eip = 0;
45594 }
45595
45596- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
45597- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
45598- atomic_set(&oprofile_stats.event_lost_overflow, 0);
45599- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
45600- atomic_set(&oprofile_stats.multiplex_counter, 0);
45601+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
45602+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
45603+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
45604+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
45605+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
45606 }
45607
45608
45609diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
45610index 38b6fc0..b5cbfce 100644
45611--- a/drivers/oprofile/oprofile_stats.h
45612+++ b/drivers/oprofile/oprofile_stats.h
45613@@ -13,11 +13,11 @@
45614 #include <linux/atomic.h>
45615
45616 struct oprofile_stat_struct {
45617- atomic_t sample_lost_no_mm;
45618- atomic_t sample_lost_no_mapping;
45619- atomic_t bt_lost_no_mapping;
45620- atomic_t event_lost_overflow;
45621- atomic_t multiplex_counter;
45622+ atomic_unchecked_t sample_lost_no_mm;
45623+ atomic_unchecked_t sample_lost_no_mapping;
45624+ atomic_unchecked_t bt_lost_no_mapping;
45625+ atomic_unchecked_t event_lost_overflow;
45626+ atomic_unchecked_t multiplex_counter;
45627 };
45628
45629 extern struct oprofile_stat_struct oprofile_stats;
45630diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
45631index 7c12d9c..558bf3bb 100644
45632--- a/drivers/oprofile/oprofilefs.c
45633+++ b/drivers/oprofile/oprofilefs.c
45634@@ -190,7 +190,7 @@ static const struct file_operations atomic_ro_fops = {
45635
45636
45637 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
45638- char const *name, atomic_t *val)
45639+ char const *name, atomic_unchecked_t *val)
45640 {
45641 return __oprofilefs_create_file(sb, root, name,
45642 &atomic_ro_fops, 0444, val);
45643diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
45644index 61be1d9..dec05d7 100644
45645--- a/drivers/oprofile/timer_int.c
45646+++ b/drivers/oprofile/timer_int.c
45647@@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
45648 return NOTIFY_OK;
45649 }
45650
45651-static struct notifier_block __refdata oprofile_cpu_notifier = {
45652+static struct notifier_block oprofile_cpu_notifier = {
45653 .notifier_call = oprofile_cpu_notify,
45654 };
45655
45656diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
45657index 92ed045..62d39bd7 100644
45658--- a/drivers/parport/procfs.c
45659+++ b/drivers/parport/procfs.c
45660@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
45661
45662 *ppos += len;
45663
45664- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
45665+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
45666 }
45667
45668 #ifdef CONFIG_PARPORT_1284
45669@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
45670
45671 *ppos += len;
45672
45673- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
45674+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
45675 }
45676 #endif /* IEEE1284.3 support. */
45677
45678diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
45679index c35e8ad..fc33beb 100644
45680--- a/drivers/pci/hotplug/acpiphp_ibm.c
45681+++ b/drivers/pci/hotplug/acpiphp_ibm.c
45682@@ -464,7 +464,9 @@ static int __init ibm_acpiphp_init(void)
45683 goto init_cleanup;
45684 }
45685
45686- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
45687+ pax_open_kernel();
45688+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
45689+ pax_close_kernel();
45690 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
45691
45692 return retval;
45693diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
45694index a6a71c4..c91097b 100644
45695--- a/drivers/pci/hotplug/cpcihp_generic.c
45696+++ b/drivers/pci/hotplug/cpcihp_generic.c
45697@@ -73,7 +73,6 @@ static u16 port;
45698 static unsigned int enum_bit;
45699 static u8 enum_mask;
45700
45701-static struct cpci_hp_controller_ops generic_hpc_ops;
45702 static struct cpci_hp_controller generic_hpc;
45703
45704 static int __init validate_parameters(void)
45705@@ -139,6 +138,10 @@ static int query_enum(void)
45706 return ((value & enum_mask) == enum_mask);
45707 }
45708
45709+static struct cpci_hp_controller_ops generic_hpc_ops = {
45710+ .query_enum = query_enum,
45711+};
45712+
45713 static int __init cpcihp_generic_init(void)
45714 {
45715 int status;
45716@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
45717 pci_dev_put(dev);
45718
45719 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
45720- generic_hpc_ops.query_enum = query_enum;
45721 generic_hpc.ops = &generic_hpc_ops;
45722
45723 status = cpci_hp_register_controller(&generic_hpc);
45724diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
45725index 449b4bb..257e2e8 100644
45726--- a/drivers/pci/hotplug/cpcihp_zt5550.c
45727+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
45728@@ -59,7 +59,6 @@
45729 /* local variables */
45730 static bool debug;
45731 static bool poll;
45732-static struct cpci_hp_controller_ops zt5550_hpc_ops;
45733 static struct cpci_hp_controller zt5550_hpc;
45734
45735 /* Primary cPCI bus bridge device */
45736@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
45737 return 0;
45738 }
45739
45740+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
45741+ .query_enum = zt5550_hc_query_enum,
45742+};
45743+
45744 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
45745 {
45746 int status;
45747@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
45748 dbg("returned from zt5550_hc_config");
45749
45750 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
45751- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
45752 zt5550_hpc.ops = &zt5550_hpc_ops;
45753 if(!poll) {
45754 zt5550_hpc.irq = hc_dev->irq;
45755 zt5550_hpc.irq_flags = IRQF_SHARED;
45756 zt5550_hpc.dev_id = hc_dev;
45757
45758- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
45759- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
45760- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
45761+ pax_open_kernel();
45762+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
45763+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
45764+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
45765+ pax_open_kernel();
45766 } else {
45767 info("using ENUM# polling mode");
45768 }
45769diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
45770index 76ba8a1..20ca857 100644
45771--- a/drivers/pci/hotplug/cpqphp_nvram.c
45772+++ b/drivers/pci/hotplug/cpqphp_nvram.c
45773@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
45774
45775 void compaq_nvram_init (void __iomem *rom_start)
45776 {
45777+
45778+#ifndef CONFIG_PAX_KERNEXEC
45779 if (rom_start) {
45780 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
45781 }
45782+#endif
45783+
45784 dbg("int15 entry = %p\n", compaq_int15_entry_point);
45785
45786 /* initialize our int15 lock */
45787diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
45788index ec20f74..c1d961e 100644
45789--- a/drivers/pci/hotplug/pci_hotplug_core.c
45790+++ b/drivers/pci/hotplug/pci_hotplug_core.c
45791@@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
45792 return -EINVAL;
45793 }
45794
45795- slot->ops->owner = owner;
45796- slot->ops->mod_name = mod_name;
45797+ pax_open_kernel();
45798+ *(struct module **)&slot->ops->owner = owner;
45799+ *(const char **)&slot->ops->mod_name = mod_name;
45800+ pax_close_kernel();
45801
45802 mutex_lock(&pci_hp_mutex);
45803 /*
45804diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
45805index 7d72c5e..edce02c 100644
45806--- a/drivers/pci/hotplug/pciehp_core.c
45807+++ b/drivers/pci/hotplug/pciehp_core.c
45808@@ -91,7 +91,7 @@ static int init_slot(struct controller *ctrl)
45809 struct slot *slot = ctrl->slot;
45810 struct hotplug_slot *hotplug = NULL;
45811 struct hotplug_slot_info *info = NULL;
45812- struct hotplug_slot_ops *ops = NULL;
45813+ hotplug_slot_ops_no_const *ops = NULL;
45814 char name[SLOT_NAME_SIZE];
45815 int retval = -ENOMEM;
45816
45817diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
45818index c0dbe1f..94cf3d8 100644
45819--- a/drivers/pci/pci-sysfs.c
45820+++ b/drivers/pci/pci-sysfs.c
45821@@ -1073,7 +1073,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
45822 {
45823 /* allocate attribute structure, piggyback attribute name */
45824 int name_len = write_combine ? 13 : 10;
45825- struct bin_attribute *res_attr;
45826+ bin_attribute_no_const *res_attr;
45827 int retval;
45828
45829 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
45830@@ -1258,7 +1258,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
45831 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
45832 {
45833 int retval;
45834- struct bin_attribute *attr;
45835+ bin_attribute_no_const *attr;
45836
45837 /* If the device has VPD, try to expose it in sysfs. */
45838 if (dev->vpd) {
45839@@ -1305,7 +1305,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
45840 {
45841 int retval;
45842 int rom_size = 0;
45843- struct bin_attribute *attr;
45844+ bin_attribute_no_const *attr;
45845
45846 if (!sysfs_initialized)
45847 return -EACCES;
45848diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
45849index d1182c4..2a138ec 100644
45850--- a/drivers/pci/pci.h
45851+++ b/drivers/pci/pci.h
45852@@ -92,7 +92,7 @@ struct pci_vpd_ops {
45853 struct pci_vpd {
45854 unsigned int len;
45855 const struct pci_vpd_ops *ops;
45856- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
45857+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
45858 };
45859
45860 int pci_vpd_pci22_init(struct pci_dev *dev);
45861diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
45862index 403a443..034e050 100644
45863--- a/drivers/pci/pcie/aspm.c
45864+++ b/drivers/pci/pcie/aspm.c
45865@@ -27,9 +27,9 @@
45866 #define MODULE_PARAM_PREFIX "pcie_aspm."
45867
45868 /* Note: those are not register definitions */
45869-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
45870-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
45871-#define ASPM_STATE_L1 (4) /* L1 state */
45872+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
45873+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
45874+#define ASPM_STATE_L1 (4U) /* L1 state */
45875 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
45876 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
45877
45878diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
45879index 46ada5c..20da716 100644
45880--- a/drivers/pci/probe.c
45881+++ b/drivers/pci/probe.c
45882@@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
45883 struct pci_bus_region region, inverted_region;
45884 bool bar_too_big = false, bar_disabled = false;
45885
45886- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
45887+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
45888
45889 /* No printks while decoding is disabled! */
45890 if (!dev->mmio_always_on) {
45891diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
45892index cdc7836..528635c 100644
45893--- a/drivers/pci/proc.c
45894+++ b/drivers/pci/proc.c
45895@@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
45896 static int __init pci_proc_init(void)
45897 {
45898 struct pci_dev *dev = NULL;
45899+
45900+#ifdef CONFIG_GRKERNSEC_PROC_ADD
45901+#ifdef CONFIG_GRKERNSEC_PROC_USER
45902+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
45903+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
45904+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
45905+#endif
45906+#else
45907 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
45908+#endif
45909 proc_create("devices", 0, proc_bus_pci_dir,
45910 &proc_bus_pci_dev_operations);
45911 proc_initialized = 1;
45912diff --git a/drivers/platform/x86/chromeos_laptop.c b/drivers/platform/x86/chromeos_laptop.c
45913index 3e5b4497..dcdfb70 100644
45914--- a/drivers/platform/x86/chromeos_laptop.c
45915+++ b/drivers/platform/x86/chromeos_laptop.c
45916@@ -301,7 +301,7 @@ static int __init setup_tsl2563_als(const struct dmi_system_id *id)
45917 return 0;
45918 }
45919
45920-static struct dmi_system_id __initdata chromeos_laptop_dmi_table[] = {
45921+static struct dmi_system_id __initconst chromeos_laptop_dmi_table[] = {
45922 {
45923 .ident = "Samsung Series 5 550 - Touchpad",
45924 .matches = {
45925diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
45926index 62f8030..c7f2a45 100644
45927--- a/drivers/platform/x86/msi-laptop.c
45928+++ b/drivers/platform/x86/msi-laptop.c
45929@@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
45930
45931 if (!quirks->ec_read_only) {
45932 /* allow userland write sysfs file */
45933- dev_attr_bluetooth.store = store_bluetooth;
45934- dev_attr_wlan.store = store_wlan;
45935- dev_attr_threeg.store = store_threeg;
45936- dev_attr_bluetooth.attr.mode |= S_IWUSR;
45937- dev_attr_wlan.attr.mode |= S_IWUSR;
45938- dev_attr_threeg.attr.mode |= S_IWUSR;
45939+ pax_open_kernel();
45940+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
45941+ *(void **)&dev_attr_wlan.store = store_wlan;
45942+ *(void **)&dev_attr_threeg.store = store_threeg;
45943+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
45944+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
45945+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
45946+ pax_close_kernel();
45947 }
45948
45949 /* disable hardware control by fn key */
45950diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
45951index 3a1b6bf..b453930 100644
45952--- a/drivers/platform/x86/sony-laptop.c
45953+++ b/drivers/platform/x86/sony-laptop.c
45954@@ -2486,7 +2486,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
45955 }
45956
45957 /* High speed charging function */
45958-static struct device_attribute *hsc_handle;
45959+static device_attribute_no_const *hsc_handle;
45960
45961 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
45962 struct device_attribute *attr,
45963diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
45964index 54d31c0..3f896d3 100644
45965--- a/drivers/platform/x86/thinkpad_acpi.c
45966+++ b/drivers/platform/x86/thinkpad_acpi.c
45967@@ -2093,7 +2093,7 @@ static int hotkey_mask_get(void)
45968 return 0;
45969 }
45970
45971-void static hotkey_mask_warn_incomplete_mask(void)
45972+static void hotkey_mask_warn_incomplete_mask(void)
45973 {
45974 /* log only what the user can fix... */
45975 const u32 wantedmask = hotkey_driver_mask &
45976@@ -2324,11 +2324,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
45977 }
45978 }
45979
45980-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45981- struct tp_nvram_state *newn,
45982- const u32 event_mask)
45983-{
45984-
45985 #define TPACPI_COMPARE_KEY(__scancode, __member) \
45986 do { \
45987 if ((event_mask & (1 << __scancode)) && \
45988@@ -2342,36 +2337,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
45989 tpacpi_hotkey_send_key(__scancode); \
45990 } while (0)
45991
45992- void issue_volchange(const unsigned int oldvol,
45993- const unsigned int newvol)
45994- {
45995- unsigned int i = oldvol;
45996+static void issue_volchange(const unsigned int oldvol,
45997+ const unsigned int newvol,
45998+ const u32 event_mask)
45999+{
46000+ unsigned int i = oldvol;
46001
46002- while (i > newvol) {
46003- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
46004- i--;
46005- }
46006- while (i < newvol) {
46007- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
46008- i++;
46009- }
46010+ while (i > newvol) {
46011+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
46012+ i--;
46013 }
46014+ while (i < newvol) {
46015+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
46016+ i++;
46017+ }
46018+}
46019
46020- void issue_brightnesschange(const unsigned int oldbrt,
46021- const unsigned int newbrt)
46022- {
46023- unsigned int i = oldbrt;
46024+static void issue_brightnesschange(const unsigned int oldbrt,
46025+ const unsigned int newbrt,
46026+ const u32 event_mask)
46027+{
46028+ unsigned int i = oldbrt;
46029
46030- while (i > newbrt) {
46031- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
46032- i--;
46033- }
46034- while (i < newbrt) {
46035- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
46036- i++;
46037- }
46038+ while (i > newbrt) {
46039+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
46040+ i--;
46041+ }
46042+ while (i < newbrt) {
46043+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
46044+ i++;
46045 }
46046+}
46047
46048+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
46049+ struct tp_nvram_state *newn,
46050+ const u32 event_mask)
46051+{
46052 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
46053 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
46054 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
46055@@ -2405,7 +2406,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
46056 oldn->volume_level != newn->volume_level) {
46057 /* recently muted, or repeated mute keypress, or
46058 * multiple presses ending in mute */
46059- issue_volchange(oldn->volume_level, newn->volume_level);
46060+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
46061 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
46062 }
46063 } else {
46064@@ -2415,7 +2416,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
46065 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
46066 }
46067 if (oldn->volume_level != newn->volume_level) {
46068- issue_volchange(oldn->volume_level, newn->volume_level);
46069+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
46070 } else if (oldn->volume_toggle != newn->volume_toggle) {
46071 /* repeated vol up/down keypress at end of scale ? */
46072 if (newn->volume_level == 0)
46073@@ -2428,7 +2429,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
46074 /* handle brightness */
46075 if (oldn->brightness_level != newn->brightness_level) {
46076 issue_brightnesschange(oldn->brightness_level,
46077- newn->brightness_level);
46078+ newn->brightness_level,
46079+ event_mask);
46080 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
46081 /* repeated key presses that didn't change state */
46082 if (newn->brightness_level == 0)
46083@@ -2437,10 +2439,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
46084 && !tp_features.bright_unkfw)
46085 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
46086 }
46087+}
46088
46089 #undef TPACPI_COMPARE_KEY
46090 #undef TPACPI_MAY_SEND_KEY
46091-}
46092
46093 /*
46094 * Polling driver
46095diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
46096index 769d265..a3a05ca 100644
46097--- a/drivers/pnp/pnpbios/bioscalls.c
46098+++ b/drivers/pnp/pnpbios/bioscalls.c
46099@@ -58,7 +58,7 @@ do { \
46100 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
46101 } while(0)
46102
46103-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
46104+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
46105 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
46106
46107 /*
46108@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
46109
46110 cpu = get_cpu();
46111 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
46112+
46113+ pax_open_kernel();
46114 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
46115+ pax_close_kernel();
46116
46117 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
46118 spin_lock_irqsave(&pnp_bios_lock, flags);
46119@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
46120 :"memory");
46121 spin_unlock_irqrestore(&pnp_bios_lock, flags);
46122
46123+ pax_open_kernel();
46124 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
46125+ pax_close_kernel();
46126+
46127 put_cpu();
46128
46129 /* If we get here and this is set then the PnP BIOS faulted on us. */
46130@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
46131 return status;
46132 }
46133
46134-void pnpbios_calls_init(union pnp_bios_install_struct *header)
46135+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
46136 {
46137 int i;
46138
46139@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
46140 pnp_bios_callpoint.offset = header->fields.pm16offset;
46141 pnp_bios_callpoint.segment = PNP_CS16;
46142
46143+ pax_open_kernel();
46144+
46145 for_each_possible_cpu(i) {
46146 struct desc_struct *gdt = get_cpu_gdt_table(i);
46147 if (!gdt)
46148@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
46149 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
46150 (unsigned long)__va(header->fields.pm16dseg));
46151 }
46152+
46153+ pax_close_kernel();
46154 }
46155diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
46156index d95e101..67f0c3f 100644
46157--- a/drivers/pnp/resource.c
46158+++ b/drivers/pnp/resource.c
46159@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
46160 return 1;
46161
46162 /* check if the resource is valid */
46163- if (*irq < 0 || *irq > 15)
46164+ if (*irq > 15)
46165 return 0;
46166
46167 /* check if the resource is reserved */
46168@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
46169 return 1;
46170
46171 /* check if the resource is valid */
46172- if (*dma < 0 || *dma == 4 || *dma > 7)
46173+ if (*dma == 4 || *dma > 7)
46174 return 0;
46175
46176 /* check if the resource is reserved */
46177diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
46178index 0c52e2a..3421ab7 100644
46179--- a/drivers/power/pda_power.c
46180+++ b/drivers/power/pda_power.c
46181@@ -37,7 +37,11 @@ static int polling;
46182
46183 #if IS_ENABLED(CONFIG_USB_PHY)
46184 static struct usb_phy *transceiver;
46185-static struct notifier_block otg_nb;
46186+static int otg_handle_notification(struct notifier_block *nb,
46187+ unsigned long event, void *unused);
46188+static struct notifier_block otg_nb = {
46189+ .notifier_call = otg_handle_notification
46190+};
46191 #endif
46192
46193 static struct regulator *ac_draw;
46194@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
46195
46196 #if IS_ENABLED(CONFIG_USB_PHY)
46197 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
46198- otg_nb.notifier_call = otg_handle_notification;
46199 ret = usb_register_notifier(transceiver, &otg_nb);
46200 if (ret) {
46201 dev_err(dev, "failure to register otg notifier\n");
46202diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
46203index cc439fd..8fa30df 100644
46204--- a/drivers/power/power_supply.h
46205+++ b/drivers/power/power_supply.h
46206@@ -16,12 +16,12 @@ struct power_supply;
46207
46208 #ifdef CONFIG_SYSFS
46209
46210-extern void power_supply_init_attrs(struct device_type *dev_type);
46211+extern void power_supply_init_attrs(void);
46212 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
46213
46214 #else
46215
46216-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
46217+static inline void power_supply_init_attrs(void) {}
46218 #define power_supply_uevent NULL
46219
46220 #endif /* CONFIG_SYSFS */
46221diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
46222index 3b2d5df..3207114 100644
46223--- a/drivers/power/power_supply_core.c
46224+++ b/drivers/power/power_supply_core.c
46225@@ -24,7 +24,10 @@
46226 struct class *power_supply_class;
46227 EXPORT_SYMBOL_GPL(power_supply_class);
46228
46229-static struct device_type power_supply_dev_type;
46230+extern const struct attribute_group *power_supply_attr_groups[];
46231+static struct device_type power_supply_dev_type = {
46232+ .groups = power_supply_attr_groups,
46233+};
46234
46235 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
46236 struct power_supply *supply)
46237@@ -558,7 +561,7 @@ static int __init power_supply_class_init(void)
46238 return PTR_ERR(power_supply_class);
46239
46240 power_supply_class->dev_uevent = power_supply_uevent;
46241- power_supply_init_attrs(&power_supply_dev_type);
46242+ power_supply_init_attrs();
46243
46244 return 0;
46245 }
46246diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
46247index 29178f7..c65f324 100644
46248--- a/drivers/power/power_supply_sysfs.c
46249+++ b/drivers/power/power_supply_sysfs.c
46250@@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
46251 .is_visible = power_supply_attr_is_visible,
46252 };
46253
46254-static const struct attribute_group *power_supply_attr_groups[] = {
46255+const struct attribute_group *power_supply_attr_groups[] = {
46256 &power_supply_attr_group,
46257 NULL,
46258 };
46259
46260-void power_supply_init_attrs(struct device_type *dev_type)
46261+void power_supply_init_attrs(void)
46262 {
46263 int i;
46264
46265- dev_type->groups = power_supply_attr_groups;
46266-
46267 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
46268 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
46269 }
46270diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
46271index 288c75a..065bc84 100644
46272--- a/drivers/regulator/core.c
46273+++ b/drivers/regulator/core.c
46274@@ -3544,7 +3544,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
46275 {
46276 const struct regulation_constraints *constraints = NULL;
46277 const struct regulator_init_data *init_data;
46278- static atomic_t regulator_no = ATOMIC_INIT(0);
46279+ static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
46280 struct regulator_dev *rdev;
46281 struct device *dev;
46282 int ret, i;
46283@@ -3614,7 +3614,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
46284 rdev->dev.of_node = config->of_node;
46285 rdev->dev.parent = dev;
46286 dev_set_name(&rdev->dev, "regulator.%d",
46287- atomic_inc_return(&regulator_no) - 1);
46288+ atomic_inc_return_unchecked(&regulator_no) - 1);
46289 ret = device_register(&rdev->dev);
46290 if (ret != 0) {
46291 put_device(&rdev->dev);
46292diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
46293index d428ef9..fdc0357 100644
46294--- a/drivers/regulator/max8660.c
46295+++ b/drivers/regulator/max8660.c
46296@@ -333,8 +333,10 @@ static int max8660_probe(struct i2c_client *client,
46297 max8660->shadow_regs[MAX8660_OVER1] = 5;
46298 } else {
46299 /* Otherwise devices can be toggled via software */
46300- max8660_dcdc_ops.enable = max8660_dcdc_enable;
46301- max8660_dcdc_ops.disable = max8660_dcdc_disable;
46302+ pax_open_kernel();
46303+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
46304+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
46305+ pax_close_kernel();
46306 }
46307
46308 /*
46309diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
46310index 0c5195a..637a453d 100644
46311--- a/drivers/regulator/max8973-regulator.c
46312+++ b/drivers/regulator/max8973-regulator.c
46313@@ -406,9 +406,11 @@ static int max8973_probe(struct i2c_client *client,
46314 if (!pdata || !pdata->enable_ext_control) {
46315 max->desc.enable_reg = MAX8973_VOUT;
46316 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
46317- max->ops.enable = regulator_enable_regmap;
46318- max->ops.disable = regulator_disable_regmap;
46319- max->ops.is_enabled = regulator_is_enabled_regmap;
46320+ pax_open_kernel();
46321+ *(void **)&max->ops.enable = regulator_enable_regmap;
46322+ *(void **)&max->ops.disable = regulator_disable_regmap;
46323+ *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
46324+ pax_close_kernel();
46325 }
46326
46327 if (pdata) {
46328diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
46329index 1037e07..e64dea1 100644
46330--- a/drivers/regulator/mc13892-regulator.c
46331+++ b/drivers/regulator/mc13892-regulator.c
46332@@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
46333 }
46334 mc13xxx_unlock(mc13892);
46335
46336- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
46337+ pax_open_kernel();
46338+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
46339 = mc13892_vcam_set_mode;
46340- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
46341+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
46342 = mc13892_vcam_get_mode;
46343+ pax_close_kernel();
46344
46345 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
46346 ARRAY_SIZE(mc13892_regulators));
46347diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
46348index be06d71..264aee9 100644
46349--- a/drivers/rtc/rtc-cmos.c
46350+++ b/drivers/rtc/rtc-cmos.c
46351@@ -731,7 +731,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
46352 hpet_rtc_timer_init();
46353
46354 /* export at least the first block of NVRAM */
46355- nvram.size = address_space - NVRAM_OFFSET;
46356+ pax_open_kernel();
46357+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
46358+ pax_close_kernel();
46359 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
46360 if (retval < 0) {
46361 dev_dbg(dev, "can't create nvram file? %d\n", retval);
46362diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
46363index d049393..bb20be0 100644
46364--- a/drivers/rtc/rtc-dev.c
46365+++ b/drivers/rtc/rtc-dev.c
46366@@ -16,6 +16,7 @@
46367 #include <linux/module.h>
46368 #include <linux/rtc.h>
46369 #include <linux/sched.h>
46370+#include <linux/grsecurity.h>
46371 #include "rtc-core.h"
46372
46373 static dev_t rtc_devt;
46374@@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
46375 if (copy_from_user(&tm, uarg, sizeof(tm)))
46376 return -EFAULT;
46377
46378+ gr_log_timechange();
46379+
46380 return rtc_set_time(rtc, &tm);
46381
46382 case RTC_PIE_ON:
46383diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
46384index ca18fd1..055e42d 100644
46385--- a/drivers/rtc/rtc-ds1307.c
46386+++ b/drivers/rtc/rtc-ds1307.c
46387@@ -107,7 +107,7 @@ struct ds1307 {
46388 u8 offset; /* register's offset */
46389 u8 regs[11];
46390 u16 nvram_offset;
46391- struct bin_attribute *nvram;
46392+ bin_attribute_no_const *nvram;
46393 enum ds_type type;
46394 unsigned long flags;
46395 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
46396diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
46397index fcb0329..d77b7f2 100644
46398--- a/drivers/rtc/rtc-m48t59.c
46399+++ b/drivers/rtc/rtc-m48t59.c
46400@@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
46401 if (IS_ERR(m48t59->rtc))
46402 return PTR_ERR(m48t59->rtc);
46403
46404- m48t59_nvram_attr.size = pdata->offset;
46405+ pax_open_kernel();
46406+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
46407+ pax_close_kernel();
46408
46409 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
46410 if (ret)
46411diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
46412index e693af6..2e525b6 100644
46413--- a/drivers/scsi/bfa/bfa_fcpim.h
46414+++ b/drivers/scsi/bfa/bfa_fcpim.h
46415@@ -36,7 +36,7 @@ struct bfa_iotag_s {
46416
46417 struct bfa_itn_s {
46418 bfa_isr_func_t isr;
46419-};
46420+} __no_const;
46421
46422 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
46423 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
46424diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
46425index 90814fe..4384138 100644
46426--- a/drivers/scsi/bfa/bfa_ioc.h
46427+++ b/drivers/scsi/bfa/bfa_ioc.h
46428@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
46429 bfa_ioc_disable_cbfn_t disable_cbfn;
46430 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
46431 bfa_ioc_reset_cbfn_t reset_cbfn;
46432-};
46433+} __no_const;
46434
46435 /*
46436 * IOC event notification mechanism.
46437@@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
46438 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
46439 enum bfi_ioc_state fwstate);
46440 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
46441-};
46442+} __no_const;
46443
46444 /*
46445 * Queue element to wait for room in request queue. FIFO order is
46446diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
46447index c9382d6..6619864 100644
46448--- a/drivers/scsi/fcoe/fcoe_sysfs.c
46449+++ b/drivers/scsi/fcoe/fcoe_sysfs.c
46450@@ -33,8 +33,8 @@
46451 */
46452 #include "libfcoe.h"
46453
46454-static atomic_t ctlr_num;
46455-static atomic_t fcf_num;
46456+static atomic_unchecked_t ctlr_num;
46457+static atomic_unchecked_t fcf_num;
46458
46459 /*
46460 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
46461@@ -681,7 +681,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
46462 if (!ctlr)
46463 goto out;
46464
46465- ctlr->id = atomic_inc_return(&ctlr_num) - 1;
46466+ ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
46467 ctlr->f = f;
46468 ctlr->mode = FIP_CONN_TYPE_FABRIC;
46469 INIT_LIST_HEAD(&ctlr->fcfs);
46470@@ -898,7 +898,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
46471 fcf->dev.parent = &ctlr->dev;
46472 fcf->dev.bus = &fcoe_bus_type;
46473 fcf->dev.type = &fcoe_fcf_device_type;
46474- fcf->id = atomic_inc_return(&fcf_num) - 1;
46475+ fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
46476 fcf->state = FCOE_FCF_STATE_UNKNOWN;
46477
46478 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
46479@@ -934,8 +934,8 @@ int __init fcoe_sysfs_setup(void)
46480 {
46481 int error;
46482
46483- atomic_set(&ctlr_num, 0);
46484- atomic_set(&fcf_num, 0);
46485+ atomic_set_unchecked(&ctlr_num, 0);
46486+ atomic_set_unchecked(&fcf_num, 0);
46487
46488 error = bus_register(&fcoe_bus_type);
46489 if (error)
46490diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
46491index df0c3c7..b00e1d0 100644
46492--- a/drivers/scsi/hosts.c
46493+++ b/drivers/scsi/hosts.c
46494@@ -42,7 +42,7 @@
46495 #include "scsi_logging.h"
46496
46497
46498-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
46499+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
46500
46501
46502 static void scsi_host_cls_release(struct device *dev)
46503@@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
46504 * subtract one because we increment first then return, but we need to
46505 * know what the next host number was before increment
46506 */
46507- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
46508+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
46509 shost->dma_channel = 0xff;
46510
46511 /* These three are default values which can be overridden */
46512diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
46513index 7f4f790..b75b92a 100644
46514--- a/drivers/scsi/hpsa.c
46515+++ b/drivers/scsi/hpsa.c
46516@@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
46517 unsigned long flags;
46518
46519 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
46520- return h->access.command_completed(h, q);
46521+ return h->access->command_completed(h, q);
46522
46523 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
46524 a = rq->head[rq->current_entry];
46525@@ -3422,7 +3422,7 @@ static void start_io(struct ctlr_info *h)
46526 while (!list_empty(&h->reqQ)) {
46527 c = list_entry(h->reqQ.next, struct CommandList, list);
46528 /* can't do anything if fifo is full */
46529- if ((h->access.fifo_full(h))) {
46530+ if ((h->access->fifo_full(h))) {
46531 dev_warn(&h->pdev->dev, "fifo full\n");
46532 break;
46533 }
46534@@ -3444,7 +3444,7 @@ static void start_io(struct ctlr_info *h)
46535
46536 /* Tell the controller execute command */
46537 spin_unlock_irqrestore(&h->lock, flags);
46538- h->access.submit_command(h, c);
46539+ h->access->submit_command(h, c);
46540 spin_lock_irqsave(&h->lock, flags);
46541 }
46542 spin_unlock_irqrestore(&h->lock, flags);
46543@@ -3452,17 +3452,17 @@ static void start_io(struct ctlr_info *h)
46544
46545 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
46546 {
46547- return h->access.command_completed(h, q);
46548+ return h->access->command_completed(h, q);
46549 }
46550
46551 static inline bool interrupt_pending(struct ctlr_info *h)
46552 {
46553- return h->access.intr_pending(h);
46554+ return h->access->intr_pending(h);
46555 }
46556
46557 static inline long interrupt_not_for_us(struct ctlr_info *h)
46558 {
46559- return (h->access.intr_pending(h) == 0) ||
46560+ return (h->access->intr_pending(h) == 0) ||
46561 (h->interrupts_enabled == 0);
46562 }
46563
46564@@ -4364,7 +4364,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
46565 if (prod_index < 0)
46566 return -ENODEV;
46567 h->product_name = products[prod_index].product_name;
46568- h->access = *(products[prod_index].access);
46569+ h->access = products[prod_index].access;
46570
46571 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
46572 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
46573@@ -4646,7 +4646,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
46574
46575 assert_spin_locked(&lockup_detector_lock);
46576 remove_ctlr_from_lockup_detector_list(h);
46577- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46578+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46579 spin_lock_irqsave(&h->lock, flags);
46580 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
46581 spin_unlock_irqrestore(&h->lock, flags);
46582@@ -4823,7 +4823,7 @@ reinit_after_soft_reset:
46583 }
46584
46585 /* make sure the board interrupts are off */
46586- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46587+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46588
46589 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
46590 goto clean2;
46591@@ -4857,7 +4857,7 @@ reinit_after_soft_reset:
46592 * fake ones to scoop up any residual completions.
46593 */
46594 spin_lock_irqsave(&h->lock, flags);
46595- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46596+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46597 spin_unlock_irqrestore(&h->lock, flags);
46598 free_irqs(h);
46599 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
46600@@ -4876,9 +4876,9 @@ reinit_after_soft_reset:
46601 dev_info(&h->pdev->dev, "Board READY.\n");
46602 dev_info(&h->pdev->dev,
46603 "Waiting for stale completions to drain.\n");
46604- h->access.set_intr_mask(h, HPSA_INTR_ON);
46605+ h->access->set_intr_mask(h, HPSA_INTR_ON);
46606 msleep(10000);
46607- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46608+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46609
46610 rc = controller_reset_failed(h->cfgtable);
46611 if (rc)
46612@@ -4899,7 +4899,7 @@ reinit_after_soft_reset:
46613 }
46614
46615 /* Turn the interrupts on so we can service requests */
46616- h->access.set_intr_mask(h, HPSA_INTR_ON);
46617+ h->access->set_intr_mask(h, HPSA_INTR_ON);
46618
46619 hpsa_hba_inquiry(h);
46620 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
46621@@ -4954,7 +4954,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
46622 * To write all data in the battery backed cache to disks
46623 */
46624 hpsa_flush_cache(h);
46625- h->access.set_intr_mask(h, HPSA_INTR_OFF);
46626+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
46627 hpsa_free_irqs_and_disable_msix(h);
46628 }
46629
46630@@ -5122,7 +5122,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
46631 return;
46632 }
46633 /* Change the access methods to the performant access methods */
46634- h->access = SA5_performant_access;
46635+ h->access = &SA5_performant_access;
46636 h->transMethod = CFGTBL_Trans_Performant;
46637 }
46638
46639diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
46640index 9816479..c5d4e97 100644
46641--- a/drivers/scsi/hpsa.h
46642+++ b/drivers/scsi/hpsa.h
46643@@ -79,7 +79,7 @@ struct ctlr_info {
46644 unsigned int msix_vector;
46645 unsigned int msi_vector;
46646 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
46647- struct access_method access;
46648+ struct access_method *access;
46649
46650 /* queue and queue Info */
46651 struct list_head reqQ;
46652diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
46653index 5879929..32b241d 100644
46654--- a/drivers/scsi/libfc/fc_exch.c
46655+++ b/drivers/scsi/libfc/fc_exch.c
46656@@ -100,12 +100,12 @@ struct fc_exch_mgr {
46657 u16 pool_max_index;
46658
46659 struct {
46660- atomic_t no_free_exch;
46661- atomic_t no_free_exch_xid;
46662- atomic_t xid_not_found;
46663- atomic_t xid_busy;
46664- atomic_t seq_not_found;
46665- atomic_t non_bls_resp;
46666+ atomic_unchecked_t no_free_exch;
46667+ atomic_unchecked_t no_free_exch_xid;
46668+ atomic_unchecked_t xid_not_found;
46669+ atomic_unchecked_t xid_busy;
46670+ atomic_unchecked_t seq_not_found;
46671+ atomic_unchecked_t non_bls_resp;
46672 } stats;
46673 };
46674
46675@@ -736,7 +736,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
46676 /* allocate memory for exchange */
46677 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
46678 if (!ep) {
46679- atomic_inc(&mp->stats.no_free_exch);
46680+ atomic_inc_unchecked(&mp->stats.no_free_exch);
46681 goto out;
46682 }
46683 memset(ep, 0, sizeof(*ep));
46684@@ -797,7 +797,7 @@ out:
46685 return ep;
46686 err:
46687 spin_unlock_bh(&pool->lock);
46688- atomic_inc(&mp->stats.no_free_exch_xid);
46689+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
46690 mempool_free(ep, mp->ep_pool);
46691 return NULL;
46692 }
46693@@ -940,7 +940,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46694 xid = ntohs(fh->fh_ox_id); /* we originated exch */
46695 ep = fc_exch_find(mp, xid);
46696 if (!ep) {
46697- atomic_inc(&mp->stats.xid_not_found);
46698+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46699 reject = FC_RJT_OX_ID;
46700 goto out;
46701 }
46702@@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46703 ep = fc_exch_find(mp, xid);
46704 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
46705 if (ep) {
46706- atomic_inc(&mp->stats.xid_busy);
46707+ atomic_inc_unchecked(&mp->stats.xid_busy);
46708 reject = FC_RJT_RX_ID;
46709 goto rel;
46710 }
46711@@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46712 }
46713 xid = ep->xid; /* get our XID */
46714 } else if (!ep) {
46715- atomic_inc(&mp->stats.xid_not_found);
46716+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46717 reject = FC_RJT_RX_ID; /* XID not found */
46718 goto out;
46719 }
46720@@ -998,7 +998,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
46721 } else {
46722 sp = &ep->seq;
46723 if (sp->id != fh->fh_seq_id) {
46724- atomic_inc(&mp->stats.seq_not_found);
46725+ atomic_inc_unchecked(&mp->stats.seq_not_found);
46726 if (f_ctl & FC_FC_END_SEQ) {
46727 /*
46728 * Update sequence_id based on incoming last
46729@@ -1448,22 +1448,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
46730
46731 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
46732 if (!ep) {
46733- atomic_inc(&mp->stats.xid_not_found);
46734+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46735 goto out;
46736 }
46737 if (ep->esb_stat & ESB_ST_COMPLETE) {
46738- atomic_inc(&mp->stats.xid_not_found);
46739+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46740 goto rel;
46741 }
46742 if (ep->rxid == FC_XID_UNKNOWN)
46743 ep->rxid = ntohs(fh->fh_rx_id);
46744 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
46745- atomic_inc(&mp->stats.xid_not_found);
46746+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46747 goto rel;
46748 }
46749 if (ep->did != ntoh24(fh->fh_s_id) &&
46750 ep->did != FC_FID_FLOGI) {
46751- atomic_inc(&mp->stats.xid_not_found);
46752+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46753 goto rel;
46754 }
46755 sof = fr_sof(fp);
46756@@ -1472,7 +1472,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
46757 sp->ssb_stat |= SSB_ST_RESP;
46758 sp->id = fh->fh_seq_id;
46759 } else if (sp->id != fh->fh_seq_id) {
46760- atomic_inc(&mp->stats.seq_not_found);
46761+ atomic_inc_unchecked(&mp->stats.seq_not_found);
46762 goto rel;
46763 }
46764
46765@@ -1536,9 +1536,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
46766 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
46767
46768 if (!sp)
46769- atomic_inc(&mp->stats.xid_not_found);
46770+ atomic_inc_unchecked(&mp->stats.xid_not_found);
46771 else
46772- atomic_inc(&mp->stats.non_bls_resp);
46773+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
46774
46775 fc_frame_free(fp);
46776 }
46777@@ -2185,13 +2185,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
46778
46779 list_for_each_entry(ema, &lport->ema_list, ema_list) {
46780 mp = ema->mp;
46781- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
46782+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
46783 st->fc_no_free_exch_xid +=
46784- atomic_read(&mp->stats.no_free_exch_xid);
46785- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
46786- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
46787- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
46788- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
46789+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
46790+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
46791+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
46792+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
46793+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
46794 }
46795 }
46796 EXPORT_SYMBOL(fc_exch_update_stats);
46797diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
46798index 161c98e..6d563b3 100644
46799--- a/drivers/scsi/libsas/sas_ata.c
46800+++ b/drivers/scsi/libsas/sas_ata.c
46801@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
46802 .postreset = ata_std_postreset,
46803 .error_handler = ata_std_error_handler,
46804 .post_internal_cmd = sas_ata_post_internal,
46805- .qc_defer = ata_std_qc_defer,
46806+ .qc_defer = ata_std_qc_defer,
46807 .qc_prep = ata_noop_qc_prep,
46808 .qc_issue = sas_ata_qc_issue,
46809 .qc_fill_rtf = sas_ata_qc_fill_rtf,
46810diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
46811index 93f222d..73e977b 100644
46812--- a/drivers/scsi/lpfc/lpfc.h
46813+++ b/drivers/scsi/lpfc/lpfc.h
46814@@ -431,7 +431,7 @@ struct lpfc_vport {
46815 struct dentry *debug_nodelist;
46816 struct dentry *vport_debugfs_root;
46817 struct lpfc_debugfs_trc *disc_trc;
46818- atomic_t disc_trc_cnt;
46819+ atomic_unchecked_t disc_trc_cnt;
46820 #endif
46821 uint8_t stat_data_enabled;
46822 uint8_t stat_data_blocked;
46823@@ -865,8 +865,8 @@ struct lpfc_hba {
46824 struct timer_list fabric_block_timer;
46825 unsigned long bit_flags;
46826 #define FABRIC_COMANDS_BLOCKED 0
46827- atomic_t num_rsrc_err;
46828- atomic_t num_cmd_success;
46829+ atomic_unchecked_t num_rsrc_err;
46830+ atomic_unchecked_t num_cmd_success;
46831 unsigned long last_rsrc_error_time;
46832 unsigned long last_ramp_down_time;
46833 unsigned long last_ramp_up_time;
46834@@ -902,7 +902,7 @@ struct lpfc_hba {
46835
46836 struct dentry *debug_slow_ring_trc;
46837 struct lpfc_debugfs_trc *slow_ring_trc;
46838- atomic_t slow_ring_trc_cnt;
46839+ atomic_unchecked_t slow_ring_trc_cnt;
46840 /* iDiag debugfs sub-directory */
46841 struct dentry *idiag_root;
46842 struct dentry *idiag_pci_cfg;
46843diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
46844index 60084e6..0e2e700 100644
46845--- a/drivers/scsi/lpfc/lpfc_debugfs.c
46846+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
46847@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
46848
46849 #include <linux/debugfs.h>
46850
46851-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
46852+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
46853 static unsigned long lpfc_debugfs_start_time = 0L;
46854
46855 /* iDiag */
46856@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
46857 lpfc_debugfs_enable = 0;
46858
46859 len = 0;
46860- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
46861+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
46862 (lpfc_debugfs_max_disc_trc - 1);
46863 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
46864 dtp = vport->disc_trc + i;
46865@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
46866 lpfc_debugfs_enable = 0;
46867
46868 len = 0;
46869- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
46870+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
46871 (lpfc_debugfs_max_slow_ring_trc - 1);
46872 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
46873 dtp = phba->slow_ring_trc + i;
46874@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
46875 !vport || !vport->disc_trc)
46876 return;
46877
46878- index = atomic_inc_return(&vport->disc_trc_cnt) &
46879+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
46880 (lpfc_debugfs_max_disc_trc - 1);
46881 dtp = vport->disc_trc + index;
46882 dtp->fmt = fmt;
46883 dtp->data1 = data1;
46884 dtp->data2 = data2;
46885 dtp->data3 = data3;
46886- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
46887+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
46888 dtp->jif = jiffies;
46889 #endif
46890 return;
46891@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
46892 !phba || !phba->slow_ring_trc)
46893 return;
46894
46895- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
46896+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
46897 (lpfc_debugfs_max_slow_ring_trc - 1);
46898 dtp = phba->slow_ring_trc + index;
46899 dtp->fmt = fmt;
46900 dtp->data1 = data1;
46901 dtp->data2 = data2;
46902 dtp->data3 = data3;
46903- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
46904+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
46905 dtp->jif = jiffies;
46906 #endif
46907 return;
46908@@ -4168,7 +4168,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
46909 "slow_ring buffer\n");
46910 goto debug_failed;
46911 }
46912- atomic_set(&phba->slow_ring_trc_cnt, 0);
46913+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
46914 memset(phba->slow_ring_trc, 0,
46915 (sizeof(struct lpfc_debugfs_trc) *
46916 lpfc_debugfs_max_slow_ring_trc));
46917@@ -4214,7 +4214,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
46918 "buffer\n");
46919 goto debug_failed;
46920 }
46921- atomic_set(&vport->disc_trc_cnt, 0);
46922+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
46923
46924 snprintf(name, sizeof(name), "discovery_trace");
46925 vport->debug_disc_trc =
46926diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
46927index e0b20fa..30c2c0d 100644
46928--- a/drivers/scsi/lpfc/lpfc_init.c
46929+++ b/drivers/scsi/lpfc/lpfc_init.c
46930@@ -10936,8 +10936,10 @@ lpfc_init(void)
46931 "misc_register returned with status %d", error);
46932
46933 if (lpfc_enable_npiv) {
46934- lpfc_transport_functions.vport_create = lpfc_vport_create;
46935- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
46936+ pax_open_kernel();
46937+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
46938+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
46939+ pax_close_kernel();
46940 }
46941 lpfc_transport_template =
46942 fc_attach_transport(&lpfc_transport_functions);
46943diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
46944index 243de1d..f40e3e5 100644
46945--- a/drivers/scsi/lpfc/lpfc_scsi.c
46946+++ b/drivers/scsi/lpfc/lpfc_scsi.c
46947@@ -353,7 +353,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
46948 uint32_t evt_posted;
46949
46950 spin_lock_irqsave(&phba->hbalock, flags);
46951- atomic_inc(&phba->num_rsrc_err);
46952+ atomic_inc_unchecked(&phba->num_rsrc_err);
46953 phba->last_rsrc_error_time = jiffies;
46954
46955 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
46956@@ -394,7 +394,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
46957 unsigned long flags;
46958 struct lpfc_hba *phba = vport->phba;
46959 uint32_t evt_posted;
46960- atomic_inc(&phba->num_cmd_success);
46961+ atomic_inc_unchecked(&phba->num_cmd_success);
46962
46963 if (vport->cfg_lun_queue_depth <= queue_depth)
46964 return;
46965@@ -438,8 +438,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
46966 unsigned long num_rsrc_err, num_cmd_success;
46967 int i;
46968
46969- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
46970- num_cmd_success = atomic_read(&phba->num_cmd_success);
46971+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
46972+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
46973
46974 /*
46975 * The error and success command counters are global per
46976@@ -467,8 +467,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
46977 }
46978 }
46979 lpfc_destroy_vport_work_array(phba, vports);
46980- atomic_set(&phba->num_rsrc_err, 0);
46981- atomic_set(&phba->num_cmd_success, 0);
46982+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
46983+ atomic_set_unchecked(&phba->num_cmd_success, 0);
46984 }
46985
46986 /**
46987@@ -502,8 +502,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
46988 }
46989 }
46990 lpfc_destroy_vport_work_array(phba, vports);
46991- atomic_set(&phba->num_rsrc_err, 0);
46992- atomic_set(&phba->num_cmd_success, 0);
46993+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
46994+ atomic_set_unchecked(&phba->num_cmd_success, 0);
46995 }
46996
46997 /**
46998diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
46999index 1eb7b028..b2a6080 100644
47000--- a/drivers/scsi/pmcraid.c
47001+++ b/drivers/scsi/pmcraid.c
47002@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
47003 res->scsi_dev = scsi_dev;
47004 scsi_dev->hostdata = res;
47005 res->change_detected = 0;
47006- atomic_set(&res->read_failures, 0);
47007- atomic_set(&res->write_failures, 0);
47008+ atomic_set_unchecked(&res->read_failures, 0);
47009+ atomic_set_unchecked(&res->write_failures, 0);
47010 rc = 0;
47011 }
47012 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
47013@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
47014
47015 /* If this was a SCSI read/write command keep count of errors */
47016 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
47017- atomic_inc(&res->read_failures);
47018+ atomic_inc_unchecked(&res->read_failures);
47019 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
47020- atomic_inc(&res->write_failures);
47021+ atomic_inc_unchecked(&res->write_failures);
47022
47023 if (!RES_IS_GSCSI(res->cfg_entry) &&
47024 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
47025@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
47026 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
47027 * hrrq_id assigned here in queuecommand
47028 */
47029- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
47030+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
47031 pinstance->num_hrrq;
47032 cmd->cmd_done = pmcraid_io_done;
47033
47034@@ -3846,7 +3846,7 @@ static long pmcraid_ioctl_passthrough(
47035 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
47036 * hrrq_id assigned here in queuecommand
47037 */
47038- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
47039+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
47040 pinstance->num_hrrq;
47041
47042 if (request_size) {
47043@@ -4483,7 +4483,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
47044
47045 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
47046 /* add resources only after host is added into system */
47047- if (!atomic_read(&pinstance->expose_resources))
47048+ if (!atomic_read_unchecked(&pinstance->expose_resources))
47049 return;
47050
47051 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
47052@@ -5310,8 +5310,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
47053 init_waitqueue_head(&pinstance->reset_wait_q);
47054
47055 atomic_set(&pinstance->outstanding_cmds, 0);
47056- atomic_set(&pinstance->last_message_id, 0);
47057- atomic_set(&pinstance->expose_resources, 0);
47058+ atomic_set_unchecked(&pinstance->last_message_id, 0);
47059+ atomic_set_unchecked(&pinstance->expose_resources, 0);
47060
47061 INIT_LIST_HEAD(&pinstance->free_res_q);
47062 INIT_LIST_HEAD(&pinstance->used_res_q);
47063@@ -6024,7 +6024,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
47064 /* Schedule worker thread to handle CCN and take care of adding and
47065 * removing devices to OS
47066 */
47067- atomic_set(&pinstance->expose_resources, 1);
47068+ atomic_set_unchecked(&pinstance->expose_resources, 1);
47069 schedule_work(&pinstance->worker_q);
47070 return rc;
47071
47072diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
47073index e1d150f..6c6df44 100644
47074--- a/drivers/scsi/pmcraid.h
47075+++ b/drivers/scsi/pmcraid.h
47076@@ -748,7 +748,7 @@ struct pmcraid_instance {
47077 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
47078
47079 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
47080- atomic_t last_message_id;
47081+ atomic_unchecked_t last_message_id;
47082
47083 /* configuration table */
47084 struct pmcraid_config_table *cfg_table;
47085@@ -777,7 +777,7 @@ struct pmcraid_instance {
47086 atomic_t outstanding_cmds;
47087
47088 /* should add/delete resources to mid-layer now ?*/
47089- atomic_t expose_resources;
47090+ atomic_unchecked_t expose_resources;
47091
47092
47093
47094@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
47095 struct pmcraid_config_table_entry_ext cfg_entry_ext;
47096 };
47097 struct scsi_device *scsi_dev; /* Link scsi_device structure */
47098- atomic_t read_failures; /* count of failed READ commands */
47099- atomic_t write_failures; /* count of failed WRITE commands */
47100+ atomic_unchecked_t read_failures; /* count of failed READ commands */
47101+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
47102
47103 /* To indicate add/delete/modify during CCN */
47104 u8 change_detected;
47105diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
47106index d7a99ae..801df70 100644
47107--- a/drivers/scsi/qla2xxx/qla_attr.c
47108+++ b/drivers/scsi/qla2xxx/qla_attr.c
47109@@ -2004,7 +2004,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
47110 return 0;
47111 }
47112
47113-struct fc_function_template qla2xxx_transport_functions = {
47114+fc_function_template_no_const qla2xxx_transport_functions = {
47115
47116 .show_host_node_name = 1,
47117 .show_host_port_name = 1,
47118@@ -2051,7 +2051,7 @@ struct fc_function_template qla2xxx_transport_functions = {
47119 .bsg_timeout = qla24xx_bsg_timeout,
47120 };
47121
47122-struct fc_function_template qla2xxx_transport_vport_functions = {
47123+fc_function_template_no_const qla2xxx_transport_vport_functions = {
47124
47125 .show_host_node_name = 1,
47126 .show_host_port_name = 1,
47127diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
47128index 2d98232..a84298e 100644
47129--- a/drivers/scsi/qla2xxx/qla_gbl.h
47130+++ b/drivers/scsi/qla2xxx/qla_gbl.h
47131@@ -528,8 +528,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
47132 struct device_attribute;
47133 extern struct device_attribute *qla2x00_host_attrs[];
47134 struct fc_function_template;
47135-extern struct fc_function_template qla2xxx_transport_functions;
47136-extern struct fc_function_template qla2xxx_transport_vport_functions;
47137+extern fc_function_template_no_const qla2xxx_transport_functions;
47138+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
47139 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
47140 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
47141 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
47142diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
47143index 3e21e9f..426ba79 100644
47144--- a/drivers/scsi/qla2xxx/qla_os.c
47145+++ b/drivers/scsi/qla2xxx/qla_os.c
47146@@ -1570,8 +1570,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
47147 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
47148 /* Ok, a 64bit DMA mask is applicable. */
47149 ha->flags.enable_64bit_addressing = 1;
47150- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
47151- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
47152+ pax_open_kernel();
47153+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
47154+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
47155+ pax_close_kernel();
47156 return;
47157 }
47158 }
47159diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
47160index ddf16a8..80f4dd0 100644
47161--- a/drivers/scsi/qla4xxx/ql4_def.h
47162+++ b/drivers/scsi/qla4xxx/ql4_def.h
47163@@ -291,7 +291,7 @@ struct ddb_entry {
47164 * (4000 only) */
47165 atomic_t relogin_timer; /* Max Time to wait for
47166 * relogin to complete */
47167- atomic_t relogin_retry_count; /* Num of times relogin has been
47168+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
47169 * retried */
47170 uint32_t default_time2wait; /* Default Min time between
47171 * relogins (+aens) */
47172diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
47173index b246b3c..897004d 100644
47174--- a/drivers/scsi/qla4xxx/ql4_os.c
47175+++ b/drivers/scsi/qla4xxx/ql4_os.c
47176@@ -2971,12 +2971,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
47177 */
47178 if (!iscsi_is_session_online(cls_sess)) {
47179 /* Reset retry relogin timer */
47180- atomic_inc(&ddb_entry->relogin_retry_count);
47181+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
47182 DEBUG2(ql4_printk(KERN_INFO, ha,
47183 "%s: index[%d] relogin timed out-retrying"
47184 " relogin (%d), retry (%d)\n", __func__,
47185 ddb_entry->fw_ddb_index,
47186- atomic_read(&ddb_entry->relogin_retry_count),
47187+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
47188 ddb_entry->default_time2wait + 4));
47189 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
47190 atomic_set(&ddb_entry->retry_relogin_timer,
47191@@ -5081,7 +5081,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
47192
47193 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
47194 atomic_set(&ddb_entry->relogin_timer, 0);
47195- atomic_set(&ddb_entry->relogin_retry_count, 0);
47196+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
47197 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
47198 ddb_entry->default_relogin_timeout =
47199 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
47200diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
47201index eaa808e..95f8841 100644
47202--- a/drivers/scsi/scsi.c
47203+++ b/drivers/scsi/scsi.c
47204@@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
47205 unsigned long timeout;
47206 int rtn = 0;
47207
47208- atomic_inc(&cmd->device->iorequest_cnt);
47209+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
47210
47211 /* check if the device is still usable */
47212 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
47213diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
47214index 124392f..75eb43e 100644
47215--- a/drivers/scsi/scsi_lib.c
47216+++ b/drivers/scsi/scsi_lib.c
47217@@ -1474,7 +1474,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
47218 shost = sdev->host;
47219 scsi_init_cmd_errh(cmd);
47220 cmd->result = DID_NO_CONNECT << 16;
47221- atomic_inc(&cmd->device->iorequest_cnt);
47222+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
47223
47224 /*
47225 * SCSI request completion path will do scsi_device_unbusy(),
47226@@ -1500,9 +1500,9 @@ static void scsi_softirq_done(struct request *rq)
47227
47228 INIT_LIST_HEAD(&cmd->eh_entry);
47229
47230- atomic_inc(&cmd->device->iodone_cnt);
47231+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
47232 if (cmd->result)
47233- atomic_inc(&cmd->device->ioerr_cnt);
47234+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
47235
47236 disposition = scsi_decide_disposition(cmd);
47237 if (disposition != SUCCESS &&
47238diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
47239index 7e50061..71db7a6 100644
47240--- a/drivers/scsi/scsi_sysfs.c
47241+++ b/drivers/scsi/scsi_sysfs.c
47242@@ -687,7 +687,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
47243 char *buf) \
47244 { \
47245 struct scsi_device *sdev = to_scsi_device(dev); \
47246- unsigned long long count = atomic_read(&sdev->field); \
47247+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
47248 return snprintf(buf, 20, "0x%llx\n", count); \
47249 } \
47250 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
47251diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
47252index 84a1fdf..693b0d6 100644
47253--- a/drivers/scsi/scsi_tgt_lib.c
47254+++ b/drivers/scsi/scsi_tgt_lib.c
47255@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
47256 int err;
47257
47258 dprintk("%lx %u\n", uaddr, len);
47259- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
47260+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
47261 if (err) {
47262 /*
47263 * TODO: need to fixup sg_tablesize, max_segment_size,
47264diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
47265index 4628fd5..a94a1c2 100644
47266--- a/drivers/scsi/scsi_transport_fc.c
47267+++ b/drivers/scsi/scsi_transport_fc.c
47268@@ -497,7 +497,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
47269 * Netlink Infrastructure
47270 */
47271
47272-static atomic_t fc_event_seq;
47273+static atomic_unchecked_t fc_event_seq;
47274
47275 /**
47276 * fc_get_event_number - Obtain the next sequential FC event number
47277@@ -510,7 +510,7 @@ static atomic_t fc_event_seq;
47278 u32
47279 fc_get_event_number(void)
47280 {
47281- return atomic_add_return(1, &fc_event_seq);
47282+ return atomic_add_return_unchecked(1, &fc_event_seq);
47283 }
47284 EXPORT_SYMBOL(fc_get_event_number);
47285
47286@@ -654,7 +654,7 @@ static __init int fc_transport_init(void)
47287 {
47288 int error;
47289
47290- atomic_set(&fc_event_seq, 0);
47291+ atomic_set_unchecked(&fc_event_seq, 0);
47292
47293 error = transport_class_register(&fc_host_class);
47294 if (error)
47295@@ -844,7 +844,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
47296 char *cp;
47297
47298 *val = simple_strtoul(buf, &cp, 0);
47299- if ((*cp && (*cp != '\n')) || (*val < 0))
47300+ if (*cp && (*cp != '\n'))
47301 return -EINVAL;
47302 /*
47303 * Check for overflow; dev_loss_tmo is u32
47304diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
47305index abf7c40..c3240ed 100644
47306--- a/drivers/scsi/scsi_transport_iscsi.c
47307+++ b/drivers/scsi/scsi_transport_iscsi.c
47308@@ -80,7 +80,7 @@ struct iscsi_internal {
47309 struct transport_container session_cont;
47310 };
47311
47312-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
47313+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
47314 static struct workqueue_struct *iscsi_eh_timer_workq;
47315
47316 static DEFINE_IDA(iscsi_sess_ida);
47317@@ -1738,7 +1738,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
47318 int err;
47319
47320 ihost = shost->shost_data;
47321- session->sid = atomic_add_return(1, &iscsi_session_nr);
47322+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
47323
47324 if (target_id == ISCSI_MAX_TARGET) {
47325 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
47326@@ -3956,7 +3956,7 @@ static __init int iscsi_transport_init(void)
47327 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
47328 ISCSI_TRANSPORT_VERSION);
47329
47330- atomic_set(&iscsi_session_nr, 0);
47331+ atomic_set_unchecked(&iscsi_session_nr, 0);
47332
47333 err = class_register(&iscsi_transport_class);
47334 if (err)
47335diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
47336index f379c7f..e8fc69c 100644
47337--- a/drivers/scsi/scsi_transport_srp.c
47338+++ b/drivers/scsi/scsi_transport_srp.c
47339@@ -33,7 +33,7 @@
47340 #include "scsi_transport_srp_internal.h"
47341
47342 struct srp_host_attrs {
47343- atomic_t next_port_id;
47344+ atomic_unchecked_t next_port_id;
47345 };
47346 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
47347
47348@@ -61,7 +61,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
47349 struct Scsi_Host *shost = dev_to_shost(dev);
47350 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
47351
47352- atomic_set(&srp_host->next_port_id, 0);
47353+ atomic_set_unchecked(&srp_host->next_port_id, 0);
47354 return 0;
47355 }
47356
47357@@ -210,7 +210,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
47358 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
47359 rport->roles = ids->roles;
47360
47361- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
47362+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
47363 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
47364
47365 transport_setup_device(&rport->dev);
47366diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
47367index 86fcf2c..26d8594 100644
47368--- a/drivers/scsi/sd.c
47369+++ b/drivers/scsi/sd.c
47370@@ -2938,7 +2938,7 @@ static int sd_probe(struct device *dev)
47371 sdkp->disk = gd;
47372 sdkp->index = index;
47373 atomic_set(&sdkp->openers, 0);
47374- atomic_set(&sdkp->device->ioerr_cnt, 0);
47375+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
47376
47377 if (!sdp->request_queue->rq_timeout) {
47378 if (sdp->type != TYPE_MOD)
47379diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
47380index df5e961..df6b97f 100644
47381--- a/drivers/scsi/sg.c
47382+++ b/drivers/scsi/sg.c
47383@@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
47384 sdp->disk->disk_name,
47385 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
47386 NULL,
47387- (char *)arg);
47388+ (char __user *)arg);
47389 case BLKTRACESTART:
47390 return blk_trace_startstop(sdp->device->request_queue, 1);
47391 case BLKTRACESTOP:
47392diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
47393index 978dda2..cb19aa0 100644
47394--- a/drivers/spi/spi.c
47395+++ b/drivers/spi/spi.c
47396@@ -1631,7 +1631,7 @@ int spi_bus_unlock(struct spi_master *master)
47397 EXPORT_SYMBOL_GPL(spi_bus_unlock);
47398
47399 /* portable code must never pass more than 32 bytes */
47400-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
47401+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
47402
47403 static u8 *buf;
47404
47405diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
47406index ee3a57f..18368c1 100644
47407--- a/drivers/staging/android/timed_output.c
47408+++ b/drivers/staging/android/timed_output.c
47409@@ -25,7 +25,7 @@
47410 #include "timed_output.h"
47411
47412 static struct class *timed_output_class;
47413-static atomic_t device_count;
47414+static atomic_unchecked_t device_count;
47415
47416 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
47417 char *buf)
47418@@ -59,7 +59,7 @@ static int create_timed_output_class(void)
47419 timed_output_class = class_create(THIS_MODULE, "timed_output");
47420 if (IS_ERR(timed_output_class))
47421 return PTR_ERR(timed_output_class);
47422- atomic_set(&device_count, 0);
47423+ atomic_set_unchecked(&device_count, 0);
47424 }
47425
47426 return 0;
47427@@ -76,7 +76,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
47428 if (ret < 0)
47429 return ret;
47430
47431- tdev->index = atomic_inc_return(&device_count);
47432+ tdev->index = atomic_inc_return_unchecked(&device_count);
47433 tdev->dev = device_create(timed_output_class, NULL,
47434 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
47435 if (IS_ERR(tdev->dev))
47436diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
47437index 3675020..e80d92c 100644
47438--- a/drivers/staging/media/solo6x10/solo6x10-core.c
47439+++ b/drivers/staging/media/solo6x10/solo6x10-core.c
47440@@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
47441
47442 static int solo_sysfs_init(struct solo_dev *solo_dev)
47443 {
47444- struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
47445+ bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
47446 struct device *dev = &solo_dev->dev;
47447 const char *driver;
47448 int i;
47449diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
47450index 3335941..2b26186 100644
47451--- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
47452+++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
47453@@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
47454
47455 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
47456 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
47457- p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
47458+ p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
47459 if (p2m_id < 0)
47460 p2m_id = -p2m_id;
47461 }
47462diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
47463index 6f91d2e..3f011d2 100644
47464--- a/drivers/staging/media/solo6x10/solo6x10.h
47465+++ b/drivers/staging/media/solo6x10/solo6x10.h
47466@@ -238,7 +238,7 @@ struct solo_dev {
47467
47468 /* P2M DMA Engine */
47469 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
47470- atomic_t p2m_count;
47471+ atomic_unchecked_t p2m_count;
47472 int p2m_jiffies;
47473 unsigned int p2m_timeouts;
47474
47475diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
47476index 34afc16..ffe44dd 100644
47477--- a/drivers/staging/octeon/ethernet-rx.c
47478+++ b/drivers/staging/octeon/ethernet-rx.c
47479@@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
47480 /* Increment RX stats for virtual ports */
47481 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
47482 #ifdef CONFIG_64BIT
47483- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
47484- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
47485+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
47486+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
47487 #else
47488- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
47489- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
47490+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
47491+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
47492 #endif
47493 }
47494 netif_receive_skb(skb);
47495@@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
47496 dev->name);
47497 */
47498 #ifdef CONFIG_64BIT
47499- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
47500+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
47501 #else
47502- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
47503+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
47504 #endif
47505 dev_kfree_skb_irq(skb);
47506 }
47507diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
47508index c3a90e7..023619a 100644
47509--- a/drivers/staging/octeon/ethernet.c
47510+++ b/drivers/staging/octeon/ethernet.c
47511@@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
47512 * since the RX tasklet also increments it.
47513 */
47514 #ifdef CONFIG_64BIT
47515- atomic64_add(rx_status.dropped_packets,
47516- (atomic64_t *)&priv->stats.rx_dropped);
47517+ atomic64_add_unchecked(rx_status.dropped_packets,
47518+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
47519 #else
47520- atomic_add(rx_status.dropped_packets,
47521- (atomic_t *)&priv->stats.rx_dropped);
47522+ atomic_add_unchecked(rx_status.dropped_packets,
47523+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
47524 #endif
47525 }
47526
47527diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
47528index dc23395..cf7e9b1 100644
47529--- a/drivers/staging/rtl8712/rtl871x_io.h
47530+++ b/drivers/staging/rtl8712/rtl871x_io.h
47531@@ -108,7 +108,7 @@ struct _io_ops {
47532 u8 *pmem);
47533 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
47534 u8 *pmem);
47535-};
47536+} __no_const;
47537
47538 struct io_req {
47539 struct list_head list;
47540diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
47541index 1f5088b..0e59820 100644
47542--- a/drivers/staging/sbe-2t3e3/netdev.c
47543+++ b/drivers/staging/sbe-2t3e3/netdev.c
47544@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
47545 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
47546
47547 if (rlen)
47548- if (copy_to_user(data, &resp, rlen))
47549+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
47550 return -EFAULT;
47551
47552 return 0;
47553diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
47554index a863a98..d272795 100644
47555--- a/drivers/staging/usbip/vhci.h
47556+++ b/drivers/staging/usbip/vhci.h
47557@@ -83,7 +83,7 @@ struct vhci_hcd {
47558 unsigned resuming:1;
47559 unsigned long re_timeout;
47560
47561- atomic_t seqnum;
47562+ atomic_unchecked_t seqnum;
47563
47564 /*
47565 * NOTE:
47566diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
47567index d7974cb..d78076b 100644
47568--- a/drivers/staging/usbip/vhci_hcd.c
47569+++ b/drivers/staging/usbip/vhci_hcd.c
47570@@ -441,7 +441,7 @@ static void vhci_tx_urb(struct urb *urb)
47571
47572 spin_lock(&vdev->priv_lock);
47573
47574- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
47575+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
47576 if (priv->seqnum == 0xffff)
47577 dev_info(&urb->dev->dev, "seqnum max\n");
47578
47579@@ -687,7 +687,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
47580 return -ENOMEM;
47581 }
47582
47583- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
47584+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
47585 if (unlink->seqnum == 0xffff)
47586 pr_info("seqnum max\n");
47587
47588@@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
47589 vdev->rhport = rhport;
47590 }
47591
47592- atomic_set(&vhci->seqnum, 0);
47593+ atomic_set_unchecked(&vhci->seqnum, 0);
47594 spin_lock_init(&vhci->lock);
47595
47596 hcd->power_budget = 0; /* no limit */
47597diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
47598index d07fcb5..358e1e1 100644
47599--- a/drivers/staging/usbip/vhci_rx.c
47600+++ b/drivers/staging/usbip/vhci_rx.c
47601@@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
47602 if (!urb) {
47603 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
47604 pr_info("max seqnum %d\n",
47605- atomic_read(&the_controller->seqnum));
47606+ atomic_read_unchecked(&the_controller->seqnum));
47607 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
47608 return;
47609 }
47610diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
47611index 57a08c5..5b4bb7c 100644
47612--- a/drivers/staging/vt6655/hostap.c
47613+++ b/drivers/staging/vt6655/hostap.c
47614@@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
47615 *
47616 */
47617
47618+static net_device_ops_no_const apdev_netdev_ops;
47619+
47620 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
47621 {
47622 PSDevice apdev_priv;
47623 struct net_device *dev = pDevice->dev;
47624 int ret;
47625- const struct net_device_ops apdev_netdev_ops = {
47626- .ndo_start_xmit = pDevice->tx_80211,
47627- };
47628
47629 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
47630
47631@@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
47632 *apdev_priv = *pDevice;
47633 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
47634
47635+ /* only half broken now */
47636+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
47637 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
47638
47639 pDevice->apdev->type = ARPHRD_IEEE80211;
47640diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
47641index c699a30..b90a5fd 100644
47642--- a/drivers/staging/vt6656/hostap.c
47643+++ b/drivers/staging/vt6656/hostap.c
47644@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
47645 *
47646 */
47647
47648+static net_device_ops_no_const apdev_netdev_ops;
47649+
47650 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
47651 {
47652 struct vnt_private *apdev_priv;
47653 struct net_device *dev = pDevice->dev;
47654 int ret;
47655- const struct net_device_ops apdev_netdev_ops = {
47656- .ndo_start_xmit = pDevice->tx_80211,
47657- };
47658
47659 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
47660
47661@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
47662 *apdev_priv = *pDevice;
47663 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
47664
47665+ /* only half broken now */
47666+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
47667 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
47668
47669 pDevice->apdev->type = ARPHRD_IEEE80211;
47670diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
47671index d128ce2..fc1f9a1 100644
47672--- a/drivers/staging/zcache/tmem.h
47673+++ b/drivers/staging/zcache/tmem.h
47674@@ -225,7 +225,7 @@ struct tmem_pamops {
47675 bool (*is_remote)(void *);
47676 int (*replace_in_obj)(void *, struct tmem_obj *);
47677 #endif
47678-};
47679+} __no_const;
47680 extern void tmem_register_pamops(struct tmem_pamops *m);
47681
47682 /* memory allocation methods provided by the host implementation */
47683@@ -234,7 +234,7 @@ struct tmem_hostops {
47684 void (*obj_free)(struct tmem_obj *, struct tmem_pool *);
47685 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
47686 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
47687-};
47688+} __no_const;
47689 extern void tmem_register_hostops(struct tmem_hostops *m);
47690
47691 /* core tmem accessor functions */
47692diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
47693index e51b09a..5ebac31 100644
47694--- a/drivers/target/sbp/sbp_target.c
47695+++ b/drivers/target/sbp/sbp_target.c
47696@@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
47697
47698 #define SESSION_MAINTENANCE_INTERVAL HZ
47699
47700-static atomic_t login_id = ATOMIC_INIT(0);
47701+static atomic_unchecked_t login_id = ATOMIC_INIT(0);
47702
47703 static void session_maintenance_work(struct work_struct *);
47704 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
47705@@ -444,7 +444,7 @@ static void sbp_management_request_login(
47706 login->lun = se_lun;
47707 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
47708 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
47709- login->login_id = atomic_inc_return(&login_id);
47710+ login->login_id = atomic_inc_return_unchecked(&login_id);
47711
47712 login->tgt_agt = sbp_target_agent_register(login);
47713 if (IS_ERR(login->tgt_agt)) {
47714diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
47715index 8f4142f..b127f7d 100644
47716--- a/drivers/target/target_core_device.c
47717+++ b/drivers/target/target_core_device.c
47718@@ -1400,7 +1400,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
47719 spin_lock_init(&dev->se_port_lock);
47720 spin_lock_init(&dev->se_tmr_lock);
47721 spin_lock_init(&dev->qf_cmd_lock);
47722- atomic_set(&dev->dev_ordered_id, 0);
47723+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
47724 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
47725 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
47726 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
47727diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
47728index d8e49d7..6fcfdec 100644
47729--- a/drivers/target/target_core_transport.c
47730+++ b/drivers/target/target_core_transport.c
47731@@ -1080,7 +1080,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
47732 * Used to determine when ORDERED commands should go from
47733 * Dormant to Active status.
47734 */
47735- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
47736+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
47737 smp_mb__after_atomic_inc();
47738 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
47739 cmd->se_ordered_id, cmd->sam_task_attr,
47740diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
47741index 33f83fe..d80f8e1 100644
47742--- a/drivers/tty/cyclades.c
47743+++ b/drivers/tty/cyclades.c
47744@@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
47745 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
47746 info->port.count);
47747 #endif
47748- info->port.count++;
47749+ atomic_inc(&info->port.count);
47750 #ifdef CY_DEBUG_COUNT
47751 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
47752- current->pid, info->port.count);
47753+ current->pid, atomic_read(&info->port.count));
47754 #endif
47755
47756 /*
47757@@ -3972,7 +3972,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
47758 for (j = 0; j < cy_card[i].nports; j++) {
47759 info = &cy_card[i].ports[j];
47760
47761- if (info->port.count) {
47762+ if (atomic_read(&info->port.count)) {
47763 /* XXX is the ldisc num worth this? */
47764 struct tty_struct *tty;
47765 struct tty_ldisc *ld;
47766diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
47767index eb255e8..f637a57 100644
47768--- a/drivers/tty/hvc/hvc_console.c
47769+++ b/drivers/tty/hvc/hvc_console.c
47770@@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
47771
47772 spin_lock_irqsave(&hp->port.lock, flags);
47773 /* Check and then increment for fast path open. */
47774- if (hp->port.count++ > 0) {
47775+ if (atomic_inc_return(&hp->port.count) > 1) {
47776 spin_unlock_irqrestore(&hp->port.lock, flags);
47777 hvc_kick();
47778 return 0;
47779@@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
47780
47781 spin_lock_irqsave(&hp->port.lock, flags);
47782
47783- if (--hp->port.count == 0) {
47784+ if (atomic_dec_return(&hp->port.count) == 0) {
47785 spin_unlock_irqrestore(&hp->port.lock, flags);
47786 /* We are done with the tty pointer now. */
47787 tty_port_tty_set(&hp->port, NULL);
47788@@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
47789 */
47790 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
47791 } else {
47792- if (hp->port.count < 0)
47793+ if (atomic_read(&hp->port.count) < 0)
47794 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
47795- hp->vtermno, hp->port.count);
47796+ hp->vtermno, atomic_read(&hp->port.count));
47797 spin_unlock_irqrestore(&hp->port.lock, flags);
47798 }
47799 }
47800@@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
47801 * open->hangup case this can be called after the final close so prevent
47802 * that from happening for now.
47803 */
47804- if (hp->port.count <= 0) {
47805+ if (atomic_read(&hp->port.count) <= 0) {
47806 spin_unlock_irqrestore(&hp->port.lock, flags);
47807 return;
47808 }
47809
47810- hp->port.count = 0;
47811+ atomic_set(&hp->port.count, 0);
47812 spin_unlock_irqrestore(&hp->port.lock, flags);
47813 tty_port_tty_set(&hp->port, NULL);
47814
47815@@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
47816 return -EPIPE;
47817
47818 /* FIXME what's this (unprotected) check for? */
47819- if (hp->port.count <= 0)
47820+ if (atomic_read(&hp->port.count) <= 0)
47821 return -EIO;
47822
47823 spin_lock_irqsave(&hp->lock, flags);
47824diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
47825index 81e939e..95ead10 100644
47826--- a/drivers/tty/hvc/hvcs.c
47827+++ b/drivers/tty/hvc/hvcs.c
47828@@ -83,6 +83,7 @@
47829 #include <asm/hvcserver.h>
47830 #include <asm/uaccess.h>
47831 #include <asm/vio.h>
47832+#include <asm/local.h>
47833
47834 /*
47835 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
47836@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
47837
47838 spin_lock_irqsave(&hvcsd->lock, flags);
47839
47840- if (hvcsd->port.count > 0) {
47841+ if (atomic_read(&hvcsd->port.count) > 0) {
47842 spin_unlock_irqrestore(&hvcsd->lock, flags);
47843 printk(KERN_INFO "HVCS: vterm state unchanged. "
47844 "The hvcs device node is still in use.\n");
47845@@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
47846 }
47847 }
47848
47849- hvcsd->port.count = 0;
47850+ atomic_set(&hvcsd->port.count, 0);
47851 hvcsd->port.tty = tty;
47852 tty->driver_data = hvcsd;
47853
47854@@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
47855 unsigned long flags;
47856
47857 spin_lock_irqsave(&hvcsd->lock, flags);
47858- hvcsd->port.count++;
47859+ atomic_inc(&hvcsd->port.count);
47860 hvcsd->todo_mask |= HVCS_SCHED_READ;
47861 spin_unlock_irqrestore(&hvcsd->lock, flags);
47862
47863@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
47864 hvcsd = tty->driver_data;
47865
47866 spin_lock_irqsave(&hvcsd->lock, flags);
47867- if (--hvcsd->port.count == 0) {
47868+ if (atomic_dec_and_test(&hvcsd->port.count)) {
47869
47870 vio_disable_interrupts(hvcsd->vdev);
47871
47872@@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
47873
47874 free_irq(irq, hvcsd);
47875 return;
47876- } else if (hvcsd->port.count < 0) {
47877+ } else if (atomic_read(&hvcsd->port.count) < 0) {
47878 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
47879 " is missmanaged.\n",
47880- hvcsd->vdev->unit_address, hvcsd->port.count);
47881+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
47882 }
47883
47884 spin_unlock_irqrestore(&hvcsd->lock, flags);
47885@@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
47886
47887 spin_lock_irqsave(&hvcsd->lock, flags);
47888 /* Preserve this so that we know how many kref refs to put */
47889- temp_open_count = hvcsd->port.count;
47890+ temp_open_count = atomic_read(&hvcsd->port.count);
47891
47892 /*
47893 * Don't kref put inside the spinlock because the destruction
47894@@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
47895 tty->driver_data = NULL;
47896 hvcsd->port.tty = NULL;
47897
47898- hvcsd->port.count = 0;
47899+ atomic_set(&hvcsd->port.count, 0);
47900
47901 /* This will drop any buffered data on the floor which is OK in a hangup
47902 * scenario. */
47903@@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
47904 * the middle of a write operation? This is a crummy place to do this
47905 * but we want to keep it all in the spinlock.
47906 */
47907- if (hvcsd->port.count <= 0) {
47908+ if (atomic_read(&hvcsd->port.count) <= 0) {
47909 spin_unlock_irqrestore(&hvcsd->lock, flags);
47910 return -ENODEV;
47911 }
47912@@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
47913 {
47914 struct hvcs_struct *hvcsd = tty->driver_data;
47915
47916- if (!hvcsd || hvcsd->port.count <= 0)
47917+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
47918 return 0;
47919
47920 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
47921diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
47922index 4190199..48f2920 100644
47923--- a/drivers/tty/hvc/hvsi.c
47924+++ b/drivers/tty/hvc/hvsi.c
47925@@ -85,7 +85,7 @@ struct hvsi_struct {
47926 int n_outbuf;
47927 uint32_t vtermno;
47928 uint32_t virq;
47929- atomic_t seqno; /* HVSI packet sequence number */
47930+ atomic_unchecked_t seqno; /* HVSI packet sequence number */
47931 uint16_t mctrl;
47932 uint8_t state; /* HVSI protocol state */
47933 uint8_t flags;
47934@@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
47935
47936 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
47937 packet.hdr.len = sizeof(struct hvsi_query_response);
47938- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47939+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47940 packet.verb = VSV_SEND_VERSION_NUMBER;
47941 packet.u.version = HVSI_VERSION;
47942 packet.query_seqno = query_seqno+1;
47943@@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
47944
47945 packet.hdr.type = VS_QUERY_PACKET_HEADER;
47946 packet.hdr.len = sizeof(struct hvsi_query);
47947- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47948+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47949 packet.verb = verb;
47950
47951 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
47952@@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
47953 int wrote;
47954
47955 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
47956- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47957+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47958 packet.hdr.len = sizeof(struct hvsi_control);
47959 packet.verb = VSV_SET_MODEM_CTL;
47960 packet.mask = HVSI_TSDTR;
47961@@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
47962 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
47963
47964 packet.hdr.type = VS_DATA_PACKET_HEADER;
47965- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47966+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47967 packet.hdr.len = count + sizeof(struct hvsi_header);
47968 memcpy(&packet.data, buf, count);
47969
47970@@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
47971 struct hvsi_control packet __ALIGNED__;
47972
47973 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
47974- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
47975+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
47976 packet.hdr.len = 6;
47977 packet.verb = VSV_CLOSE_PROTOCOL;
47978
47979diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
47980index ac27671..0f627ee 100644
47981--- a/drivers/tty/hvc/hvsi_lib.c
47982+++ b/drivers/tty/hvc/hvsi_lib.c
47983@@ -9,7 +9,7 @@
47984
47985 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
47986 {
47987- packet->seqno = atomic_inc_return(&pv->seqno);
47988+ packet->seqno = atomic_inc_return_unchecked(&pv->seqno);
47989
47990 /* Assumes that always succeeds, works in practice */
47991 return pv->put_chars(pv->termno, (char *)packet, packet->len);
47992@@ -21,7 +21,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
47993
47994 /* Reset state */
47995 pv->established = 0;
47996- atomic_set(&pv->seqno, 0);
47997+ atomic_set_unchecked(&pv->seqno, 0);
47998
47999 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
48000
48001@@ -265,7 +265,7 @@ int hvsilib_read_mctrl(struct hvsi_priv *pv)
48002 pv->mctrl_update = 0;
48003 q.hdr.type = VS_QUERY_PACKET_HEADER;
48004 q.hdr.len = sizeof(struct hvsi_query);
48005- q.hdr.seqno = atomic_inc_return(&pv->seqno);
48006+ q.hdr.seqno = atomic_inc_return_unchecked(&pv->seqno);
48007 q.verb = VSV_SEND_MODEM_CTL_STATUS;
48008 rc = hvsi_send_packet(pv, &q.hdr);
48009 if (rc <= 0) {
48010diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
48011index 8fd72ff..34a0bed 100644
48012--- a/drivers/tty/ipwireless/tty.c
48013+++ b/drivers/tty/ipwireless/tty.c
48014@@ -29,6 +29,7 @@
48015 #include <linux/tty_driver.h>
48016 #include <linux/tty_flip.h>
48017 #include <linux/uaccess.h>
48018+#include <asm/local.h>
48019
48020 #include "tty.h"
48021 #include "network.h"
48022@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
48023 mutex_unlock(&tty->ipw_tty_mutex);
48024 return -ENODEV;
48025 }
48026- if (tty->port.count == 0)
48027+ if (atomic_read(&tty->port.count) == 0)
48028 tty->tx_bytes_queued = 0;
48029
48030- tty->port.count++;
48031+ atomic_inc(&tty->port.count);
48032
48033 tty->port.tty = linux_tty;
48034 linux_tty->driver_data = tty;
48035@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
48036
48037 static void do_ipw_close(struct ipw_tty *tty)
48038 {
48039- tty->port.count--;
48040-
48041- if (tty->port.count == 0) {
48042+ if (atomic_dec_return(&tty->port.count) == 0) {
48043 struct tty_struct *linux_tty = tty->port.tty;
48044
48045 if (linux_tty != NULL) {
48046@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
48047 return;
48048
48049 mutex_lock(&tty->ipw_tty_mutex);
48050- if (tty->port.count == 0) {
48051+ if (atomic_read(&tty->port.count) == 0) {
48052 mutex_unlock(&tty->ipw_tty_mutex);
48053 return;
48054 }
48055@@ -164,7 +163,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
48056
48057 mutex_lock(&tty->ipw_tty_mutex);
48058
48059- if (!tty->port.count) {
48060+ if (!atomic_read(&tty->port.count)) {
48061 mutex_unlock(&tty->ipw_tty_mutex);
48062 return;
48063 }
48064@@ -206,7 +205,7 @@ static int ipw_write(struct tty_struct *linux_tty,
48065 return -ENODEV;
48066
48067 mutex_lock(&tty->ipw_tty_mutex);
48068- if (!tty->port.count) {
48069+ if (!atomic_read(&tty->port.count)) {
48070 mutex_unlock(&tty->ipw_tty_mutex);
48071 return -EINVAL;
48072 }
48073@@ -246,7 +245,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
48074 if (!tty)
48075 return -ENODEV;
48076
48077- if (!tty->port.count)
48078+ if (!atomic_read(&tty->port.count))
48079 return -EINVAL;
48080
48081 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
48082@@ -288,7 +287,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
48083 if (!tty)
48084 return 0;
48085
48086- if (!tty->port.count)
48087+ if (!atomic_read(&tty->port.count))
48088 return 0;
48089
48090 return tty->tx_bytes_queued;
48091@@ -369,7 +368,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
48092 if (!tty)
48093 return -ENODEV;
48094
48095- if (!tty->port.count)
48096+ if (!atomic_read(&tty->port.count))
48097 return -EINVAL;
48098
48099 return get_control_lines(tty);
48100@@ -385,7 +384,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
48101 if (!tty)
48102 return -ENODEV;
48103
48104- if (!tty->port.count)
48105+ if (!atomic_read(&tty->port.count))
48106 return -EINVAL;
48107
48108 return set_control_lines(tty, set, clear);
48109@@ -399,7 +398,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
48110 if (!tty)
48111 return -ENODEV;
48112
48113- if (!tty->port.count)
48114+ if (!atomic_read(&tty->port.count))
48115 return -EINVAL;
48116
48117 /* FIXME: Exactly how is the tty object locked here .. */
48118@@ -555,7 +554,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
48119 * are gone */
48120 mutex_lock(&ttyj->ipw_tty_mutex);
48121 }
48122- while (ttyj->port.count)
48123+ while (atomic_read(&ttyj->port.count))
48124 do_ipw_close(ttyj);
48125 ipwireless_disassociate_network_ttys(network,
48126 ttyj->channel_idx);
48127diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
48128index 1deaca4..c8582d4 100644
48129--- a/drivers/tty/moxa.c
48130+++ b/drivers/tty/moxa.c
48131@@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
48132 }
48133
48134 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
48135- ch->port.count++;
48136+ atomic_inc(&ch->port.count);
48137 tty->driver_data = ch;
48138 tty_port_tty_set(&ch->port, tty);
48139 mutex_lock(&ch->port.mutex);
48140diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
48141index 6422390..49003ac8 100644
48142--- a/drivers/tty/n_gsm.c
48143+++ b/drivers/tty/n_gsm.c
48144@@ -1632,7 +1632,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
48145 spin_lock_init(&dlci->lock);
48146 mutex_init(&dlci->mutex);
48147 dlci->fifo = &dlci->_fifo;
48148- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
48149+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
48150 kfree(dlci);
48151 return NULL;
48152 }
48153@@ -2932,7 +2932,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
48154 struct gsm_dlci *dlci = tty->driver_data;
48155 struct tty_port *port = &dlci->port;
48156
48157- port->count++;
48158+ atomic_inc(&port->count);
48159 dlci_get(dlci);
48160 dlci_get(dlci->gsm->dlci[0]);
48161 mux_get(dlci->gsm);
48162diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
48163index 4bf0fc0..433bd58 100644
48164--- a/drivers/tty/n_tty.c
48165+++ b/drivers/tty/n_tty.c
48166@@ -2217,6 +2217,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
48167 {
48168 *ops = tty_ldisc_N_TTY;
48169 ops->owner = NULL;
48170- ops->refcount = ops->flags = 0;
48171+ atomic_set(&ops->refcount, 0);
48172+ ops->flags = 0;
48173 }
48174 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
48175diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
48176index abfd990..5ab5da9 100644
48177--- a/drivers/tty/pty.c
48178+++ b/drivers/tty/pty.c
48179@@ -796,8 +796,10 @@ static void __init unix98_pty_init(void)
48180 panic("Couldn't register Unix98 pts driver");
48181
48182 /* Now create the /dev/ptmx special device */
48183+ pax_open_kernel();
48184 tty_default_fops(&ptmx_fops);
48185- ptmx_fops.open = ptmx_open;
48186+ *(void **)&ptmx_fops.open = ptmx_open;
48187+ pax_close_kernel();
48188
48189 cdev_init(&ptmx_cdev, &ptmx_fops);
48190 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
48191diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
48192index 354564e..fe50d9a 100644
48193--- a/drivers/tty/rocket.c
48194+++ b/drivers/tty/rocket.c
48195@@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
48196 tty->driver_data = info;
48197 tty_port_tty_set(port, tty);
48198
48199- if (port->count++ == 0) {
48200+ if (atomic_inc_return(&port->count) == 1) {
48201 atomic_inc(&rp_num_ports_open);
48202
48203 #ifdef ROCKET_DEBUG_OPEN
48204@@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
48205 #endif
48206 }
48207 #ifdef ROCKET_DEBUG_OPEN
48208- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
48209+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
48210 #endif
48211
48212 /*
48213@@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
48214 spin_unlock_irqrestore(&info->port.lock, flags);
48215 return;
48216 }
48217- if (info->port.count)
48218+ if (atomic_read(&info->port.count))
48219 atomic_dec(&rp_num_ports_open);
48220 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
48221 spin_unlock_irqrestore(&info->port.lock, flags);
48222diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
48223index e2520ab..034e20b 100644
48224--- a/drivers/tty/serial/ioc4_serial.c
48225+++ b/drivers/tty/serial/ioc4_serial.c
48226@@ -437,7 +437,7 @@ struct ioc4_soft {
48227 } is_intr_info[MAX_IOC4_INTR_ENTS];
48228
48229 /* Number of entries active in the above array */
48230- atomic_t is_num_intrs;
48231+ atomic_unchecked_t is_num_intrs;
48232 } is_intr_type[IOC4_NUM_INTR_TYPES];
48233
48234 /* is_ir_lock must be held while
48235@@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
48236 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
48237 || (type == IOC4_OTHER_INTR_TYPE)));
48238
48239- i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
48240+ i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
48241 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
48242
48243 /* Save off the lower level interrupt handler */
48244@@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
48245
48246 soft = arg;
48247 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
48248- num_intrs = (int)atomic_read(
48249+ num_intrs = (int)atomic_read_unchecked(
48250 &soft->is_intr_type[intr_type].is_num_intrs);
48251
48252 this_mir = this_ir = pending_intrs(soft, intr_type);
48253diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
48254index 1002054..dd644a8 100644
48255--- a/drivers/tty/serial/kgdboc.c
48256+++ b/drivers/tty/serial/kgdboc.c
48257@@ -24,8 +24,9 @@
48258 #define MAX_CONFIG_LEN 40
48259
48260 static struct kgdb_io kgdboc_io_ops;
48261+static struct kgdb_io kgdboc_io_ops_console;
48262
48263-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
48264+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
48265 static int configured = -1;
48266
48267 static char config[MAX_CONFIG_LEN];
48268@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
48269 kgdboc_unregister_kbd();
48270 if (configured == 1)
48271 kgdb_unregister_io_module(&kgdboc_io_ops);
48272+ else if (configured == 2)
48273+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
48274 }
48275
48276 static int configure_kgdboc(void)
48277@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
48278 int err;
48279 char *cptr = config;
48280 struct console *cons;
48281+ int is_console = 0;
48282
48283 err = kgdboc_option_setup(config);
48284 if (err || !strlen(config) || isspace(config[0]))
48285 goto noconfig;
48286
48287 err = -ENODEV;
48288- kgdboc_io_ops.is_console = 0;
48289 kgdb_tty_driver = NULL;
48290
48291 kgdboc_use_kms = 0;
48292@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
48293 int idx;
48294 if (cons->device && cons->device(cons, &idx) == p &&
48295 idx == tty_line) {
48296- kgdboc_io_ops.is_console = 1;
48297+ is_console = 1;
48298 break;
48299 }
48300 cons = cons->next;
48301@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
48302 kgdb_tty_line = tty_line;
48303
48304 do_register:
48305- err = kgdb_register_io_module(&kgdboc_io_ops);
48306+ if (is_console) {
48307+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
48308+ configured = 2;
48309+ } else {
48310+ err = kgdb_register_io_module(&kgdboc_io_ops);
48311+ configured = 1;
48312+ }
48313 if (err)
48314 goto noconfig;
48315
48316@@ -205,8 +214,6 @@ do_register:
48317 if (err)
48318 goto nmi_con_failed;
48319
48320- configured = 1;
48321-
48322 return 0;
48323
48324 nmi_con_failed:
48325@@ -223,7 +230,7 @@ noconfig:
48326 static int __init init_kgdboc(void)
48327 {
48328 /* Already configured? */
48329- if (configured == 1)
48330+ if (configured >= 1)
48331 return 0;
48332
48333 return configure_kgdboc();
48334@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
48335 if (config[len - 1] == '\n')
48336 config[len - 1] = '\0';
48337
48338- if (configured == 1)
48339+ if (configured >= 1)
48340 cleanup_kgdboc();
48341
48342 /* Go and configure with the new params. */
48343@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
48344 .post_exception = kgdboc_post_exp_handler,
48345 };
48346
48347+static struct kgdb_io kgdboc_io_ops_console = {
48348+ .name = "kgdboc",
48349+ .read_char = kgdboc_get_char,
48350+ .write_char = kgdboc_put_char,
48351+ .pre_exception = kgdboc_pre_exp_handler,
48352+ .post_exception = kgdboc_post_exp_handler,
48353+ .is_console = 1
48354+};
48355+
48356 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
48357 /* This is only available if kgdboc is a built in for early debugging */
48358 static int __init kgdboc_early_init(char *opt)
48359diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
48360index 2c6cfb3..048274e 100644
48361--- a/drivers/tty/serial/msm_serial.c
48362+++ b/drivers/tty/serial/msm_serial.c
48363@@ -857,7 +857,7 @@ static struct uart_driver msm_uart_driver = {
48364 .cons = MSM_CONSOLE,
48365 };
48366
48367-static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
48368+static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
48369
48370 static int __init msm_serial_probe(struct platform_device *pdev)
48371 {
48372@@ -867,7 +867,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
48373 int irq;
48374
48375 if (pdev->id == -1)
48376- pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
48377+ pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
48378
48379 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
48380 return -ENXIO;
48381diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
48382index 376079b..d8de7aa 100644
48383--- a/drivers/tty/serial/samsung.c
48384+++ b/drivers/tty/serial/samsung.c
48385@@ -453,11 +453,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
48386 }
48387 }
48388
48389+static int s3c64xx_serial_startup(struct uart_port *port);
48390 static int s3c24xx_serial_startup(struct uart_port *port)
48391 {
48392 struct s3c24xx_uart_port *ourport = to_ourport(port);
48393 int ret;
48394
48395+ /* Startup sequence is different for s3c64xx and higher SoC's */
48396+ if (s3c24xx_serial_has_interrupt_mask(port))
48397+ return s3c64xx_serial_startup(port);
48398+
48399 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
48400 port->mapbase, port->membase);
48401
48402@@ -1124,10 +1129,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
48403 /* setup info for port */
48404 port->dev = &platdev->dev;
48405
48406- /* Startup sequence is different for s3c64xx and higher SoC's */
48407- if (s3c24xx_serial_has_interrupt_mask(port))
48408- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
48409-
48410 port->uartclk = 1;
48411
48412 if (cfg->uart_flags & UPF_CONS_FLOW) {
48413diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
48414index 28cdd28..56f1d60 100644
48415--- a/drivers/tty/serial/serial_core.c
48416+++ b/drivers/tty/serial/serial_core.c
48417@@ -1448,7 +1448,7 @@ static void uart_hangup(struct tty_struct *tty)
48418 uart_flush_buffer(tty);
48419 uart_shutdown(tty, state);
48420 spin_lock_irqsave(&port->lock, flags);
48421- port->count = 0;
48422+ atomic_set(&port->count, 0);
48423 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
48424 spin_unlock_irqrestore(&port->lock, flags);
48425 tty_port_tty_set(port, NULL);
48426@@ -1544,7 +1544,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
48427 goto end;
48428 }
48429
48430- port->count++;
48431+ atomic_inc(&port->count);
48432 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
48433 retval = -ENXIO;
48434 goto err_dec_count;
48435@@ -1572,7 +1572,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
48436 /*
48437 * Make sure the device is in D0 state.
48438 */
48439- if (port->count == 1)
48440+ if (atomic_read(&port->count) == 1)
48441 uart_change_pm(state, UART_PM_STATE_ON);
48442
48443 /*
48444@@ -1590,7 +1590,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
48445 end:
48446 return retval;
48447 err_dec_count:
48448- port->count--;
48449+ atomic_inc(&port->count);
48450 mutex_unlock(&port->mutex);
48451 goto end;
48452 }
48453diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
48454index 8eaf1ab..85c030d 100644
48455--- a/drivers/tty/synclink.c
48456+++ b/drivers/tty/synclink.c
48457@@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
48458
48459 if (debug_level >= DEBUG_LEVEL_INFO)
48460 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
48461- __FILE__,__LINE__, info->device_name, info->port.count);
48462+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
48463
48464 if (tty_port_close_start(&info->port, tty, filp) == 0)
48465 goto cleanup;
48466@@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
48467 cleanup:
48468 if (debug_level >= DEBUG_LEVEL_INFO)
48469 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
48470- tty->driver->name, info->port.count);
48471+ tty->driver->name, atomic_read(&info->port.count));
48472
48473 } /* end of mgsl_close() */
48474
48475@@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
48476
48477 mgsl_flush_buffer(tty);
48478 shutdown(info);
48479-
48480- info->port.count = 0;
48481+
48482+ atomic_set(&info->port.count, 0);
48483 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
48484 info->port.tty = NULL;
48485
48486@@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
48487
48488 if (debug_level >= DEBUG_LEVEL_INFO)
48489 printk("%s(%d):block_til_ready before block on %s count=%d\n",
48490- __FILE__,__LINE__, tty->driver->name, port->count );
48491+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48492
48493 spin_lock_irqsave(&info->irq_spinlock, flags);
48494 if (!tty_hung_up_p(filp)) {
48495 extra_count = true;
48496- port->count--;
48497+ atomic_dec(&port->count);
48498 }
48499 spin_unlock_irqrestore(&info->irq_spinlock, flags);
48500 port->blocked_open++;
48501@@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
48502
48503 if (debug_level >= DEBUG_LEVEL_INFO)
48504 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
48505- __FILE__,__LINE__, tty->driver->name, port->count );
48506+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48507
48508 tty_unlock(tty);
48509 schedule();
48510@@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
48511
48512 /* FIXME: Racy on hangup during close wait */
48513 if (extra_count)
48514- port->count++;
48515+ atomic_inc(&port->count);
48516 port->blocked_open--;
48517
48518 if (debug_level >= DEBUG_LEVEL_INFO)
48519 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
48520- __FILE__,__LINE__, tty->driver->name, port->count );
48521+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48522
48523 if (!retval)
48524 port->flags |= ASYNC_NORMAL_ACTIVE;
48525@@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
48526
48527 if (debug_level >= DEBUG_LEVEL_INFO)
48528 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
48529- __FILE__,__LINE__,tty->driver->name, info->port.count);
48530+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
48531
48532 /* If port is closing, signal caller to try again */
48533 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
48534@@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
48535 spin_unlock_irqrestore(&info->netlock, flags);
48536 goto cleanup;
48537 }
48538- info->port.count++;
48539+ atomic_inc(&info->port.count);
48540 spin_unlock_irqrestore(&info->netlock, flags);
48541
48542- if (info->port.count == 1) {
48543+ if (atomic_read(&info->port.count) == 1) {
48544 /* 1st open on this device, init hardware */
48545 retval = startup(info);
48546 if (retval < 0)
48547@@ -3446,8 +3446,8 @@ cleanup:
48548 if (retval) {
48549 if (tty->count == 1)
48550 info->port.tty = NULL; /* tty layer will release tty struct */
48551- if(info->port.count)
48552- info->port.count--;
48553+ if (atomic_read(&info->port.count))
48554+ atomic_dec(&info->port.count);
48555 }
48556
48557 return retval;
48558@@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
48559 unsigned short new_crctype;
48560
48561 /* return error if TTY interface open */
48562- if (info->port.count)
48563+ if (atomic_read(&info->port.count))
48564 return -EBUSY;
48565
48566 switch (encoding)
48567@@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
48568
48569 /* arbitrate between network and tty opens */
48570 spin_lock_irqsave(&info->netlock, flags);
48571- if (info->port.count != 0 || info->netcount != 0) {
48572+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
48573 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
48574 spin_unlock_irqrestore(&info->netlock, flags);
48575 return -EBUSY;
48576@@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48577 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
48578
48579 /* return error if TTY interface open */
48580- if (info->port.count)
48581+ if (atomic_read(&info->port.count))
48582 return -EBUSY;
48583
48584 if (cmd != SIOCWANDEV)
48585diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
48586index 1abf946..1ee34fc 100644
48587--- a/drivers/tty/synclink_gt.c
48588+++ b/drivers/tty/synclink_gt.c
48589@@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
48590 tty->driver_data = info;
48591 info->port.tty = tty;
48592
48593- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
48594+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
48595
48596 /* If port is closing, signal caller to try again */
48597 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
48598@@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
48599 mutex_unlock(&info->port.mutex);
48600 goto cleanup;
48601 }
48602- info->port.count++;
48603+ atomic_inc(&info->port.count);
48604 spin_unlock_irqrestore(&info->netlock, flags);
48605
48606- if (info->port.count == 1) {
48607+ if (atomic_read(&info->port.count) == 1) {
48608 /* 1st open on this device, init hardware */
48609 retval = startup(info);
48610 if (retval < 0) {
48611@@ -715,8 +715,8 @@ cleanup:
48612 if (retval) {
48613 if (tty->count == 1)
48614 info->port.tty = NULL; /* tty layer will release tty struct */
48615- if(info->port.count)
48616- info->port.count--;
48617+ if(atomic_read(&info->port.count))
48618+ atomic_dec(&info->port.count);
48619 }
48620
48621 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
48622@@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48623
48624 if (sanity_check(info, tty->name, "close"))
48625 return;
48626- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
48627+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
48628
48629 if (tty_port_close_start(&info->port, tty, filp) == 0)
48630 goto cleanup;
48631@@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48632 tty_port_close_end(&info->port, tty);
48633 info->port.tty = NULL;
48634 cleanup:
48635- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
48636+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
48637 }
48638
48639 static void hangup(struct tty_struct *tty)
48640@@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
48641 shutdown(info);
48642
48643 spin_lock_irqsave(&info->port.lock, flags);
48644- info->port.count = 0;
48645+ atomic_set(&info->port.count, 0);
48646 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
48647 info->port.tty = NULL;
48648 spin_unlock_irqrestore(&info->port.lock, flags);
48649@@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
48650 unsigned short new_crctype;
48651
48652 /* return error if TTY interface open */
48653- if (info->port.count)
48654+ if (atomic_read(&info->port.count))
48655 return -EBUSY;
48656
48657 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
48658@@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
48659
48660 /* arbitrate between network and tty opens */
48661 spin_lock_irqsave(&info->netlock, flags);
48662- if (info->port.count != 0 || info->netcount != 0) {
48663+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
48664 DBGINFO(("%s hdlc_open busy\n", dev->name));
48665 spin_unlock_irqrestore(&info->netlock, flags);
48666 return -EBUSY;
48667@@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48668 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
48669
48670 /* return error if TTY interface open */
48671- if (info->port.count)
48672+ if (atomic_read(&info->port.count))
48673 return -EBUSY;
48674
48675 if (cmd != SIOCWANDEV)
48676@@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
48677 if (port == NULL)
48678 continue;
48679 spin_lock(&port->lock);
48680- if ((port->port.count || port->netcount) &&
48681+ if ((atomic_read(&port->port.count) || port->netcount) &&
48682 port->pending_bh && !port->bh_running &&
48683 !port->bh_requested) {
48684 DBGISR(("%s bh queued\n", port->device_name));
48685@@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48686 spin_lock_irqsave(&info->lock, flags);
48687 if (!tty_hung_up_p(filp)) {
48688 extra_count = true;
48689- port->count--;
48690+ atomic_dec(&port->count);
48691 }
48692 spin_unlock_irqrestore(&info->lock, flags);
48693 port->blocked_open++;
48694@@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48695 remove_wait_queue(&port->open_wait, &wait);
48696
48697 if (extra_count)
48698- port->count++;
48699+ atomic_inc(&port->count);
48700 port->blocked_open--;
48701
48702 if (!retval)
48703diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
48704index dc6e969..5dc8786 100644
48705--- a/drivers/tty/synclinkmp.c
48706+++ b/drivers/tty/synclinkmp.c
48707@@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
48708
48709 if (debug_level >= DEBUG_LEVEL_INFO)
48710 printk("%s(%d):%s open(), old ref count = %d\n",
48711- __FILE__,__LINE__,tty->driver->name, info->port.count);
48712+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
48713
48714 /* If port is closing, signal caller to try again */
48715 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
48716@@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
48717 spin_unlock_irqrestore(&info->netlock, flags);
48718 goto cleanup;
48719 }
48720- info->port.count++;
48721+ atomic_inc(&info->port.count);
48722 spin_unlock_irqrestore(&info->netlock, flags);
48723
48724- if (info->port.count == 1) {
48725+ if (atomic_read(&info->port.count) == 1) {
48726 /* 1st open on this device, init hardware */
48727 retval = startup(info);
48728 if (retval < 0)
48729@@ -796,8 +796,8 @@ cleanup:
48730 if (retval) {
48731 if (tty->count == 1)
48732 info->port.tty = NULL; /* tty layer will release tty struct */
48733- if(info->port.count)
48734- info->port.count--;
48735+ if(atomic_read(&info->port.count))
48736+ atomic_dec(&info->port.count);
48737 }
48738
48739 return retval;
48740@@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48741
48742 if (debug_level >= DEBUG_LEVEL_INFO)
48743 printk("%s(%d):%s close() entry, count=%d\n",
48744- __FILE__,__LINE__, info->device_name, info->port.count);
48745+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
48746
48747 if (tty_port_close_start(&info->port, tty, filp) == 0)
48748 goto cleanup;
48749@@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
48750 cleanup:
48751 if (debug_level >= DEBUG_LEVEL_INFO)
48752 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
48753- tty->driver->name, info->port.count);
48754+ tty->driver->name, atomic_read(&info->port.count));
48755 }
48756
48757 /* Called by tty_hangup() when a hangup is signaled.
48758@@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
48759 shutdown(info);
48760
48761 spin_lock_irqsave(&info->port.lock, flags);
48762- info->port.count = 0;
48763+ atomic_set(&info->port.count, 0);
48764 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
48765 info->port.tty = NULL;
48766 spin_unlock_irqrestore(&info->port.lock, flags);
48767@@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
48768 unsigned short new_crctype;
48769
48770 /* return error if TTY interface open */
48771- if (info->port.count)
48772+ if (atomic_read(&info->port.count))
48773 return -EBUSY;
48774
48775 switch (encoding)
48776@@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
48777
48778 /* arbitrate between network and tty opens */
48779 spin_lock_irqsave(&info->netlock, flags);
48780- if (info->port.count != 0 || info->netcount != 0) {
48781+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
48782 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
48783 spin_unlock_irqrestore(&info->netlock, flags);
48784 return -EBUSY;
48785@@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48786 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
48787
48788 /* return error if TTY interface open */
48789- if (info->port.count)
48790+ if (atomic_read(&info->port.count))
48791 return -EBUSY;
48792
48793 if (cmd != SIOCWANDEV)
48794@@ -2620,7 +2620,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
48795 * do not request bottom half processing if the
48796 * device is not open in a normal mode.
48797 */
48798- if ( port && (port->port.count || port->netcount) &&
48799+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
48800 port->pending_bh && !port->bh_running &&
48801 !port->bh_requested ) {
48802 if ( debug_level >= DEBUG_LEVEL_ISR )
48803@@ -3318,12 +3318,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48804
48805 if (debug_level >= DEBUG_LEVEL_INFO)
48806 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
48807- __FILE__,__LINE__, tty->driver->name, port->count );
48808+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48809
48810 spin_lock_irqsave(&info->lock, flags);
48811 if (!tty_hung_up_p(filp)) {
48812 extra_count = true;
48813- port->count--;
48814+ atomic_dec(&port->count);
48815 }
48816 spin_unlock_irqrestore(&info->lock, flags);
48817 port->blocked_open++;
48818@@ -3352,7 +3352,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48819
48820 if (debug_level >= DEBUG_LEVEL_INFO)
48821 printk("%s(%d):%s block_til_ready() count=%d\n",
48822- __FILE__,__LINE__, tty->driver->name, port->count );
48823+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48824
48825 tty_unlock(tty);
48826 schedule();
48827@@ -3363,12 +3363,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
48828 remove_wait_queue(&port->open_wait, &wait);
48829
48830 if (extra_count)
48831- port->count++;
48832+ atomic_inc(&port->count);
48833 port->blocked_open--;
48834
48835 if (debug_level >= DEBUG_LEVEL_INFO)
48836 printk("%s(%d):%s block_til_ready() after, count=%d\n",
48837- __FILE__,__LINE__, tty->driver->name, port->count );
48838+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
48839
48840 if (!retval)
48841 port->flags |= ASYNC_NORMAL_ACTIVE;
48842diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
48843index d5cc3ac..3263411 100644
48844--- a/drivers/tty/sysrq.c
48845+++ b/drivers/tty/sysrq.c
48846@@ -1033,7 +1033,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
48847 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
48848 size_t count, loff_t *ppos)
48849 {
48850- if (count) {
48851+ if (count && capable(CAP_SYS_ADMIN)) {
48852 char c;
48853
48854 if (get_user(c, buf))
48855diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
48856index 366af83..6db51c3 100644
48857--- a/drivers/tty/tty_io.c
48858+++ b/drivers/tty/tty_io.c
48859@@ -3467,7 +3467,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
48860
48861 void tty_default_fops(struct file_operations *fops)
48862 {
48863- *fops = tty_fops;
48864+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
48865 }
48866
48867 /*
48868diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
48869index 1afe192..73d2c20 100644
48870--- a/drivers/tty/tty_ldisc.c
48871+++ b/drivers/tty/tty_ldisc.c
48872@@ -66,7 +66,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
48873 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
48874 tty_ldiscs[disc] = new_ldisc;
48875 new_ldisc->num = disc;
48876- new_ldisc->refcount = 0;
48877+ atomic_set(&new_ldisc->refcount, 0);
48878 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
48879
48880 return ret;
48881@@ -94,7 +94,7 @@ int tty_unregister_ldisc(int disc)
48882 return -EINVAL;
48883
48884 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
48885- if (tty_ldiscs[disc]->refcount)
48886+ if (atomic_read(&tty_ldiscs[disc]->refcount))
48887 ret = -EBUSY;
48888 else
48889 tty_ldiscs[disc] = NULL;
48890@@ -115,7 +115,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
48891 if (ldops) {
48892 ret = ERR_PTR(-EAGAIN);
48893 if (try_module_get(ldops->owner)) {
48894- ldops->refcount++;
48895+ atomic_inc(&ldops->refcount);
48896 ret = ldops;
48897 }
48898 }
48899@@ -128,7 +128,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
48900 unsigned long flags;
48901
48902 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
48903- ldops->refcount--;
48904+ atomic_dec(&ldops->refcount);
48905 module_put(ldops->owner);
48906 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
48907 }
48908@@ -196,7 +196,7 @@ static inline void tty_ldisc_put(struct tty_ldisc *ld)
48909 /* unreleased reader reference(s) will cause this WARN */
48910 WARN_ON(!atomic_dec_and_test(&ld->users));
48911
48912- ld->ops->refcount--;
48913+ atomic_dec(&ld->ops->refcount);
48914 module_put(ld->ops->owner);
48915 kfree(ld);
48916 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
48917diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
48918index f597e88..b7f68ed 100644
48919--- a/drivers/tty/tty_port.c
48920+++ b/drivers/tty/tty_port.c
48921@@ -232,7 +232,7 @@ void tty_port_hangup(struct tty_port *port)
48922 unsigned long flags;
48923
48924 spin_lock_irqsave(&port->lock, flags);
48925- port->count = 0;
48926+ atomic_set(&port->count, 0);
48927 port->flags &= ~ASYNC_NORMAL_ACTIVE;
48928 tty = port->tty;
48929 if (tty)
48930@@ -390,7 +390,7 @@ int tty_port_block_til_ready(struct tty_port *port,
48931 /* The port lock protects the port counts */
48932 spin_lock_irqsave(&port->lock, flags);
48933 if (!tty_hung_up_p(filp))
48934- port->count--;
48935+ atomic_dec(&port->count);
48936 port->blocked_open++;
48937 spin_unlock_irqrestore(&port->lock, flags);
48938
48939@@ -432,7 +432,7 @@ int tty_port_block_til_ready(struct tty_port *port,
48940 we must not mess that up further */
48941 spin_lock_irqsave(&port->lock, flags);
48942 if (!tty_hung_up_p(filp))
48943- port->count++;
48944+ atomic_inc(&port->count);
48945 port->blocked_open--;
48946 if (retval == 0)
48947 port->flags |= ASYNC_NORMAL_ACTIVE;
48948@@ -466,19 +466,19 @@ int tty_port_close_start(struct tty_port *port,
48949 return 0;
48950 }
48951
48952- if (tty->count == 1 && port->count != 1) {
48953+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
48954 printk(KERN_WARNING
48955 "tty_port_close_start: tty->count = 1 port count = %d.\n",
48956- port->count);
48957- port->count = 1;
48958+ atomic_read(&port->count));
48959+ atomic_set(&port->count, 1);
48960 }
48961- if (--port->count < 0) {
48962+ if (atomic_dec_return(&port->count) < 0) {
48963 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
48964- port->count);
48965- port->count = 0;
48966+ atomic_read(&port->count));
48967+ atomic_set(&port->count, 0);
48968 }
48969
48970- if (port->count) {
48971+ if (atomic_read(&port->count)) {
48972 spin_unlock_irqrestore(&port->lock, flags);
48973 if (port->ops->drop)
48974 port->ops->drop(port);
48975@@ -564,7 +564,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
48976 {
48977 spin_lock_irq(&port->lock);
48978 if (!tty_hung_up_p(filp))
48979- ++port->count;
48980+ atomic_inc(&port->count);
48981 spin_unlock_irq(&port->lock);
48982 tty_port_tty_set(port, tty);
48983
48984diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
48985index a9af1b9a..1e08e7f 100644
48986--- a/drivers/tty/vt/keyboard.c
48987+++ b/drivers/tty/vt/keyboard.c
48988@@ -647,6 +647,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
48989 kbd->kbdmode == VC_OFF) &&
48990 value != KVAL(K_SAK))
48991 return; /* SAK is allowed even in raw mode */
48992+
48993+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
48994+ {
48995+ void *func = fn_handler[value];
48996+ if (func == fn_show_state || func == fn_show_ptregs ||
48997+ func == fn_show_mem)
48998+ return;
48999+ }
49000+#endif
49001+
49002 fn_handler[value](vc);
49003 }
49004
49005@@ -1795,9 +1805,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
49006 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
49007 return -EFAULT;
49008
49009- if (!capable(CAP_SYS_TTY_CONFIG))
49010- perm = 0;
49011-
49012 switch (cmd) {
49013 case KDGKBENT:
49014 /* Ensure another thread doesn't free it under us */
49015@@ -1812,6 +1819,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
49016 spin_unlock_irqrestore(&kbd_event_lock, flags);
49017 return put_user(val, &user_kbe->kb_value);
49018 case KDSKBENT:
49019+ if (!capable(CAP_SYS_TTY_CONFIG))
49020+ perm = 0;
49021+
49022 if (!perm)
49023 return -EPERM;
49024 if (!i && v == K_NOSUCHMAP) {
49025@@ -1902,9 +1912,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
49026 int i, j, k;
49027 int ret;
49028
49029- if (!capable(CAP_SYS_TTY_CONFIG))
49030- perm = 0;
49031-
49032 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
49033 if (!kbs) {
49034 ret = -ENOMEM;
49035@@ -1938,6 +1945,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
49036 kfree(kbs);
49037 return ((p && *p) ? -EOVERFLOW : 0);
49038 case KDSKBSENT:
49039+ if (!capable(CAP_SYS_TTY_CONFIG))
49040+ perm = 0;
49041+
49042 if (!perm) {
49043 ret = -EPERM;
49044 goto reterr;
49045diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
49046index 3b96f18..026a9bf 100644
49047--- a/drivers/uio/uio.c
49048+++ b/drivers/uio/uio.c
49049@@ -25,6 +25,7 @@
49050 #include <linux/kobject.h>
49051 #include <linux/cdev.h>
49052 #include <linux/uio_driver.h>
49053+#include <asm/local.h>
49054
49055 #define UIO_MAX_DEVICES (1U << MINORBITS)
49056
49057@@ -32,10 +33,10 @@ struct uio_device {
49058 struct module *owner;
49059 struct device *dev;
49060 int minor;
49061- atomic_t event;
49062+ atomic_unchecked_t event;
49063 struct fasync_struct *async_queue;
49064 wait_queue_head_t wait;
49065- int vma_count;
49066+ local_t vma_count;
49067 struct uio_info *info;
49068 struct kobject *map_dir;
49069 struct kobject *portio_dir;
49070@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
49071 struct device_attribute *attr, char *buf)
49072 {
49073 struct uio_device *idev = dev_get_drvdata(dev);
49074- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
49075+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
49076 }
49077
49078 static struct device_attribute uio_class_attributes[] = {
49079@@ -398,7 +399,7 @@ void uio_event_notify(struct uio_info *info)
49080 {
49081 struct uio_device *idev = info->uio_dev;
49082
49083- atomic_inc(&idev->event);
49084+ atomic_inc_unchecked(&idev->event);
49085 wake_up_interruptible(&idev->wait);
49086 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
49087 }
49088@@ -451,7 +452,7 @@ static int uio_open(struct inode *inode, struct file *filep)
49089 }
49090
49091 listener->dev = idev;
49092- listener->event_count = atomic_read(&idev->event);
49093+ listener->event_count = atomic_read_unchecked(&idev->event);
49094 filep->private_data = listener;
49095
49096 if (idev->info->open) {
49097@@ -502,7 +503,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
49098 return -EIO;
49099
49100 poll_wait(filep, &idev->wait, wait);
49101- if (listener->event_count != atomic_read(&idev->event))
49102+ if (listener->event_count != atomic_read_unchecked(&idev->event))
49103 return POLLIN | POLLRDNORM;
49104 return 0;
49105 }
49106@@ -527,7 +528,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
49107 do {
49108 set_current_state(TASK_INTERRUPTIBLE);
49109
49110- event_count = atomic_read(&idev->event);
49111+ event_count = atomic_read_unchecked(&idev->event);
49112 if (event_count != listener->event_count) {
49113 if (copy_to_user(buf, &event_count, count))
49114 retval = -EFAULT;
49115@@ -596,13 +597,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
49116 static void uio_vma_open(struct vm_area_struct *vma)
49117 {
49118 struct uio_device *idev = vma->vm_private_data;
49119- idev->vma_count++;
49120+ local_inc(&idev->vma_count);
49121 }
49122
49123 static void uio_vma_close(struct vm_area_struct *vma)
49124 {
49125 struct uio_device *idev = vma->vm_private_data;
49126- idev->vma_count--;
49127+ local_dec(&idev->vma_count);
49128 }
49129
49130 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
49131@@ -809,7 +810,7 @@ int __uio_register_device(struct module *owner,
49132 idev->owner = owner;
49133 idev->info = info;
49134 init_waitqueue_head(&idev->wait);
49135- atomic_set(&idev->event, 0);
49136+ atomic_set_unchecked(&idev->event, 0);
49137
49138 ret = uio_get_minor(idev);
49139 if (ret)
49140diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
49141index 8a7eb77..c00402f 100644
49142--- a/drivers/usb/atm/cxacru.c
49143+++ b/drivers/usb/atm/cxacru.c
49144@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
49145 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
49146 if (ret < 2)
49147 return -EINVAL;
49148- if (index < 0 || index > 0x7f)
49149+ if (index > 0x7f)
49150 return -EINVAL;
49151 pos += tmp;
49152
49153diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
49154index 5e0d33a..cc10579 100644
49155--- a/drivers/usb/atm/usbatm.c
49156+++ b/drivers/usb/atm/usbatm.c
49157@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
49158 if (printk_ratelimit())
49159 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
49160 __func__, vpi, vci);
49161- atomic_inc(&vcc->stats->rx_err);
49162+ atomic_inc_unchecked(&vcc->stats->rx_err);
49163 return;
49164 }
49165
49166@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
49167 if (length > ATM_MAX_AAL5_PDU) {
49168 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
49169 __func__, length, vcc);
49170- atomic_inc(&vcc->stats->rx_err);
49171+ atomic_inc_unchecked(&vcc->stats->rx_err);
49172 goto out;
49173 }
49174
49175@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
49176 if (sarb->len < pdu_length) {
49177 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
49178 __func__, pdu_length, sarb->len, vcc);
49179- atomic_inc(&vcc->stats->rx_err);
49180+ atomic_inc_unchecked(&vcc->stats->rx_err);
49181 goto out;
49182 }
49183
49184 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
49185 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
49186 __func__, vcc);
49187- atomic_inc(&vcc->stats->rx_err);
49188+ atomic_inc_unchecked(&vcc->stats->rx_err);
49189 goto out;
49190 }
49191
49192@@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
49193 if (printk_ratelimit())
49194 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
49195 __func__, length);
49196- atomic_inc(&vcc->stats->rx_drop);
49197+ atomic_inc_unchecked(&vcc->stats->rx_drop);
49198 goto out;
49199 }
49200
49201@@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
49202
49203 vcc->push(vcc, skb);
49204
49205- atomic_inc(&vcc->stats->rx);
49206+ atomic_inc_unchecked(&vcc->stats->rx);
49207 out:
49208 skb_trim(sarb, 0);
49209 }
49210@@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
49211 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
49212
49213 usbatm_pop(vcc, skb);
49214- atomic_inc(&vcc->stats->tx);
49215+ atomic_inc_unchecked(&vcc->stats->tx);
49216
49217 skb = skb_dequeue(&instance->sndqueue);
49218 }
49219@@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
49220 if (!left--)
49221 return sprintf(page,
49222 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
49223- atomic_read(&atm_dev->stats.aal5.tx),
49224- atomic_read(&atm_dev->stats.aal5.tx_err),
49225- atomic_read(&atm_dev->stats.aal5.rx),
49226- atomic_read(&atm_dev->stats.aal5.rx_err),
49227- atomic_read(&atm_dev->stats.aal5.rx_drop));
49228+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
49229+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
49230+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
49231+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
49232+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
49233
49234 if (!left--) {
49235 if (instance->disconnected)
49236diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
49237index 2a3bbdf..91d72cf 100644
49238--- a/drivers/usb/core/devices.c
49239+++ b/drivers/usb/core/devices.c
49240@@ -126,7 +126,7 @@ static const char format_endpt[] =
49241 * time it gets called.
49242 */
49243 static struct device_connect_event {
49244- atomic_t count;
49245+ atomic_unchecked_t count;
49246 wait_queue_head_t wait;
49247 } device_event = {
49248 .count = ATOMIC_INIT(1),
49249@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
49250
49251 void usbfs_conn_disc_event(void)
49252 {
49253- atomic_add(2, &device_event.count);
49254+ atomic_add_unchecked(2, &device_event.count);
49255 wake_up(&device_event.wait);
49256 }
49257
49258@@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
49259
49260 poll_wait(file, &device_event.wait, wait);
49261
49262- event_count = atomic_read(&device_event.count);
49263+ event_count = atomic_read_unchecked(&device_event.count);
49264 if (file->f_version != event_count) {
49265 file->f_version = event_count;
49266 return POLLIN | POLLRDNORM;
49267diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
49268index 014dc99..4d25fd7 100644
49269--- a/drivers/usb/core/hcd.c
49270+++ b/drivers/usb/core/hcd.c
49271@@ -1551,7 +1551,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
49272 */
49273 usb_get_urb(urb);
49274 atomic_inc(&urb->use_count);
49275- atomic_inc(&urb->dev->urbnum);
49276+ atomic_inc_unchecked(&urb->dev->urbnum);
49277 usbmon_urb_submit(&hcd->self, urb);
49278
49279 /* NOTE requirements on root-hub callers (usbfs and the hub
49280@@ -1578,7 +1578,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
49281 urb->hcpriv = NULL;
49282 INIT_LIST_HEAD(&urb->urb_list);
49283 atomic_dec(&urb->use_count);
49284- atomic_dec(&urb->dev->urbnum);
49285+ atomic_dec_unchecked(&urb->dev->urbnum);
49286 if (atomic_read(&urb->reject))
49287 wake_up(&usb_kill_urb_queue);
49288 usb_put_urb(urb);
49289diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
49290index 558313d..8cadfa5 100644
49291--- a/drivers/usb/core/hub.c
49292+++ b/drivers/usb/core/hub.c
49293@@ -27,6 +27,7 @@
49294 #include <linux/freezer.h>
49295 #include <linux/random.h>
49296 #include <linux/pm_qos.h>
49297+#include <linux/grsecurity.h>
49298
49299 #include <asm/uaccess.h>
49300 #include <asm/byteorder.h>
49301@@ -4426,6 +4427,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
49302 goto done;
49303 return;
49304 }
49305+
49306+ if (gr_handle_new_usb())
49307+ goto done;
49308+
49309 if (hub_is_superspeed(hub->hdev))
49310 unit_load = 150;
49311 else
49312diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
49313index e7ee1e4..1dfc9ea4 100644
49314--- a/drivers/usb/core/message.c
49315+++ b/drivers/usb/core/message.c
49316@@ -129,7 +129,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
49317 * method can wait for it to complete. Since you don't have a handle on the
49318 * URB used, you can't cancel the request.
49319 */
49320-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
49321+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
49322 __u8 requesttype, __u16 value, __u16 index, void *data,
49323 __u16 size, int timeout)
49324 {
49325diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
49326index d9284b9..17023c7 100644
49327--- a/drivers/usb/core/sysfs.c
49328+++ b/drivers/usb/core/sysfs.c
49329@@ -239,7 +239,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
49330 struct usb_device *udev;
49331
49332 udev = to_usb_device(dev);
49333- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
49334+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
49335 }
49336 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
49337
49338diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
49339index 7dad603..350f7a9 100644
49340--- a/drivers/usb/core/usb.c
49341+++ b/drivers/usb/core/usb.c
49342@@ -422,7 +422,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
49343 set_dev_node(&dev->dev, dev_to_node(bus->controller));
49344 dev->state = USB_STATE_ATTACHED;
49345 dev->lpm_disable_count = 1;
49346- atomic_set(&dev->urbnum, 0);
49347+ atomic_set_unchecked(&dev->urbnum, 0);
49348
49349 INIT_LIST_HEAD(&dev->ep0.urb_list);
49350 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
49351diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
49352index f77083f..f3e2e34 100644
49353--- a/drivers/usb/dwc3/gadget.c
49354+++ b/drivers/usb/dwc3/gadget.c
49355@@ -550,8 +550,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
49356 if (!usb_endpoint_xfer_isoc(desc))
49357 return 0;
49358
49359- memset(&trb_link, 0, sizeof(trb_link));
49360-
49361 /* Link TRB for ISOC. The HWO bit is never reset */
49362 trb_st_hw = &dep->trb_pool[0];
49363
49364diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
49365index 5e29dde..eca992f 100644
49366--- a/drivers/usb/early/ehci-dbgp.c
49367+++ b/drivers/usb/early/ehci-dbgp.c
49368@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
49369
49370 #ifdef CONFIG_KGDB
49371 static struct kgdb_io kgdbdbgp_io_ops;
49372-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
49373+static struct kgdb_io kgdbdbgp_io_ops_console;
49374+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
49375 #else
49376 #define dbgp_kgdb_mode (0)
49377 #endif
49378@@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
49379 .write_char = kgdbdbgp_write_char,
49380 };
49381
49382+static struct kgdb_io kgdbdbgp_io_ops_console = {
49383+ .name = "kgdbdbgp",
49384+ .read_char = kgdbdbgp_read_char,
49385+ .write_char = kgdbdbgp_write_char,
49386+ .is_console = 1
49387+};
49388+
49389 static int kgdbdbgp_wait_time;
49390
49391 static int __init kgdbdbgp_parse_config(char *str)
49392@@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
49393 ptr++;
49394 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
49395 }
49396- kgdb_register_io_module(&kgdbdbgp_io_ops);
49397- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
49398+ if (early_dbgp_console.index != -1)
49399+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
49400+ else
49401+ kgdb_register_io_module(&kgdbdbgp_io_ops);
49402
49403 return 0;
49404 }
49405diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
49406index b369292..9f3ba40 100644
49407--- a/drivers/usb/gadget/u_serial.c
49408+++ b/drivers/usb/gadget/u_serial.c
49409@@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
49410 spin_lock_irq(&port->port_lock);
49411
49412 /* already open? Great. */
49413- if (port->port.count) {
49414+ if (atomic_read(&port->port.count)) {
49415 status = 0;
49416- port->port.count++;
49417+ atomic_inc(&port->port.count);
49418
49419 /* currently opening/closing? wait ... */
49420 } else if (port->openclose) {
49421@@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
49422 tty->driver_data = port;
49423 port->port.tty = tty;
49424
49425- port->port.count = 1;
49426+ atomic_set(&port->port.count, 1);
49427 port->openclose = false;
49428
49429 /* if connected, start the I/O stream */
49430@@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
49431
49432 spin_lock_irq(&port->port_lock);
49433
49434- if (port->port.count != 1) {
49435- if (port->port.count == 0)
49436+ if (atomic_read(&port->port.count) != 1) {
49437+ if (atomic_read(&port->port.count) == 0)
49438 WARN_ON(1);
49439 else
49440- --port->port.count;
49441+ atomic_dec(&port->port.count);
49442 goto exit;
49443 }
49444
49445@@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
49446 * and sleep if necessary
49447 */
49448 port->openclose = true;
49449- port->port.count = 0;
49450+ atomic_set(&port->port.count, 0);
49451
49452 gser = port->port_usb;
49453 if (gser && gser->disconnect)
49454@@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
49455 int cond;
49456
49457 spin_lock_irq(&port->port_lock);
49458- cond = (port->port.count == 0) && !port->openclose;
49459+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
49460 spin_unlock_irq(&port->port_lock);
49461 return cond;
49462 }
49463@@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
49464 /* if it's already open, start I/O ... and notify the serial
49465 * protocol about open/close status (connect/disconnect).
49466 */
49467- if (port->port.count) {
49468+ if (atomic_read(&port->port.count)) {
49469 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
49470 gs_start_io(port);
49471 if (gser->connect)
49472@@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
49473
49474 port->port_usb = NULL;
49475 gser->ioport = NULL;
49476- if (port->port.count > 0 || port->openclose) {
49477+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
49478 wake_up_interruptible(&port->drain_wait);
49479 if (port->port.tty)
49480 tty_hangup(port->port.tty);
49481@@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
49482
49483 /* finally, free any unused/unusable I/O buffers */
49484 spin_lock_irqsave(&port->port_lock, flags);
49485- if (port->port.count == 0 && !port->openclose)
49486+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
49487 gs_buf_free(&port->port_write_buf);
49488 gs_free_requests(gser->out, &port->read_pool, NULL);
49489 gs_free_requests(gser->out, &port->read_queue, NULL);
49490diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
49491index ba6a5d6..f88f7f3 100644
49492--- a/drivers/usb/misc/appledisplay.c
49493+++ b/drivers/usb/misc/appledisplay.c
49494@@ -83,7 +83,7 @@ struct appledisplay {
49495 spinlock_t lock;
49496 };
49497
49498-static atomic_t count_displays = ATOMIC_INIT(0);
49499+static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
49500 static struct workqueue_struct *wq;
49501
49502 static void appledisplay_complete(struct urb *urb)
49503@@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
49504
49505 /* Register backlight device */
49506 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
49507- atomic_inc_return(&count_displays) - 1);
49508+ atomic_inc_return_unchecked(&count_displays) - 1);
49509 memset(&props, 0, sizeof(struct backlight_properties));
49510 props.type = BACKLIGHT_RAW;
49511 props.max_brightness = 0xff;
49512diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
49513index afb50ea..7b0b1cf 100644
49514--- a/drivers/usb/serial/console.c
49515+++ b/drivers/usb/serial/console.c
49516@@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
49517
49518 info->port = port;
49519
49520- ++port->port.count;
49521+ atomic_inc(&port->port.count);
49522 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
49523 if (serial->type->set_termios) {
49524 /*
49525@@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
49526 }
49527 /* Now that any required fake tty operations are completed restore
49528 * the tty port count */
49529- --port->port.count;
49530+ atomic_dec(&port->port.count);
49531 /* The console is special in terms of closing the device so
49532 * indicate this port is now acting as a system console. */
49533 port->port.console = 1;
49534@@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
49535 free_tty:
49536 kfree(tty);
49537 reset_open_count:
49538- port->port.count = 0;
49539+ atomic_set(&port->port.count, 0);
49540 usb_autopm_put_interface(serial->interface);
49541 error_get_interface:
49542 usb_serial_put(serial);
49543diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
49544index 75f70f0..d467e1a 100644
49545--- a/drivers/usb/storage/usb.h
49546+++ b/drivers/usb/storage/usb.h
49547@@ -63,7 +63,7 @@ struct us_unusual_dev {
49548 __u8 useProtocol;
49549 __u8 useTransport;
49550 int (*initFunction)(struct us_data *);
49551-};
49552+} __do_const;
49553
49554
49555 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
49556diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
49557index d6bea3e..60b250e 100644
49558--- a/drivers/usb/wusbcore/wa-hc.h
49559+++ b/drivers/usb/wusbcore/wa-hc.h
49560@@ -192,7 +192,7 @@ struct wahc {
49561 struct list_head xfer_delayed_list;
49562 spinlock_t xfer_list_lock;
49563 struct work_struct xfer_work;
49564- atomic_t xfer_id_count;
49565+ atomic_unchecked_t xfer_id_count;
49566 };
49567
49568
49569@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
49570 INIT_LIST_HEAD(&wa->xfer_delayed_list);
49571 spin_lock_init(&wa->xfer_list_lock);
49572 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
49573- atomic_set(&wa->xfer_id_count, 1);
49574+ atomic_set_unchecked(&wa->xfer_id_count, 1);
49575 }
49576
49577 /**
49578diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
49579index d3493ca..0c33b7e 100644
49580--- a/drivers/usb/wusbcore/wa-xfer.c
49581+++ b/drivers/usb/wusbcore/wa-xfer.c
49582@@ -297,7 +297,7 @@ out:
49583 */
49584 static void wa_xfer_id_init(struct wa_xfer *xfer)
49585 {
49586- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
49587+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
49588 }
49589
49590 /*
49591diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
49592index 842f450..d1d7409 100644
49593--- a/drivers/vfio/vfio.c
49594+++ b/drivers/vfio/vfio.c
49595@@ -488,7 +488,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
49596 return 0;
49597
49598 /* TODO Prevent device auto probing */
49599- WARN("Device %s added to live group %d!\n", dev_name(dev),
49600+ WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
49601 iommu_group_id(group->iommu_group));
49602
49603 return 0;
49604diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
49605index 5174eba..86e764a 100644
49606--- a/drivers/vhost/vringh.c
49607+++ b/drivers/vhost/vringh.c
49608@@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
49609
49610 static inline int putu16_kern(u16 *p, u16 val)
49611 {
49612- ACCESS_ONCE(*p) = val;
49613+ ACCESS_ONCE_RW(*p) = val;
49614 return 0;
49615 }
49616
49617diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
49618index a4dfe8c..297ddd9 100644
49619--- a/drivers/video/aty/aty128fb.c
49620+++ b/drivers/video/aty/aty128fb.c
49621@@ -149,7 +149,7 @@ enum {
49622 };
49623
49624 /* Must match above enum */
49625-static char * const r128_family[] = {
49626+static const char * const r128_family[] = {
49627 "AGP",
49628 "PCI",
49629 "PRO AGP",
49630diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
49631index 9b0f12c..024673d 100644
49632--- a/drivers/video/aty/atyfb_base.c
49633+++ b/drivers/video/aty/atyfb_base.c
49634@@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
49635 par->accel_flags = var->accel_flags; /* hack */
49636
49637 if (var->accel_flags) {
49638- info->fbops->fb_sync = atyfb_sync;
49639+ pax_open_kernel();
49640+ *(void **)&info->fbops->fb_sync = atyfb_sync;
49641+ pax_close_kernel();
49642 info->flags &= ~FBINFO_HWACCEL_DISABLED;
49643 } else {
49644- info->fbops->fb_sync = NULL;
49645+ pax_open_kernel();
49646+ *(void **)&info->fbops->fb_sync = NULL;
49647+ pax_close_kernel();
49648 info->flags |= FBINFO_HWACCEL_DISABLED;
49649 }
49650
49651diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
49652index 95ec042..e6affdd 100644
49653--- a/drivers/video/aty/mach64_cursor.c
49654+++ b/drivers/video/aty/mach64_cursor.c
49655@@ -7,6 +7,7 @@
49656 #include <linux/string.h>
49657
49658 #include <asm/io.h>
49659+#include <asm/pgtable.h>
49660
49661 #ifdef __sparc__
49662 #include <asm/fbio.h>
49663@@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
49664 info->sprite.buf_align = 16; /* and 64 lines tall. */
49665 info->sprite.flags = FB_PIXMAP_IO;
49666
49667- info->fbops->fb_cursor = atyfb_cursor;
49668+ pax_open_kernel();
49669+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
49670+ pax_close_kernel();
49671
49672 return 0;
49673 }
49674diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
49675index bca6ccc..252107e 100644
49676--- a/drivers/video/backlight/kb3886_bl.c
49677+++ b/drivers/video/backlight/kb3886_bl.c
49678@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
49679 static unsigned long kb3886bl_flags;
49680 #define KB3886BL_SUSPENDED 0x01
49681
49682-static struct dmi_system_id __initdata kb3886bl_device_table[] = {
49683+static const struct dmi_system_id __initconst kb3886bl_device_table[] = {
49684 {
49685 .ident = "Sahara Touch-iT",
49686 .matches = {
49687diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
49688index 900aa4e..6d49418 100644
49689--- a/drivers/video/fb_defio.c
49690+++ b/drivers/video/fb_defio.c
49691@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
49692
49693 BUG_ON(!fbdefio);
49694 mutex_init(&fbdefio->lock);
49695- info->fbops->fb_mmap = fb_deferred_io_mmap;
49696+ pax_open_kernel();
49697+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
49698+ pax_close_kernel();
49699 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
49700 INIT_LIST_HEAD(&fbdefio->pagelist);
49701 if (fbdefio->delay == 0) /* set a default of 1 s */
49702@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
49703 page->mapping = NULL;
49704 }
49705
49706- info->fbops->fb_mmap = NULL;
49707+ *(void **)&info->fbops->fb_mmap = NULL;
49708 mutex_destroy(&fbdefio->lock);
49709 }
49710 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
49711diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
49712index 5c3960d..15cf8fc 100644
49713--- a/drivers/video/fbcmap.c
49714+++ b/drivers/video/fbcmap.c
49715@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
49716 rc = -ENODEV;
49717 goto out;
49718 }
49719- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
49720- !info->fbops->fb_setcmap)) {
49721+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
49722 rc = -EINVAL;
49723 goto out1;
49724 }
49725diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
49726index 36e1fe2..c744820 100644
49727--- a/drivers/video/fbmem.c
49728+++ b/drivers/video/fbmem.c
49729@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
49730 image->dx += image->width + 8;
49731 }
49732 } else if (rotate == FB_ROTATE_UD) {
49733- for (x = 0; x < num && image->dx >= 0; x++) {
49734+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
49735 info->fbops->fb_imageblit(info, image);
49736 image->dx -= image->width + 8;
49737 }
49738@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
49739 image->dy += image->height + 8;
49740 }
49741 } else if (rotate == FB_ROTATE_CCW) {
49742- for (x = 0; x < num && image->dy >= 0; x++) {
49743+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
49744 info->fbops->fb_imageblit(info, image);
49745 image->dy -= image->height + 8;
49746 }
49747@@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
49748 return -EFAULT;
49749 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
49750 return -EINVAL;
49751- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
49752+ if (con2fb.framebuffer >= FB_MAX)
49753 return -EINVAL;
49754 if (!registered_fb[con2fb.framebuffer])
49755 request_module("fb%d", con2fb.framebuffer);
49756diff --git a/drivers/video/hyperv_fb.c b/drivers/video/hyperv_fb.c
49757index d4d2c5f..ebbd113 100644
49758--- a/drivers/video/hyperv_fb.c
49759+++ b/drivers/video/hyperv_fb.c
49760@@ -233,7 +233,7 @@ static uint screen_fb_size;
49761 static inline int synthvid_send(struct hv_device *hdev,
49762 struct synthvid_msg *msg)
49763 {
49764- static atomic64_t request_id = ATOMIC64_INIT(0);
49765+ static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
49766 int ret;
49767
49768 msg->pipe_hdr.type = PIPE_MSG_DATA;
49769@@ -241,7 +241,7 @@ static inline int synthvid_send(struct hv_device *hdev,
49770
49771 ret = vmbus_sendpacket(hdev->channel, msg,
49772 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
49773- atomic64_inc_return(&request_id),
49774+ atomic64_inc_return_unchecked(&request_id),
49775 VM_PKT_DATA_INBAND, 0);
49776
49777 if (ret)
49778diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
49779index 7672d2e..b56437f 100644
49780--- a/drivers/video/i810/i810_accel.c
49781+++ b/drivers/video/i810/i810_accel.c
49782@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
49783 }
49784 }
49785 printk("ringbuffer lockup!!!\n");
49786+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
49787 i810_report_error(mmio);
49788 par->dev_flags |= LOCKUP;
49789 info->pixmap.scan_align = 1;
49790diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
49791index 285d552..eafa544 100644
49792--- a/drivers/video/logo/logo_linux_clut224.ppm
49793+++ b/drivers/video/logo/logo_linux_clut224.ppm
49794@@ -1,883 +1,1123 @@
49795 P3
49796 80 80
49797 255
49798-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49799-0 0 0 0 0 0 0 0 0 0 0 0 11 15 17 33 49 54 59 85 92 73 97 106
49800-83 116 129 105 131 142 115 114 122 74 88 93 20 29 31 0 0 0 0 0 0 0 0 0
49801-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49802-0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 6 6 6 10 10 10 10 10 10
49803-10 10 10 6 6 6 6 6 6 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
49804-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49805-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49806-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49807-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49808-
49809-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49810-0 0 0 0 0 0 2 3 3 17 23 26 50 67 72 73 97 106 59 85 92 73 97 106
49811-105 131 142 124 127 131 105 131 142 105 131 142 53 75 83 6 8 8 0 0 0 0 0 0
49812-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49813-0 0 0 6 6 6 10 10 10 14 14 14 22 22 22 26 26 26 30 30 30 34 34 34
49814-30 30 30 30 30 30 26 26 26 18 18 18 14 14 14 10 10 10 6 6 6 0 0 0
49815-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49816-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49817-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49818-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49819-
49820-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 0 0 0
49821-0 0 0 1 1 1 26 35 39 59 85 92 59 85 92 59 85 92 29 43 47 53 75 83
49822-108 122 132 132 98 104 108 122 132 105 131 142 101 101 101 43 45 48 6 8 8 0 0 0
49823-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49824-6 6 6 14 14 14 26 26 26 42 42 42 54 54 54 66 66 66 78 78 78 78 78 78
49825-78 78 78 74 74 74 66 66 66 54 54 54 42 42 42 26 26 26 18 18 18 10 10 10
49826-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49827-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49828-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49829-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49830-
49831-0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 0 0
49832-11 15 17 27 40 45 59 85 92 59 85 92 27 40 45 31 45 49 73 97 106 93 121 133
49833-108 122 132 108 122 132 105 131 142 108 122 132 105 131 142 73 97 106 26 35 39 0 0 0
49834-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
49835-22 22 22 42 42 42 66 66 66 86 86 86 66 66 66 38 38 38 38 38 38 22 22 22
49836-26 26 26 34 34 34 54 54 54 66 66 66 86 86 86 70 70 70 46 46 46 26 26 26
49837-14 14 14 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49838-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49839-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49840-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49841-
49842-0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 7 12 13 21 31 35 42 59 64
49843-53 75 83 53 75 83 50 67 72 42 59 64 32 40 45 42 59 64 73 97 106 116 116 116
49844-132 98 104 116 116 116 108 122 132 117 104 110 105 131 142 83 116 129 50 67 72 7 12 13
49845-1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10 26 26 26
49846-50 50 50 82 82 82 58 58 58 6 6 6 2 2 6 2 2 6 2 2 6 2 2 6
49847-2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 54 54 54 86 86 86 66 66 66
49848-38 38 38 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49849-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49850-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49851-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49852-
49853-0 0 0 1 1 1 6 8 8 15 22 25 26 35 39 36 54 60 53 75 83 59 85 92
49854-59 85 92 48 63 69 15 22 25 12 17 20 52 67 79 94 94 94 132 98 104 132 98 104
49855-117 104 110 108 122 132 108 122 132 115 114 122 105 131 142 77 105 114 59 85 92 36 54 60
49856-7 12 13 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22 50 50 50
49857-78 78 78 34 34 34 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49858-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 70 70 70
49859-78 78 78 46 46 46 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
49860-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49861-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49862-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49863-
49864-0 0 0 15 22 25 29 43 47 36 54 60 42 59 64 42 59 64 48 63 69 21 31 35
49865-6 8 8 29 43 47 36 50 56 43 45 48 79 78 84 132 98 104 165 78 79 132 98 104
49866-108 122 132 117 104 110 117 104 110 108 122 132 77 105 114 73 97 106 95 131 149 78 102 129
49867-36 50 56 0 0 0 0 0 0 0 0 0 6 6 6 18 18 18 42 42 42 82 82 82
49868-26 26 26 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49869-2 2 6 2 2 6 2 2 6 14 14 14 46 46 46 34 34 34 6 6 6 2 2 6
49870-42 42 42 78 78 78 42 42 42 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
49871-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49872-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49873-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49874-
49875-27 40 45 53 75 83 48 63 69 24 31 37 6 8 12 0 0 0 18 25 28 26 35 39
49876-12 17 20 26 35 39 65 78 84 112 81 86 152 81 83 137 83 86 132 98 104 117 104 110
49877-117 104 110 132 98 104 132 98 104 115 114 122 73 97 106 53 75 83 95 131 149 93 124 152
49878-68 78 128 15 22 25 0 0 0 0 0 0 10 10 10 30 30 30 66 66 66 58 58 58
49879-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49880-2 2 6 2 2 6 2 2 6 26 26 26 86 86 86 101 101 101 46 46 46 10 10 10
49881-2 2 6 58 58 58 70 70 70 34 34 34 10 10 10 0 0 0 0 0 0 0 0 0
49882-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49883-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49884-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49885-
49886-36 50 56 21 30 33 4 7 7 0 0 0 1 1 1 17 12 12 69 31 31 68 59 64
49887-57 59 63 21 31 35 32 40 45 86 73 69 152 81 83 152 81 83 117 104 110 132 98 104
49888-152 81 83 132 98 104 108 122 132 77 105 114 77 105 114 93 121 133 95 131 149 93 124 152
49889-95 131 149 53 75 83 11 15 17 0 0 0 14 14 14 42 42 42 86 86 86 10 10 10
49890-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49891-2 2 6 2 2 6 2 2 6 30 30 30 94 94 94 94 94 94 58 58 58 26 26 26
49892-2 2 6 6 6 6 78 78 78 54 54 54 22 22 22 6 6 6 0 0 0 0 0 0
49893-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49894-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49895-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49896-
49897-17 23 26 2 3 3 0 0 0 17 12 12 69 31 31 123 55 55 123 55 55 152 81 83
49898-86 73 69 17 23 26 7 12 13 45 54 57 101 101 101 137 83 86 132 98 104 132 98 104
49899-137 83 86 117 104 110 77 105 114 42 59 64 50 67 72 78 102 129 91 117 157 91 117 157
49900-95 131 149 83 116 129 40 48 73 6 6 6 22 22 22 62 62 62 62 62 62 2 2 6
49901-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49902-2 2 6 2 2 6 2 2 6 26 26 26 54 54 54 38 38 38 18 18 18 10 10 10
49903-2 2 6 2 2 6 34 34 34 82 82 82 38 38 38 14 14 14 0 0 0 0 0 0
49904-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49905-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49906-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49907-
49908-1 1 1 1 2 2 2 3 3 28 12 12 123 55 55 174 79 79 174 79 79 174 79 79
49909-152 81 83 68 59 64 26 35 39 27 40 45 79 78 84 137 83 86 165 78 79 137 83 86
49910-94 94 94 48 63 69 36 50 56 50 67 72 73 97 106 93 121 133 93 124 152 93 124 152
49911-95 131 149 91 118 149 78 102 129 27 40 45 30 30 30 78 78 78 30 30 30 2 2 6
49912-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49913-2 2 6 2 2 6 2 2 6 10 10 10 10 10 10 2 2 6 2 2 6 2 2 6
49914-2 2 6 2 2 6 2 2 6 78 78 78 50 50 50 18 18 18 6 6 6 0 0 0
49915-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49916-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49917-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49918-
49919-4 5 3 24 53 24 19 31 15 8 7 3 90 61 47 165 78 79 174 79 79 174 79 79
49920-174 79 79 137 83 86 60 52 57 7 12 13 17 23 26 70 70 70 132 98 104 112 81 86
49921-79 78 84 31 45 49 15 22 25 53 75 83 91 118 149 86 106 160 91 117 157 93 124 152
49922-91 117 157 93 124 152 95 131 149 53 75 83 50 50 50 86 86 86 14 14 14 2 2 6
49923-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49924-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49925-2 2 6 2 2 6 2 2 6 54 54 54 66 66 66 26 26 26 6 6 6 0 0 0
49926-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49927-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49928-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49929-
49930-19 31 15 34 76 34 34 76 34 19 31 15 28 12 12 123 55 55 174 79 79 174 79 79
49931-174 79 79 165 78 79 112 81 86 32 40 45 15 22 25 38 53 58 65 78 84 29 31 32
49932-21 30 33 42 59 64 60 80 103 78 102 129 87 112 149 84 96 162 91 117 157 93 124 152
49933-91 117 157 93 124 152 93 121 133 59 85 92 57 68 71 82 85 86 2 2 6 2 2 6
49934-2 2 6 6 6 6 10 10 10 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
49935-2 2 6 2 2 6 2 2 6 6 6 6 14 14 14 10 10 10 2 2 6 2 2 6
49936-2 2 6 2 2 6 2 2 6 18 18 18 82 82 82 34 34 34 10 10 10 0 0 0
49937-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49938-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49939-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49940-
49941-34 76 34 40 89 40 40 89 40 34 76 34 8 15 6 48 26 18 123 55 55 174 79 79
49942-174 79 79 174 79 79 137 83 86 68 59 64 32 40 45 21 30 33 31 45 49 21 31 35
49943-12 17 20 48 63 69 78 102 129 81 88 166 84 96 162 91 117 157 93 124 152 91 117 157
49944-93 124 152 95 131 149 83 116 129 59 85 92 57 68 71 86 86 86 2 2 6 2 2 6
49945-6 6 6 6 6 6 22 22 22 34 34 34 6 6 6 2 2 6 2 2 6 2 2 6
49946-2 2 6 2 2 6 18 18 18 34 34 34 10 10 10 50 50 50 22 22 22 2 2 6
49947-2 2 6 2 2 6 2 2 6 10 10 10 86 86 86 42 42 42 14 14 14 0 0 0
49948-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49949-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49950-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49951-
49952-40 89 40 40 89 40 40 89 40 40 89 40 24 53 24 6 6 6 69 31 31 123 55 55
49953-123 55 55 90 61 47 69 31 31 36 32 33 21 31 35 7 12 13 18 25 28 48 63 69
49954-60 80 103 68 78 128 84 101 153 84 96 162 84 96 162 91 117 157 91 117 157 84 96 162
49955-91 117 157 73 97 106 48 63 69 50 67 72 57 59 63 86 86 86 2 2 6 2 2 6
49956-38 38 38 116 116 116 94 94 94 22 22 22 22 22 22 2 2 6 2 2 6 2 2 6
49957-14 14 14 86 86 86 124 131 137 170 170 170 151 151 151 38 38 38 26 26 26 6 6 6
49958-2 2 6 2 2 6 2 2 6 2 2 6 86 86 86 46 46 46 14 14 14 0 0 0
49959-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49960-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49961-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49962-
49963-34 76 34 40 89 40 40 89 40 40 89 40 34 76 34 19 31 15 17 12 12 48 26 18
49964-48 26 18 8 7 3 10 10 22 23 29 47 51 61 92 42 59 64 21 30 33 34 45 54
49965-68 78 128 81 88 166 81 82 173 86 106 160 86 106 160 84 96 162 86 106 160 87 112 149
49966-91 118 149 77 105 114 52 67 79 32 40 45 50 50 50 86 86 86 2 2 6 14 14 14
49967-124 131 137 198 198 198 195 195 195 116 116 116 10 10 10 2 2 6 2 2 6 6 6 6
49968-101 98 89 187 187 187 210 210 210 218 218 218 214 214 214 124 131 137 14 14 14 6 6 6
49969-2 2 6 2 2 6 2 2 6 2 2 6 86 86 86 50 50 50 18 18 18 6 6 6
49970-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49971-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49972-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49973-
49974-19 31 15 34 76 34 40 89 40 40 89 40 40 89 40 24 53 24 8 7 3 0 0 0
49975-6 8 12 28 32 52 51 61 92 54 54 122 74 77 160 68 78 128 26 35 39 6 8 8
49976-34 45 54 68 78 128 84 96 162 86 106 160 86 106 160 81 88 166 84 96 162 87 112 149
49977-73 97 106 36 50 56 33 49 54 18 18 18 46 46 46 86 86 86 2 2 6 54 54 54
49978-218 218 218 195 195 195 226 226 226 246 246 246 58 58 58 2 2 6 2 2 6 30 30 30
49979-210 210 210 253 253 253 170 170 170 124 127 131 221 221 221 234 234 234 74 74 74 2 2 6
49980-2 2 6 2 2 6 2 2 6 2 2 6 70 70 70 58 58 58 22 22 22 6 6 6
49981-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49982-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49983-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49984-
49985-4 5 3 24 53 24 40 89 40 40 89 40 34 76 34 12 22 15 4 5 3 4 5 3
49986-13 17 26 54 54 122 78 78 174 78 78 174 78 78 174 74 77 160 51 61 92 21 31 35
49987-26 35 39 53 75 83 84 101 153 81 82 173 81 88 166 84 101 153 60 80 103 60 80 103
49988-53 75 83 38 53 58 42 59 64 22 22 22 46 46 46 82 82 82 2 2 6 106 106 106
49989-170 170 170 26 26 26 86 86 86 226 226 226 124 127 131 10 10 10 14 14 14 46 46 46
49990-231 231 231 190 190 190 6 6 6 70 70 70 90 90 90 238 238 238 151 151 151 2 2 6
49991-2 2 6 2 2 6 2 2 6 2 2 6 70 70 70 58 58 58 22 22 22 6 6 6
49992-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49993-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49994-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
49995-
49996-1 2 2 8 15 6 24 53 24 34 76 34 19 31 15 8 15 6 63 55 20 63 55 20
49997-18 18 18 40 48 73 74 77 160 78 78 174 78 78 174 81 82 173 74 77 160 52 67 79
49998-17 23 26 21 31 35 60 80 103 81 88 166 74 77 160 78 102 129 36 54 60 12 17 20
49999-42 59 64 48 63 69 21 31 35 18 18 18 42 42 42 86 86 86 6 6 6 116 116 116
50000-106 106 106 6 6 6 70 70 70 151 151 151 124 127 131 18 18 18 38 38 38 54 54 54
50001-221 221 221 106 106 106 2 2 6 14 14 14 46 46 46 190 190 190 198 198 198 2 2 6
50002-2 2 6 2 2 6 2 2 6 2 2 6 74 74 74 62 62 62 22 22 22 6 6 6
50003-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50004-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50005-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50006-
50007-11 15 17 0 0 0 12 22 15 19 31 15 8 15 6 63 55 20 149 139 69 149 139 69
50008-63 55 20 10 10 22 54 54 122 78 78 174 78 78 174 78 78 174 81 82 173 68 78 128
50009-24 31 37 6 6 6 36 50 56 60 80 103 51 61 92 42 59 64 36 50 56 31 45 49
50010-29 43 47 27 40 45 6 8 8 14 14 14 42 42 42 94 94 94 14 14 14 101 101 101
50011-124 127 131 2 2 6 18 18 18 116 116 116 106 107 48 121 92 8 121 92 8 98 70 6
50012-170 170 170 106 106 106 2 2 6 2 2 6 2 2 6 195 195 195 195 195 195 6 6 6
50013-2 2 6 2 2 6 2 2 6 2 2 6 74 74 74 62 62 62 22 22 22 6 6 6
50014-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50015-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50016-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50017-
50018-26 35 39 3 5 6 1 1 1 2 3 3 35 31 12 133 118 54 175 176 80 175 176 80
50019-133 118 54 35 31 12 23 29 47 54 54 122 78 78 174 78 78 174 74 77 160 68 78 128
50020-51 61 92 31 45 49 26 35 39 36 50 56 29 43 47 7 12 13 21 30 33 42 59 64
50021-18 25 28 7 12 13 1 1 1 10 10 10 38 38 38 90 90 90 14 14 14 58 58 58
50022-210 210 210 26 26 26 62 42 6 154 114 10 226 170 11 237 188 10 220 174 15 184 138 11
50023-220 174 15 174 140 55 35 31 12 2 2 6 70 70 70 246 246 246 124 131 137 2 2 6
50024-2 2 6 2 2 6 2 2 6 2 2 6 70 70 70 66 66 66 26 26 26 6 6 6
50025-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50026-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50027-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50028-
50029-27 40 45 17 23 26 2 3 3 1 1 1 56 77 35 165 152 80 175 176 80 175 176 80
50030-175 176 80 106 107 48 22 22 22 28 32 52 54 54 122 54 54 122 51 61 92 28 32 52
50031-20 27 34 31 45 49 11 15 17 7 12 13 36 50 56 31 45 49 29 43 47 36 50 56
50032-6 8 8 0 0 0 0 0 0 10 10 10 38 38 38 86 86 86 14 14 14 10 10 10
50033-195 195 195 198 179 130 192 133 9 220 174 15 239 182 13 237 188 10 232 195 16 239 207 25
50034-237 201 50 241 208 19 232 195 16 184 138 11 198 179 130 208 206 196 42 42 42 2 2 6
50035-2 2 6 2 2 6 2 2 6 2 2 6 50 50 50 74 74 74 30 30 30 6 6 6
50036-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50037-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50038-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50039-
50040-15 22 25 26 35 39 15 22 25 0 0 0 35 31 12 133 118 54 175 176 80 175 176 80
50041-175 176 80 165 152 80 56 77 35 6 8 12 23 29 47 13 17 26 2 2 6 0 0 0
50042-1 2 2 26 35 39 26 35 39 26 35 39 42 59 64 42 59 64 20 29 31 6 8 8
50043-0 0 0 0 0 0 0 0 0 10 10 10 34 34 34 86 86 86 14 14 14 2 2 6
50044-121 92 8 192 133 9 219 162 10 239 182 13 237 188 10 232 195 16 241 208 19 237 201 50
50045-237 201 50 239 207 25 241 208 19 241 208 19 241 208 19 230 187 11 121 92 8 2 2 6
50046-2 2 6 2 2 6 2 2 6 2 2 6 50 50 50 82 82 82 34 34 34 10 10 10
50047-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50048-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50049-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50050-
50051-1 2 2 15 22 25 31 45 49 6 8 12 4 5 3 63 55 20 149 139 69 175 176 80
50052-175 176 80 175 176 80 106 107 48 20 16 6 1 1 1 0 0 0 2 3 3 11 15 17
50053-21 30 33 36 50 56 36 50 56 24 31 37 15 22 25 6 8 8 0 0 0 0 0 0
50054-0 0 0 0 0 0 0 0 0 10 10 10 34 34 34 82 82 82 30 30 30 62 42 6
50055-180 123 7 206 145 10 230 174 11 239 182 13 237 188 10 238 202 15 241 208 19 237 201 50
50056-239 207 25 241 208 19 241 208 19 241 208 19 230 187 11 220 174 15 184 138 11 6 6 6
50057-2 2 6 2 2 6 2 2 6 2 2 6 26 26 26 94 94 94 42 42 42 14 14 14
50058-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50059-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50060-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50061-
50062-0 0 0 1 2 2 29 43 47 26 35 39 3 5 6 8 7 3 106 107 48 165 152 80
50063-175 176 80 149 139 69 63 55 20 4 5 3 2 3 3 12 17 20 26 35 39 26 35 39
50064-17 23 26 7 12 13 6 8 8 3 5 6 1 2 2 0 0 0 0 0 0 0 0 0
50065-0 0 0 0 0 0 0 0 0 10 10 10 30 30 30 78 78 78 50 50 50 104 69 6
50066-192 133 9 216 158 10 236 178 12 237 188 10 232 195 16 241 208 19 237 201 50 237 201 50
50067-241 208 19 241 208 19 241 208 19 204 160 10 200 144 11 216 158 10 156 118 10 2 2 6
50068-2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 90 90 90 54 54 54 18 18 18
50069-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50070-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50071-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50072-
50073-0 0 0 0 0 0 12 17 20 27 40 45 18 25 28 1 1 1 35 31 12 106 107 48
50074-149 139 69 56 77 35 8 7 3 1 2 2 12 17 20 26 35 39 21 31 35 11 15 17
50075-3 5 6 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50076-0 0 0 0 0 0 0 0 0 10 10 10 30 30 30 78 78 78 46 46 46 22 22 22
50077-137 92 6 204 160 10 239 182 13 237 188 10 238 202 15 241 208 19 241 208 19 241 208 19
50078-241 208 19 204 160 10 184 138 11 210 150 10 216 158 10 210 150 10 98 70 6 2 2 6
50079-6 6 6 54 54 54 14 14 14 2 2 6 2 2 6 62 62 62 74 74 74 30 30 30
50080-10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50081-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50082-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50083-
50084-0 0 0 0 0 0 1 1 1 15 22 25 33 49 54 12 17 20 2 3 3 35 31 12
50085-56 77 35 20 16 6 1 1 1 18 25 28 21 31 35 11 15 17 1 1 1 0 0 0
50086-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50087-0 0 0 0 0 0 0 0 0 10 10 10 34 34 34 78 78 78 50 50 50 6 6 6
50088-88 55 22 139 102 15 190 146 13 230 187 11 239 207 25 232 195 16 220 174 15 190 146 13
50089-171 120 8 192 133 9 210 150 10 213 154 11 185 146 40 165 152 80 101 98 89 2 2 6
50090-2 2 6 78 78 78 116 116 116 58 58 58 2 2 6 22 22 22 90 90 90 46 46 46
50091-18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50092-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50093-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50094-
50095-0 0 0 0 0 0 0 0 0 1 1 1 27 40 45 29 43 47 3 5 6 2 3 3
50096-8 7 3 1 1 1 17 23 26 31 45 49 15 22 25 0 0 0 0 0 0 0 0 0
50097-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50098-0 0 0 0 0 0 0 0 0 10 10 10 38 38 38 86 86 86 50 50 50 6 6 6
50099-124 127 131 168 158 138 156 107 11 171 120 8 204 160 10 184 138 11 197 138 11 200 144 11
50100-206 145 10 206 145 10 197 138 11 198 179 130 195 195 195 198 198 198 170 170 170 14 14 14
50101-2 2 6 22 22 22 116 116 116 116 116 116 22 22 22 2 2 6 74 74 74 70 70 70
50102-30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50103-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50104-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50105-
50106-0 0 0 0 0 0 0 0 0 0 0 0 11 15 17 31 45 49 26 35 39 3 5 6
50107-0 0 0 7 12 13 27 40 45 18 25 28 0 0 0 0 0 0 0 0 0 0 0 0
50108-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50109-0 0 0 0 0 0 6 6 6 18 18 18 50 50 50 101 101 101 26 26 26 10 10 10
50110-124 131 137 190 190 190 168 158 138 156 107 11 197 138 11 200 144 11 197 138 11 192 133 9
50111-180 123 7 185 146 40 198 179 130 187 187 187 202 202 202 221 221 221 214 214 214 66 66 66
50112-2 2 6 2 2 6 50 50 50 62 62 62 6 6 6 2 2 6 10 10 10 90 90 90
50113-50 50 50 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50114-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50115-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50116-
50117-0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 15 22 25 36 54 60 18 25 28
50118-0 0 0 21 30 33 27 40 45 2 3 3 0 0 0 0 0 0 0 0 0 0 0 0
50119-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50120-0 0 0 0 0 0 10 10 10 34 34 34 74 74 74 74 74 74 2 2 6 6 6 6
50121-151 151 151 198 198 198 190 190 190 168 158 138 148 132 55 156 107 11 156 107 11 169 125 40
50122-168 158 138 187 187 187 190 190 190 210 210 210 246 246 246 253 253 253 253 253 253 180 180 180
50123-6 6 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 62 62 62
50124-74 74 74 34 34 34 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50125-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50126-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50127-
50128-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 27 40 45 35 52 58
50129-18 25 28 35 52 58 17 23 26 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50130-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50131-0 0 0 10 10 10 22 22 22 54 54 54 94 94 94 18 18 18 2 2 6 46 46 46
50132-234 234 234 221 221 221 190 190 190 190 190 190 190 190 190 187 187 187 187 187 187 190 190 190
50133-190 190 190 195 195 195 214 214 214 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
50134-82 82 82 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 14 14 14
50135-86 86 86 54 54 54 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
50136-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50137-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50138-
50139-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 7 12 13 33 49 54
50140-52 72 81 36 54 60 6 8 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50141-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50142-6 6 6 18 18 18 46 46 46 90 90 90 46 46 46 18 18 18 6 6 6 180 180 180
50143-253 253 253 246 246 246 202 202 202 190 190 190 190 190 190 190 190 190 190 190 190 190 190 190
50144-202 202 202 231 231 231 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50145-202 202 202 14 14 14 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50146-42 42 42 86 86 86 42 42 42 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
50147-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50148-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50149-
50150-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 12 17 20
50151-36 54 60 29 43 47 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50152-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50153-14 14 14 38 38 38 74 74 74 66 66 66 2 2 6 6 6 6 90 90 90 250 250 250
50154-253 253 253 253 253 253 238 238 238 198 198 198 190 190 190 190 190 190 195 195 195 221 221 221
50155-246 246 246 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50156-253 253 253 82 82 82 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50157-2 2 6 78 78 78 70 70 70 34 34 34 14 14 14 6 6 6 0 0 0 0 0 0
50158-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50159-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50160-
50161-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50162-21 30 33 35 52 58 6 8 12 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50163-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 14 14 14
50164-34 34 34 66 66 66 78 78 78 6 6 6 2 2 6 18 18 18 218 218 218 253 253 253
50165-253 253 253 253 253 253 253 253 253 246 246 246 226 226 226 231 231 231 246 246 246 253 253 253
50166-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50167-253 253 253 180 180 180 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50168-2 2 6 18 18 18 90 90 90 62 62 62 30 30 30 10 10 10 0 0 0 0 0 0
50169-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50170-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50171-
50172-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50173-12 17 20 36 54 60 29 43 47 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50174-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10 26 26 26
50175-58 58 58 90 90 90 18 18 18 2 2 6 2 2 6 106 106 106 253 253 253 253 253 253
50176-253 253 253 253 253 253 253 253 253 253 253 253 250 250 250 253 253 253 253 253 253 253 253 253
50177-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50178-253 253 253 231 231 231 18 18 18 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50179-2 2 6 2 2 6 18 18 18 94 94 94 54 54 54 26 26 26 10 10 10 0 0 0
50180-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50181-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50182-
50183-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50184-0 0 0 21 30 33 35 52 58 6 8 12 0 0 0 0 0 0 0 0 0 0 0 0
50185-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22 50 50 50
50186-90 90 90 26 26 26 2 2 6 2 2 6 14 14 14 195 195 195 250 250 250 253 253 253
50187-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50188-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50189-250 250 250 242 242 242 54 54 54 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50190-2 2 6 2 2 6 2 2 6 38 38 38 86 86 86 50 50 50 22 22 22 6 6 6
50191-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50192-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50193-
50194-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50195-0 0 0 0 0 0 12 17 20 36 54 60 29 43 47 0 0 0 0 0 0 0 0 0
50196-0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 14 14 14 38 38 38 82 82 82
50197-34 34 34 2 2 6 2 2 6 2 2 6 42 42 42 195 195 195 246 246 246 253 253 253
50198-253 253 253 253 253 253 253 253 253 250 250 250 242 242 242 242 242 242 250 250 250 253 253 253
50199-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 250 250 250 246 246 246 238 238 238
50200-226 226 226 231 231 231 101 101 101 6 6 6 2 2 6 2 2 6 2 2 6 2 2 6
50201-2 2 6 2 2 6 2 2 6 2 2 6 38 38 38 82 82 82 42 42 42 14 14 14
50202-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50203-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50204-
50205-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50206-0 0 0 0 0 0 0 0 0 21 30 33 35 52 58 6 8 12 0 0 0 0 0 0
50207-0 0 0 0 0 0 0 0 0 0 0 0 10 10 10 26 26 26 62 62 62 66 66 66
50208-2 2 6 2 2 6 2 2 6 6 6 6 70 70 70 170 170 170 202 202 202 234 234 234
50209-246 246 246 250 250 250 250 250 250 238 238 238 226 226 226 231 231 231 238 238 238 250 250 250
50210-250 250 250 250 250 250 246 246 246 231 231 231 214 214 214 202 202 202 202 202 202 202 202 202
50211-198 198 198 202 202 202 180 180 180 18 18 18 2 2 6 2 2 6 2 2 6 2 2 6
50212-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 62 62 62 66 66 66 30 30 30
50213-10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50214-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50215-
50216-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50217-0 0 0 0 0 0 0 0 0 12 17 20 36 54 60 29 43 47 0 0 0 0 0 0
50218-0 0 0 0 0 0 0 0 0 0 0 0 14 14 14 42 42 42 82 82 82 18 18 18
50219-2 2 6 2 2 6 2 2 6 10 10 10 94 94 94 180 180 180 218 218 218 242 242 242
50220-250 250 250 253 253 253 253 253 253 250 250 250 234 234 234 253 253 253 253 253 253 253 253 253
50221-253 253 253 253 253 253 253 253 253 246 246 246 238 238 238 226 226 226 210 210 210 202 202 202
50222-195 195 195 195 195 195 210 210 210 151 151 151 6 6 6 14 14 14 50 50 50 14 14 14
50223-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 86 86 86 46 46 46
50224-18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50225-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50226-
50227-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50228-0 0 0 0 0 0 0 0 0 0 0 0 21 30 33 35 52 58 6 8 12 0 0 0
50229-0 0 0 0 0 0 0 0 0 6 6 6 22 22 22 54 54 54 70 70 70 2 2 6
50230-2 2 6 10 10 10 2 2 6 22 22 22 170 170 170 231 231 231 250 250 250 253 253 253
50231-253 253 253 253 253 253 253 253 253 250 250 250 242 242 242 253 253 253 253 253 253 253 253 253
50232-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 246 246 246
50233-231 231 231 202 202 202 198 198 198 226 226 226 94 94 94 2 2 6 6 6 6 38 38 38
50234-30 30 30 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 62 62 62 66 66 66
50235-26 26 26 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50236-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50237-
50238-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50239-0 0 0 0 0 0 0 0 0 0 0 0 6 8 8 33 49 54 29 43 47 6 8 12
50240-0 0 0 0 0 0 0 0 0 10 10 10 30 30 30 74 74 74 50 50 50 2 2 6
50241-26 26 26 26 26 26 2 2 6 106 106 106 238 238 238 253 253 253 253 253 253 253 253 253
50242-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50243-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50244-253 253 253 246 246 246 218 218 218 202 202 202 210 210 210 14 14 14 2 2 6 2 2 6
50245-30 30 30 22 22 22 2 2 6 2 2 6 2 2 6 2 2 6 18 18 18 86 86 86
50246-42 42 42 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50247-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50248-
50249-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50250-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 12 17 20 33 49 54 17 23 26
50251-0 0 0 0 0 0 0 0 0 14 14 14 42 42 42 90 90 90 22 22 22 2 2 6
50252-42 42 42 2 2 6 18 18 18 218 218 218 253 253 253 253 253 253 253 253 253 253 253 253
50253-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50254-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50255-253 253 253 253 253 253 250 250 250 221 221 221 218 218 218 101 101 101 2 2 6 14 14 14
50256-18 18 18 38 38 38 10 10 10 2 2 6 2 2 6 2 2 6 2 2 6 78 78 78
50257-58 58 58 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50258-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50259-
50260-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50261-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 15 22 25 36 54 60
50262-0 0 0 0 0 0 0 0 0 18 18 18 54 54 54 82 82 82 2 2 6 26 26 26
50263-22 22 22 2 2 6 124 127 131 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50264-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50265-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50266-253 253 253 253 253 253 253 253 253 250 250 250 238 238 238 198 198 198 6 6 6 38 38 38
50267-58 58 58 26 26 26 38 38 38 2 2 6 2 2 6 2 2 6 2 2 6 46 46 46
50268-78 78 78 30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50269-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50270-
50271-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50272-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 21 30 33
50273-36 54 60 0 0 0 0 0 0 30 30 30 74 74 74 58 58 58 2 2 6 42 42 42
50274-2 2 6 22 22 22 231 231 231 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50275-253 253 253 253 253 253 253 253 253 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253
50276-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50277-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 246 246 246 46 46 46 38 38 38
50278-42 42 42 14 14 14 38 38 38 14 14 14 2 2 6 2 2 6 2 2 6 6 6 6
50279-86 86 86 46 46 46 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50280-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50281-
50282-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50283-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50284-36 54 60 0 0 0 0 0 0 42 42 42 90 90 90 18 18 18 18 18 18 26 26 26
50285-2 2 6 116 116 116 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50286-253 253 253 253 253 253 250 250 250 238 238 238 253 253 253 253 253 253 253 253 253 253 253 253
50287-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50288-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 94 94 94 6 6 6
50289-2 2 6 2 2 6 10 10 10 34 34 34 2 2 6 2 2 6 2 2 6 2 2 6
50290-74 74 74 58 58 58 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
50291-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50292-
50293-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50294-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50295-0 0 0 36 54 60 26 26 26 66 66 66 82 82 82 2 2 6 38 38 38 6 6 6
50296-14 14 14 210 210 210 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50297-253 253 253 253 253 253 246 246 246 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
50298-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50299-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 151 151 151 2 2 6
50300-2 2 6 2 2 6 2 2 6 46 46 46 2 2 6 2 2 6 2 2 6 2 2 6
50301-42 42 42 74 74 74 30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0
50302-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50303-
50304-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50305-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50306-6 6 6 36 54 60 21 30 33 90 90 90 26 26 26 6 6 6 42 42 42 2 2 6
50307-74 74 74 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50308-253 253 253 253 253 253 242 242 242 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
50309-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50310-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 180 180 180 2 2 6
50311-2 2 6 2 2 6 2 2 6 46 46 46 2 2 6 2 2 6 2 2 6 2 2 6
50312-10 10 10 86 86 86 38 38 38 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0
50313-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50314-
50315-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50316-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50317-10 10 10 26 26 26 36 54 60 82 82 82 2 2 6 22 22 22 18 18 18 2 2 6
50318-151 151 151 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50319-253 253 253 253 253 253 234 234 234 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
50320-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50321-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 202 202 202 2 2 6
50322-2 2 6 2 2 6 2 2 6 38 38 38 2 2 6 2 2 6 2 2 6 2 2 6
50323-6 6 6 86 86 86 46 46 46 14 14 14 0 0 0 0 0 0 0 0 0 0 0 0
50324-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50325-
50326-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50327-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50328-18 18 18 46 46 46 86 86 86 36 54 60 2 2 6 34 34 34 10 10 10 6 6 6
50329-210 210 210 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50330-253 253 253 253 253 253 234 234 234 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
50331-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50332-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 221 221 221 6 6 6
50333-2 2 6 2 2 6 6 6 6 30 30 30 2 2 6 2 2 6 2 2 6 2 2 6
50334-2 2 6 82 82 82 54 54 54 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
50335-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50336-
50337-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50338-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50339-26 26 26 66 66 66 62 62 62 2 2 6 2 2 6 38 38 38 10 10 10 26 26 26
50340-238 238 238 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50341-253 253 253 253 253 253 231 231 231 238 238 238 253 253 253 253 253 253 253 253 253 253 253 253
50342-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50343-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 231 231 231 6 6 6
50344-2 2 6 2 2 6 10 10 10 30 30 30 2 2 6 2 2 6 2 2 6 2 2 6
50345-2 2 6 66 66 66 58 58 58 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0
50346-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50347-
50348-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50349-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50350-38 38 38 78 78 78 6 6 6 2 2 6 2 2 6 46 46 46 14 14 14 42 42 42
50351-246 246 246 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50352-253 253 253 253 253 253 231 231 231 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
50353-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50354-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 234 234 234 10 10 10
50355-2 2 6 2 2 6 22 22 22 14 14 14 2 2 6 2 2 6 2 2 6 2 2 6
50356-2 2 6 66 66 66 62 62 62 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0
50357-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50358-
50359-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50360-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 18 18 18
50361-50 50 50 74 74 74 2 2 6 2 2 6 14 14 14 70 70 70 34 34 34 62 62 62
50362-250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50363-253 253 253 253 253 253 231 231 231 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253
50364-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50365-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 234 234 234 14 14 14
50366-2 2 6 2 2 6 30 30 30 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50367-2 2 6 66 66 66 62 62 62 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0
50368-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50369-
50370-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50371-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 18 18 18
50372-54 54 54 62 62 62 2 2 6 2 2 6 2 2 6 30 30 30 46 46 46 70 70 70
50373-250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50374-253 253 253 253 253 253 231 231 231 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253
50375-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50376-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 226 226 226 10 10 10
50377-2 2 6 6 6 6 30 30 30 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50378-2 2 6 66 66 66 58 58 58 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0
50379-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50380-
50381-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50382-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22
50383-58 58 58 62 62 62 2 2 6 2 2 6 2 2 6 2 2 6 30 30 30 78 78 78
50384-250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50385-253 253 253 253 253 253 231 231 231 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253
50386-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50387-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 202 202 202 2 2 6
50388-22 22 22 34 34 34 20 16 6 22 22 22 26 26 26 18 18 18 6 6 6 2 2 6
50389-2 2 6 82 82 82 54 54 54 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
50390-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50391-
50392-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50393-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 26 26 26
50394-62 62 62 106 106 106 63 55 20 184 138 11 204 160 10 121 92 8 6 6 6 62 62 62
50395-238 238 238 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50396-253 253 253 253 253 253 231 231 231 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253
50397-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50398-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 151 151 151 18 18 18
50399-14 14 14 2 2 6 2 2 6 2 2 6 6 6 6 18 18 18 66 66 66 38 38 38
50400-6 6 6 94 94 94 50 50 50 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
50401-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50402-
50403-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50404-0 0 0 0 0 0 0 0 0 6 6 6 10 10 10 10 10 10 18 18 18 38 38 38
50405-78 78 78 138 132 106 216 158 10 242 186 14 246 190 14 246 190 14 156 118 10 10 10 10
50406-90 90 90 238 238 238 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50407-253 253 253 253 253 253 231 231 231 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253
50408-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50409-253 253 253 253 253 253 253 253 253 246 230 190 214 187 87 214 187 87 185 146 40 35 31 12
50410-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 38 38 38 46 46 46
50411-26 26 26 106 106 106 54 54 54 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0
50412-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50413-
50414-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50415-0 0 0 6 6 6 14 14 14 22 22 22 30 30 30 38 38 38 50 50 50 70 70 70
50416-106 106 106 185 146 40 226 170 11 242 186 14 246 190 14 246 190 14 246 190 14 154 114 10
50417-6 6 6 74 74 74 226 226 226 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50418-253 253 253 253 253 253 231 231 231 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253
50419-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50420-253 253 253 253 253 253 253 253 253 237 201 50 241 196 14 241 208 19 232 195 16 35 31 12
50421-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 30 30 30 26 26 26
50422-204 160 10 165 152 80 66 66 66 26 26 26 6 6 6 0 0 0 0 0 0 0 0 0
50423-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50424-
50425-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50426-6 6 6 18 18 18 38 38 38 58 58 58 78 78 78 86 86 86 101 101 101 124 127 131
50427-174 140 55 210 150 10 234 174 13 246 186 14 246 190 14 246 190 14 246 190 14 237 188 10
50428-98 70 6 2 2 6 46 46 46 198 198 198 253 253 253 253 253 253 253 253 253 253 253 253
50429-253 253 253 253 253 253 234 234 234 242 242 242 253 253 253 253 253 253 253 253 253 253 253 253
50430-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50431-253 253 253 253 253 253 253 253 253 214 187 87 242 186 14 241 196 14 204 160 10 20 16 6
50432-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 6 6 6 121 92 8
50433-238 202 15 232 195 16 82 82 82 34 34 34 10 10 10 0 0 0 0 0 0 0 0 0
50434-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50435-
50436-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50437-14 14 14 38 38 38 70 70 70 148 132 55 185 146 40 200 144 11 197 138 11 197 138 11
50438-213 154 11 226 170 11 242 186 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50439-220 174 15 35 31 12 2 2 6 22 22 22 151 151 151 250 250 250 253 253 253 253 253 253
50440-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50441-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50442-253 253 253 250 250 250 242 242 242 214 187 87 239 182 13 237 188 10 213 154 11 35 31 12
50443-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 62 42 6 220 174 15
50444-237 188 10 237 188 10 113 101 86 42 42 42 14 14 14 0 0 0 0 0 0 0 0 0
50445-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50446-
50447-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50448-22 22 22 54 54 54 148 132 55 213 154 11 226 170 11 230 174 11 226 170 11 226 170 11
50449-236 178 12 242 186 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50450-241 196 14 184 138 11 10 10 10 2 2 6 6 6 6 116 116 116 242 242 242 253 253 253
50451-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50452-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50453-253 253 253 231 231 231 198 198 198 213 164 39 236 178 12 236 178 12 210 150 10 137 92 6
50454-20 16 6 2 2 6 2 2 6 2 2 6 6 6 6 62 42 6 200 144 11 236 178 12
50455-239 182 13 239 182 13 124 112 88 58 58 58 22 22 22 6 6 6 0 0 0 0 0 0
50456-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50457-
50458-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50459-30 30 30 70 70 70 169 125 40 226 170 11 239 182 13 242 186 14 242 186 14 246 186 14
50460-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50461-246 190 14 232 195 16 98 70 6 2 2 6 2 2 6 2 2 6 66 66 66 221 221 221
50462-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50463-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50464-253 253 253 202 202 202 198 198 198 213 164 39 230 174 11 230 174 11 216 158 10 192 133 9
50465-163 110 8 120 80 7 98 70 6 120 80 7 167 114 7 197 138 11 226 170 11 239 182 13
50466-242 186 14 242 186 14 165 152 80 78 78 78 34 34 34 14 14 14 6 6 6 0 0 0
50467-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50468-
50469-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50470-30 30 30 78 78 78 185 146 40 226 170 11 239 182 13 246 190 14 246 190 14 246 190 14
50471-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50472-246 190 14 241 196 14 204 160 10 20 16 6 2 2 6 2 2 6 2 2 6 38 38 38
50473-218 218 218 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50474-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50475-250 250 250 202 202 202 198 198 198 213 164 39 226 170 11 236 178 12 224 166 10 210 150 10
50476-200 144 11 197 138 11 192 133 9 197 138 11 210 150 10 226 170 11 242 186 14 246 190 14
50477-246 190 14 246 186 14 220 174 15 124 112 88 62 62 62 30 30 30 14 14 14 6 6 6
50478-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50479-
50480-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50481-30 30 30 78 78 78 174 140 55 224 166 10 239 182 13 246 190 14 246 190 14 246 190 14
50482-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50483-246 190 14 246 190 14 241 196 14 139 102 15 2 2 6 2 2 6 2 2 6 2 2 6
50484-78 78 78 250 250 250 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50485-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50486-250 250 250 214 214 214 198 198 198 185 146 40 219 162 10 236 178 12 234 174 13 224 166 10
50487-216 158 10 213 154 11 213 154 11 216 158 10 226 170 11 239 182 13 246 190 14 246 190 14
50488-246 190 14 246 190 14 242 186 14 213 164 39 101 101 101 58 58 58 30 30 30 14 14 14
50489-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50490-
50491-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50492-30 30 30 74 74 74 174 140 55 216 158 10 236 178 12 246 190 14 246 190 14 246 190 14
50493-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50494-246 190 14 246 190 14 241 196 14 230 187 11 62 42 6 2 2 6 2 2 6 2 2 6
50495-22 22 22 238 238 238 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50496-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50497-253 253 253 226 226 226 187 187 187 169 125 40 216 158 10 236 178 12 239 182 13 236 178 12
50498-230 174 11 226 170 11 226 170 11 230 174 11 236 178 12 242 186 14 246 190 14 246 190 14
50499-246 190 14 246 190 14 246 186 14 239 182 13 213 164 39 106 106 106 66 66 66 34 34 34
50500-14 14 14 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50501-
50502-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50503-26 26 26 70 70 70 149 139 69 213 154 11 236 178 12 246 190 14 246 190 14 246 190 14
50504-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50505-246 190 14 246 190 14 246 190 14 241 196 14 190 146 13 20 16 6 2 2 6 2 2 6
50506-46 46 46 246 246 246 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50507-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50508-253 253 253 221 221 221 86 86 86 156 107 11 216 158 10 236 178 12 242 186 14 246 186 14
50509-242 186 14 239 182 13 239 182 13 242 186 14 242 186 14 246 186 14 246 190 14 246 190 14
50510-246 190 14 246 190 14 246 190 14 246 190 14 242 186 14 220 174 15 149 139 69 66 66 66
50511-30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50512-
50513-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50514-26 26 26 70 70 70 149 139 69 210 150 10 236 178 12 246 190 14 246 190 14 246 190 14
50515-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50516-246 190 14 246 190 14 246 190 14 246 190 14 232 195 16 121 92 8 34 34 34 106 106 106
50517-221 221 221 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50518-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50519-242 242 242 82 82 82 20 16 6 163 110 8 216 158 10 236 178 12 242 186 14 246 190 14
50520-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50521-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 242 186 14 149 139 69
50522-46 46 46 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50523-
50524-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 10 10 10
50525-30 30 30 78 78 78 149 139 69 210 150 10 236 178 12 246 186 14 246 190 14 246 190 14
50526-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50527-246 190 14 246 190 14 246 190 14 246 190 14 241 196 14 220 174 15 198 179 130 253 253 253
50528-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50529-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 218 218 218
50530-58 58 58 2 2 6 20 16 6 167 114 7 216 158 10 236 178 12 246 186 14 246 190 14
50531-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50532-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 186 14 242 186 14 185 146 40
50533-54 54 54 22 22 22 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50534-
50535-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 14 14 14
50536-38 38 38 86 86 86 169 125 40 213 154 11 236 178 12 246 186 14 246 190 14 246 190 14
50537-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50538-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 232 195 16 190 146 13 214 214 214
50539-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50540-253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 250 250 250 170 170 170 26 26 26
50541-2 2 6 2 2 6 35 31 12 163 110 8 219 162 10 239 182 13 246 186 14 246 190 14
50542-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50543-246 190 14 246 190 14 246 190 14 246 190 14 246 186 14 236 178 12 224 166 10 149 139 69
50544-46 46 46 18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50545-
50546-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 18 18 18
50547-50 50 50 113 101 86 192 133 9 224 166 10 242 186 14 246 190 14 246 190 14 246 190 14
50548-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50549-246 190 14 246 190 14 246 190 14 246 190 14 242 186 14 230 187 11 204 160 10 133 118 54
50550-226 226 226 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253 253
50551-253 253 253 253 253 253 253 253 253 253 253 253 198 198 198 66 66 66 2 2 6 2 2 6
50552-2 2 6 2 2 6 62 42 6 156 107 11 219 162 10 239 182 13 246 186 14 246 190 14
50553-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50554-246 190 14 246 190 14 246 190 14 242 186 14 234 174 13 213 154 11 148 132 55 66 66 66
50555-30 30 30 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50556-
50557-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22
50558-58 58 58 148 132 55 206 145 10 234 174 13 242 186 14 246 186 14 246 190 14 246 190 14
50559-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50560-246 190 14 246 190 14 246 190 14 246 190 14 246 186 14 236 178 12 204 160 10 163 110 8
50561-62 42 6 124 131 137 218 218 218 250 250 250 253 253 253 253 253 253 253 253 253 250 250 250
50562-242 242 242 210 210 210 151 151 151 66 66 66 6 6 6 2 2 6 2 2 6 2 2 6
50563-2 2 6 2 2 6 62 42 6 163 110 8 216 158 10 236 178 12 246 190 14 246 190 14
50564-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50565-246 190 14 239 182 13 230 174 11 216 158 10 185 146 40 124 112 88 70 70 70 38 38 38
50566-18 18 18 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50567-
50568-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 22 22 22
50569-62 62 62 169 125 40 206 145 10 224 166 10 236 178 12 239 182 13 242 186 14 242 186 14
50570-246 186 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 246 190 14
50571-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 236 178 12 216 158 10 171 120 8
50572-85 57 6 2 2 6 6 6 6 30 30 30 54 54 54 62 62 62 50 50 50 38 38 38
50573-14 14 14 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50574-2 2 6 6 6 6 85 57 6 167 114 7 213 154 11 236 178 12 246 190 14 246 190 14
50575-246 190 14 246 190 14 246 190 14 246 190 14 246 190 14 242 186 14 239 182 13 239 182 13
50576-230 174 11 210 150 10 174 140 55 124 112 88 82 82 82 54 54 54 34 34 34 18 18 18
50577-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50578-
50579-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 18 18 18
50580-50 50 50 169 125 40 192 133 9 200 144 11 216 158 10 219 162 10 224 166 10 226 170 11
50581-230 174 11 236 178 12 239 182 13 239 182 13 242 186 14 246 186 14 246 190 14 246 190 14
50582-246 190 14 246 190 14 246 190 14 246 190 14 246 186 14 230 174 11 210 150 10 163 110 8
50583-104 69 6 10 10 10 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50584-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50585-2 2 6 6 6 6 85 57 6 167 114 7 206 145 10 230 174 11 242 186 14 246 190 14
50586-246 190 14 246 190 14 246 186 14 242 186 14 239 182 13 230 174 11 224 166 10 213 154 11
50587-169 125 40 124 112 88 86 86 86 58 58 58 38 38 38 22 22 22 10 10 10 6 6 6
50588-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50589-
50590-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 14 14 14
50591-34 34 34 70 70 70 133 118 54 169 125 40 167 114 7 180 123 7 192 133 9 197 138 11
50592-200 144 11 206 145 10 213 154 11 219 162 10 224 166 10 230 174 11 239 182 13 242 186 14
50593-246 186 14 246 186 14 246 186 14 246 186 14 239 182 13 216 158 10 184 138 11 152 99 6
50594-104 69 6 20 16 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50595-2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6 2 2 6
50596-2 2 6 6 6 6 85 57 6 152 99 6 192 133 9 219 162 10 236 178 12 239 182 13
50597-246 186 14 242 186 14 239 182 13 236 178 12 224 166 10 206 145 10 192 133 9 148 132 55
50598-94 94 94 62 62 62 42 42 42 22 22 22 14 14 14 6 6 6 0 0 0 0 0 0
50599-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50600-
50601-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50602-18 18 18 34 34 34 58 58 58 78 78 78 101 98 89 124 112 88 133 118 54 156 107 11
50603-163 110 8 167 114 7 171 120 8 180 123 7 184 138 11 197 138 11 210 150 10 219 162 10
50604-226 170 11 236 178 12 236 178 12 234 174 13 219 162 10 197 138 11 163 110 8 134 84 6
50605-85 57 6 10 10 10 2 2 6 2 2 6 18 18 18 38 38 38 38 38 38 38 38 38
50606-38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 38 26 26 26 2 2 6
50607-2 2 6 6 6 6 62 42 6 137 92 6 171 120 8 200 144 11 219 162 10 230 174 11
50608-234 174 13 230 174 11 219 162 10 210 150 10 192 133 9 163 110 8 124 112 88 82 82 82
50609-50 50 50 30 30 30 14 14 14 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
50610-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50611-
50612-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50613-6 6 6 14 14 14 22 22 22 34 34 34 42 42 42 58 58 58 74 74 74 86 86 86
50614-101 98 89 113 101 86 133 118 54 121 92 8 137 92 6 152 99 6 163 110 8 180 123 7
50615-184 138 11 197 138 11 206 145 10 200 144 11 180 123 7 156 107 11 134 84 6 104 69 6
50616-62 42 6 54 54 54 106 106 106 101 98 89 86 86 86 82 82 82 78 78 78 78 78 78
50617-78 78 78 78 78 78 78 78 78 78 78 78 78 78 78 82 82 82 86 86 86 94 94 94
50618-106 106 106 101 101 101 90 61 47 120 80 7 156 107 11 180 123 7 192 133 9 200 144 11
50619-206 145 10 200 144 11 192 133 9 171 120 8 139 102 15 113 101 86 70 70 70 42 42 42
50620-22 22 22 10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50621-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50622-
50623-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50624-0 0 0 0 0 0 6 6 6 10 10 10 14 14 14 22 22 22 30 30 30 38 38 38
50625-50 50 50 62 62 62 74 74 74 90 90 90 101 98 89 113 101 86 121 92 8 120 80 7
50626-137 92 6 152 99 6 152 99 6 152 99 6 134 84 6 120 80 7 98 70 6 88 55 22
50627-101 98 89 82 82 82 58 58 58 46 46 46 38 38 38 34 34 34 34 34 34 34 34 34
50628-34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 34 38 38 38 42 42 42
50629-54 54 54 82 82 82 94 86 71 85 57 6 134 84 6 156 107 11 167 114 7 171 120 8
50630-171 120 8 167 114 7 152 99 6 121 92 8 101 98 89 62 62 62 34 34 34 18 18 18
50631-6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50632-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50633-
50634-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50635-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 6 6 6 10 10 10
50636-18 18 18 22 22 22 30 30 30 42 42 42 50 50 50 66 66 66 86 86 86 101 98 89
50637-94 86 71 98 70 6 104 69 6 104 69 6 104 69 6 85 57 6 88 55 22 90 90 90
50638-62 62 62 38 38 38 22 22 22 14 14 14 10 10 10 10 10 10 10 10 10 10 10 10
50639-10 10 10 10 10 10 6 6 6 10 10 10 10 10 10 10 10 10 10 10 10 14 14 14
50640-22 22 22 42 42 42 70 70 70 94 86 71 85 57 6 104 69 6 120 80 7 137 92 6
50641-134 84 6 120 80 7 94 86 71 86 86 86 58 58 58 30 30 30 14 14 14 6 6 6
50642-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50643-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50644-
50645-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50646-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50647-0 0 0 6 6 6 10 10 10 14 14 14 18 18 18 26 26 26 38 38 38 54 54 54
50648-70 70 70 86 86 86 94 86 71 94 86 71 94 86 71 86 86 86 74 74 74 50 50 50
50649-30 30 30 14 14 14 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50650-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50651-6 6 6 18 18 18 34 34 34 58 58 58 82 82 82 94 86 71 94 86 71 94 86 71
50652-94 86 71 94 86 71 74 74 74 50 50 50 26 26 26 14 14 14 6 6 6 0 0 0
50653-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50654-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50655-
50656-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50657-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50658-0 0 0 0 0 0 0 0 0 0 0 0 6 6 6 6 6 6 14 14 14 18 18 18
50659-30 30 30 38 38 38 46 46 46 54 54 54 50 50 50 42 42 42 30 30 30 18 18 18
50660-10 10 10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50661-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50662-0 0 0 6 6 6 14 14 14 26 26 26 38 38 38 50 50 50 58 58 58 58 58 58
50663-54 54 54 42 42 42 30 30 30 18 18 18 10 10 10 0 0 0 0 0 0 0 0 0
50664-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50665-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50666-
50667-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50668-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50669-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 6 6
50670-6 6 6 10 10 10 14 14 14 18 18 18 18 18 18 14 14 14 10 10 10 6 6 6
50671-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50672-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50673-0 0 0 0 0 0 0 0 0 6 6 6 14 14 14 18 18 18 22 22 22 22 22 22
50674-18 18 18 14 14 14 10 10 10 6 6 6 0 0 0 0 0 0 0 0 0 0 0 0
50675-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50676-0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
50677-
50678+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50679+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50680+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50681+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50682+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50683+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50684+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50685+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50686+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50687+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50688+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50689+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50690+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50691+4 4 4 4 4 4
50692+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50693+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50694+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50695+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50696+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50697+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50698+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50699+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50700+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50701+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50702+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50703+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50704+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50705+4 4 4 4 4 4
50706+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50707+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50708+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50709+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50710+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50711+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50712+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50713+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50714+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50715+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50716+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50717+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50718+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50719+4 4 4 4 4 4
50720+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50721+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50722+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50723+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50724+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50725+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50726+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50727+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50728+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50729+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50730+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50731+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50732+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50733+4 4 4 4 4 4
50734+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50735+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50736+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50737+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50738+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50739+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50740+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50741+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50742+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50743+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50744+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50745+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50746+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50747+4 4 4 4 4 4
50748+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50749+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50750+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50751+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50752+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50753+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50754+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50755+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50756+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50757+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50758+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50759+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50760+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50761+4 4 4 4 4 4
50762+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50763+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50764+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50765+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50766+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
50767+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
50768+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50769+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50770+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50771+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
50772+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
50773+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
50774+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50775+4 4 4 4 4 4
50776+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50777+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50778+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50779+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50780+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
50781+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
50782+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50783+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50784+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50785+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
50786+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
50787+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
50788+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50789+4 4 4 4 4 4
50790+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50791+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50792+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50793+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50794+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
50795+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
50796+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
50797+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50798+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50799+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
50800+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
50801+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
50802+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
50803+4 4 4 4 4 4
50804+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50805+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50806+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50807+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
50808+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
50809+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
50810+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
50811+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50812+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
50813+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
50814+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
50815+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
50816+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
50817+4 4 4 4 4 4
50818+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50819+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50820+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50821+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
50822+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
50823+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
50824+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
50825+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
50826+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
50827+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
50828+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
50829+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
50830+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
50831+4 4 4 4 4 4
50832+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50833+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50834+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
50835+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
50836+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
50837+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
50838+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
50839+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
50840+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
50841+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
50842+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
50843+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
50844+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
50845+4 4 4 4 4 4
50846+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50847+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50848+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
50849+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
50850+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
50851+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
50852+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
50853+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
50854+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
50855+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
50856+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
50857+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
50858+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
50859+4 4 4 4 4 4
50860+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50861+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50862+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
50863+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
50864+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
50865+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
50866+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
50867+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
50868+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
50869+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
50870+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
50871+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
50872+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
50873+4 4 4 4 4 4
50874+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50875+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50876+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
50877+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
50878+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
50879+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
50880+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
50881+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
50882+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
50883+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
50884+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
50885+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
50886+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
50887+4 4 4 4 4 4
50888+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50889+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50890+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
50891+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
50892+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
50893+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
50894+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
50895+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
50896+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
50897+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
50898+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
50899+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
50900+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
50901+4 4 4 4 4 4
50902+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50903+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
50904+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
50905+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
50906+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
50907+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
50908+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
50909+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
50910+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
50911+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
50912+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
50913+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
50914+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
50915+4 4 4 4 4 4
50916+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
50917+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
50918+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
50919+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
50920+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
50921+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
50922+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
50923+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
50924+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
50925+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
50926+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
50927+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
50928+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
50929+0 0 0 4 4 4
50930+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
50931+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
50932+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
50933+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
50934+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
50935+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
50936+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
50937+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
50938+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
50939+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
50940+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
50941+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
50942+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
50943+2 0 0 0 0 0
50944+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
50945+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
50946+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
50947+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
50948+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
50949+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
50950+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
50951+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
50952+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
50953+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
50954+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
50955+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
50956+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
50957+37 38 37 0 0 0
50958+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
50959+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
50960+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
50961+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
50962+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
50963+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
50964+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
50965+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
50966+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
50967+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
50968+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
50969+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
50970+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
50971+85 115 134 4 0 0
50972+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
50973+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
50974+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
50975+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
50976+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
50977+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
50978+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
50979+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
50980+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
50981+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
50982+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
50983+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
50984+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
50985+60 73 81 4 0 0
50986+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
50987+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
50988+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
50989+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
50990+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
50991+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
50992+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
50993+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
50994+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
50995+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
50996+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
50997+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
50998+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
50999+16 19 21 4 0 0
51000+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
51001+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
51002+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
51003+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
51004+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
51005+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
51006+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
51007+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
51008+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
51009+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
51010+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
51011+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
51012+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
51013+4 0 0 4 3 3
51014+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
51015+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
51016+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
51017+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
51018+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
51019+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
51020+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
51021+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
51022+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
51023+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
51024+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
51025+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
51026+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
51027+3 2 2 4 4 4
51028+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
51029+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
51030+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
51031+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
51032+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
51033+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
51034+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
51035+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
51036+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
51037+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
51038+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
51039+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
51040+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
51041+4 4 4 4 4 4
51042+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
51043+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
51044+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
51045+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
51046+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
51047+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
51048+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
51049+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
51050+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
51051+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
51052+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
51053+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
51054+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
51055+4 4 4 4 4 4
51056+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
51057+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
51058+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
51059+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
51060+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
51061+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
51062+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
51063+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
51064+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
51065+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
51066+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
51067+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
51068+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
51069+5 5 5 5 5 5
51070+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
51071+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
51072+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
51073+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
51074+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
51075+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
51076+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
51077+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
51078+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
51079+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
51080+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
51081+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
51082+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
51083+5 5 5 4 4 4
51084+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
51085+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
51086+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
51087+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
51088+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
51089+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
51090+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
51091+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
51092+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
51093+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
51094+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
51095+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
51096+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51097+4 4 4 4 4 4
51098+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
51099+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
51100+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
51101+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
51102+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
51103+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
51104+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
51105+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
51106+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
51107+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
51108+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
51109+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
51110+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51111+4 4 4 4 4 4
51112+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
51113+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
51114+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
51115+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
51116+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
51117+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
51118+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
51119+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
51120+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
51121+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
51122+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
51123+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51124+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51125+4 4 4 4 4 4
51126+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
51127+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
51128+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
51129+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
51130+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
51131+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
51132+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
51133+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
51134+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
51135+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
51136+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
51137+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51138+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51139+4 4 4 4 4 4
51140+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
51141+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
51142+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
51143+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
51144+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
51145+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
51146+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
51147+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
51148+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
51149+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
51150+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51151+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51152+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51153+4 4 4 4 4 4
51154+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
51155+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
51156+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
51157+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
51158+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
51159+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
51160+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
51161+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
51162+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
51163+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
51164+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
51165+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51166+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51167+4 4 4 4 4 4
51168+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
51169+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
51170+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
51171+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
51172+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
51173+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
51174+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
51175+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
51176+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
51177+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
51178+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
51179+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51180+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51181+4 4 4 4 4 4
51182+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
51183+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
51184+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
51185+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
51186+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
51187+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
51188+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
51189+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
51190+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
51191+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
51192+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51193+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51194+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51195+4 4 4 4 4 4
51196+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
51197+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
51198+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
51199+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
51200+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51201+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
51202+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
51203+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
51204+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
51205+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
51206+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51207+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51208+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51209+4 4 4 4 4 4
51210+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
51211+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
51212+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
51213+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
51214+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51215+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
51216+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
51217+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
51218+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
51219+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
51220+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51221+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51222+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51223+4 4 4 4 4 4
51224+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
51225+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
51226+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
51227+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
51228+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51229+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
51230+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
51231+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
51232+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
51233+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51234+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51235+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51236+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51237+4 4 4 4 4 4
51238+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
51239+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
51240+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
51241+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
51242+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
51243+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
51244+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
51245+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
51246+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
51247+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51248+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51249+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51250+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51251+4 4 4 4 4 4
51252+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
51253+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
51254+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
51255+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
51256+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51257+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
51258+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
51259+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
51260+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
51261+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51262+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51263+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51264+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51265+4 4 4 4 4 4
51266+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
51267+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
51268+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
51269+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
51270+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
51271+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
51272+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
51273+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
51274+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
51275+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51276+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51277+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51278+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51279+4 4 4 4 4 4
51280+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
51281+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
51282+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
51283+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
51284+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
51285+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
51286+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
51287+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
51288+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
51289+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51290+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51291+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51292+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51293+4 4 4 4 4 4
51294+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
51295+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
51296+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
51297+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
51298+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
51299+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
51300+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
51301+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
51302+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
51303+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51304+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51305+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51306+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51307+4 4 4 4 4 4
51308+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
51309+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
51310+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
51311+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
51312+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
51313+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
51314+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
51315+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
51316+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
51317+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51318+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51319+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51320+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51321+4 4 4 4 4 4
51322+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
51323+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
51324+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
51325+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
51326+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
51327+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
51328+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
51329+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
51330+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
51331+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51332+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51333+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51334+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51335+4 4 4 4 4 4
51336+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
51337+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
51338+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
51339+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
51340+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
51341+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
51342+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
51343+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
51344+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
51345+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51346+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51347+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51348+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51349+4 4 4 4 4 4
51350+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
51351+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
51352+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
51353+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
51354+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
51355+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
51356+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51357+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
51358+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
51359+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51360+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51361+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51362+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51363+4 4 4 4 4 4
51364+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
51365+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
51366+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
51367+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
51368+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
51369+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
51370+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
51371+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
51372+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
51373+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51374+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51375+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51376+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51377+4 4 4 4 4 4
51378+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
51379+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
51380+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
51381+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
51382+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
51383+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
51384+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
51385+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
51386+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
51387+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51388+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51389+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51390+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51391+4 4 4 4 4 4
51392+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
51393+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
51394+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
51395+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
51396+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
51397+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
51398+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
51399+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
51400+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
51401+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51402+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51403+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51404+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51405+4 4 4 4 4 4
51406+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
51407+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
51408+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
51409+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
51410+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
51411+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
51412+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
51413+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
51414+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
51415+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51416+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51417+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51418+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51419+4 4 4 4 4 4
51420+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
51421+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
51422+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
51423+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
51424+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
51425+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
51426+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
51427+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
51428+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
51429+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
51430+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51431+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51432+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51433+4 4 4 4 4 4
51434+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
51435+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
51436+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
51437+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
51438+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
51439+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
51440+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
51441+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
51442+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
51443+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
51444+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51445+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51446+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51447+4 4 4 4 4 4
51448+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
51449+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
51450+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
51451+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
51452+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
51453+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
51454+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
51455+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
51456+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
51457+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
51458+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51459+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51460+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51461+4 4 4 4 4 4
51462+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
51463+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
51464+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
51465+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
51466+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
51467+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
51468+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51469+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
51470+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
51471+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
51472+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
51473+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51474+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51475+4 4 4 4 4 4
51476+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
51477+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
51478+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
51479+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
51480+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
51481+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
51482+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
51483+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
51484+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
51485+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
51486+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51487+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51488+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51489+4 4 4 4 4 4
51490+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
51491+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
51492+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
51493+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
51494+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
51495+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
51496+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
51497+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
51498+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
51499+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
51500+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51501+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51502+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51503+4 4 4 4 4 4
51504+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
51505+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
51506+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
51507+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
51508+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
51509+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
51510+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
51511+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
51512+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
51513+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
51514+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51515+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51516+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51517+4 4 4 4 4 4
51518+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
51519+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
51520+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
51521+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
51522+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
51523+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
51524+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
51525+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
51526+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
51527+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
51528+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51529+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51530+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51531+4 4 4 4 4 4
51532+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
51533+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
51534+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
51535+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
51536+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
51537+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
51538+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
51539+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
51540+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
51541+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
51542+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51543+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51544+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51545+4 4 4 4 4 4
51546+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
51547+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
51548+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
51549+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
51550+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
51551+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
51552+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
51553+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
51554+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
51555+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51556+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51557+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51558+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51559+4 4 4 4 4 4
51560+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
51561+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
51562+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
51563+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
51564+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
51565+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
51566+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
51567+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
51568+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
51569+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51570+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51571+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51572+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51573+4 4 4 4 4 4
51574+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
51575+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
51576+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
51577+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
51578+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
51579+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
51580+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
51581+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
51582+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51583+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51584+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51585+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51586+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51587+4 4 4 4 4 4
51588+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
51589+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
51590+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
51591+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
51592+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
51593+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
51594+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
51595+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
51596+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51597+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51598+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51599+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51600+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51601+4 4 4 4 4 4
51602+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
51603+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
51604+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
51605+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
51606+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
51607+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
51608+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
51609+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
51610+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51611+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51612+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51613+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51614+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51615+4 4 4 4 4 4
51616+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
51617+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
51618+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
51619+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
51620+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
51621+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
51622+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
51623+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
51624+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51625+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51626+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51627+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51628+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51629+4 4 4 4 4 4
51630+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51631+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
51632+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
51633+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
51634+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
51635+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
51636+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
51637+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
51638+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51639+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51640+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51641+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51642+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51643+4 4 4 4 4 4
51644+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51645+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
51646+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
51647+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
51648+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
51649+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
51650+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
51651+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
51652+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51653+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51654+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51655+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51656+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51657+4 4 4 4 4 4
51658+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51659+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51660+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
51661+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
51662+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
51663+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
51664+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
51665+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
51666+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51667+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51668+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51669+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51670+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51671+4 4 4 4 4 4
51672+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51673+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51674+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
51675+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
51676+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
51677+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
51678+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
51679+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51680+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51681+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51682+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51683+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51684+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51685+4 4 4 4 4 4
51686+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51687+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51688+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51689+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
51690+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
51691+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
51692+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
51693+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51694+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51695+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51696+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51697+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51698+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51699+4 4 4 4 4 4
51700+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51701+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51702+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51703+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
51704+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
51705+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
51706+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
51707+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51708+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51709+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51710+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51711+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51712+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51713+4 4 4 4 4 4
51714+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51715+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51716+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51717+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
51718+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
51719+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
51720+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
51721+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51722+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51723+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51724+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51725+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51726+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51727+4 4 4 4 4 4
51728+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51729+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51730+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51731+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
51732+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
51733+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
51734+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
51735+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51736+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51737+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51738+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51739+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51740+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51741+4 4 4 4 4 4
51742+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51743+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51744+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51745+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51746+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
51747+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
51748+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
51749+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51750+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51751+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51752+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51753+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51754+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51755+4 4 4 4 4 4
51756+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51757+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51758+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51759+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51760+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
51761+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
51762+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51763+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51764+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51765+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51766+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51767+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51768+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51769+4 4 4 4 4 4
51770+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51771+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51772+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51773+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51774+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
51775+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
51776+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51777+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51778+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51779+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51780+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51781+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51782+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51783+4 4 4 4 4 4
51784+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51785+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51786+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51787+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51788+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
51789+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
51790+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51791+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51792+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51793+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51794+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51795+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51796+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
51797+4 4 4 4 4 4
51798diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
51799index fe92eed..106e085 100644
51800--- a/drivers/video/mb862xx/mb862xxfb_accel.c
51801+++ b/drivers/video/mb862xx/mb862xxfb_accel.c
51802@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
51803 struct mb862xxfb_par *par = info->par;
51804
51805 if (info->var.bits_per_pixel == 32) {
51806- info->fbops->fb_fillrect = cfb_fillrect;
51807- info->fbops->fb_copyarea = cfb_copyarea;
51808- info->fbops->fb_imageblit = cfb_imageblit;
51809+ pax_open_kernel();
51810+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
51811+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
51812+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
51813+ pax_close_kernel();
51814 } else {
51815 outreg(disp, GC_L0EM, 3);
51816- info->fbops->fb_fillrect = mb86290fb_fillrect;
51817- info->fbops->fb_copyarea = mb86290fb_copyarea;
51818- info->fbops->fb_imageblit = mb86290fb_imageblit;
51819+ pax_open_kernel();
51820+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
51821+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
51822+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
51823+ pax_close_kernel();
51824 }
51825 outreg(draw, GDC_REG_DRAW_BASE, 0);
51826 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
51827diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
51828index ff22871..b129bed 100644
51829--- a/drivers/video/nvidia/nvidia.c
51830+++ b/drivers/video/nvidia/nvidia.c
51831@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
51832 info->fix.line_length = (info->var.xres_virtual *
51833 info->var.bits_per_pixel) >> 3;
51834 if (info->var.accel_flags) {
51835- info->fbops->fb_imageblit = nvidiafb_imageblit;
51836- info->fbops->fb_fillrect = nvidiafb_fillrect;
51837- info->fbops->fb_copyarea = nvidiafb_copyarea;
51838- info->fbops->fb_sync = nvidiafb_sync;
51839+ pax_open_kernel();
51840+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
51841+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
51842+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
51843+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
51844+ pax_close_kernel();
51845 info->pixmap.scan_align = 4;
51846 info->flags &= ~FBINFO_HWACCEL_DISABLED;
51847 info->flags |= FBINFO_READS_FAST;
51848 NVResetGraphics(info);
51849 } else {
51850- info->fbops->fb_imageblit = cfb_imageblit;
51851- info->fbops->fb_fillrect = cfb_fillrect;
51852- info->fbops->fb_copyarea = cfb_copyarea;
51853- info->fbops->fb_sync = NULL;
51854+ pax_open_kernel();
51855+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
51856+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
51857+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
51858+ *(void **)&info->fbops->fb_sync = NULL;
51859+ pax_close_kernel();
51860 info->pixmap.scan_align = 1;
51861 info->flags |= FBINFO_HWACCEL_DISABLED;
51862 info->flags &= ~FBINFO_READS_FAST;
51863@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
51864 info->pixmap.size = 8 * 1024;
51865 info->pixmap.flags = FB_PIXMAP_SYSTEM;
51866
51867- if (!hwcur)
51868- info->fbops->fb_cursor = NULL;
51869+ if (!hwcur) {
51870+ pax_open_kernel();
51871+ *(void **)&info->fbops->fb_cursor = NULL;
51872+ pax_close_kernel();
51873+ }
51874
51875 info->var.accel_flags = (!noaccel);
51876
51877diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
51878index 05c2dc3..ea1f391 100644
51879--- a/drivers/video/s1d13xxxfb.c
51880+++ b/drivers/video/s1d13xxxfb.c
51881@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
51882
51883 switch(prod_id) {
51884 case S1D13506_PROD_ID: /* activate acceleration */
51885- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
51886- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
51887+ pax_open_kernel();
51888+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
51889+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
51890+ pax_close_kernel();
51891 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
51892 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
51893 break;
51894diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
51895index e188ada..aac63c8 100644
51896--- a/drivers/video/smscufx.c
51897+++ b/drivers/video/smscufx.c
51898@@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
51899 fb_deferred_io_cleanup(info);
51900 kfree(info->fbdefio);
51901 info->fbdefio = NULL;
51902- info->fbops->fb_mmap = ufx_ops_mmap;
51903+ pax_open_kernel();
51904+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
51905+ pax_close_kernel();
51906 }
51907
51908 pr_debug("released /dev/fb%d user=%d count=%d",
51909diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
51910index d2e5bc3..4cb05d1 100644
51911--- a/drivers/video/udlfb.c
51912+++ b/drivers/video/udlfb.c
51913@@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
51914 dlfb_urb_completion(urb);
51915
51916 error:
51917- atomic_add(bytes_sent, &dev->bytes_sent);
51918- atomic_add(bytes_identical, &dev->bytes_identical);
51919- atomic_add(width*height*2, &dev->bytes_rendered);
51920+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
51921+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
51922+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
51923 end_cycles = get_cycles();
51924- atomic_add(((unsigned int) ((end_cycles - start_cycles)
51925+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
51926 >> 10)), /* Kcycles */
51927 &dev->cpu_kcycles_used);
51928
51929@@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
51930 dlfb_urb_completion(urb);
51931
51932 error:
51933- atomic_add(bytes_sent, &dev->bytes_sent);
51934- atomic_add(bytes_identical, &dev->bytes_identical);
51935- atomic_add(bytes_rendered, &dev->bytes_rendered);
51936+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
51937+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
51938+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
51939 end_cycles = get_cycles();
51940- atomic_add(((unsigned int) ((end_cycles - start_cycles)
51941+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
51942 >> 10)), /* Kcycles */
51943 &dev->cpu_kcycles_used);
51944 }
51945@@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
51946 fb_deferred_io_cleanup(info);
51947 kfree(info->fbdefio);
51948 info->fbdefio = NULL;
51949- info->fbops->fb_mmap = dlfb_ops_mmap;
51950+ pax_open_kernel();
51951+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
51952+ pax_close_kernel();
51953 }
51954
51955 pr_warn("released /dev/fb%d user=%d count=%d\n",
51956@@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
51957 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51958 struct dlfb_data *dev = fb_info->par;
51959 return snprintf(buf, PAGE_SIZE, "%u\n",
51960- atomic_read(&dev->bytes_rendered));
51961+ atomic_read_unchecked(&dev->bytes_rendered));
51962 }
51963
51964 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
51965@@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
51966 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51967 struct dlfb_data *dev = fb_info->par;
51968 return snprintf(buf, PAGE_SIZE, "%u\n",
51969- atomic_read(&dev->bytes_identical));
51970+ atomic_read_unchecked(&dev->bytes_identical));
51971 }
51972
51973 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
51974@@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
51975 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51976 struct dlfb_data *dev = fb_info->par;
51977 return snprintf(buf, PAGE_SIZE, "%u\n",
51978- atomic_read(&dev->bytes_sent));
51979+ atomic_read_unchecked(&dev->bytes_sent));
51980 }
51981
51982 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
51983@@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
51984 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51985 struct dlfb_data *dev = fb_info->par;
51986 return snprintf(buf, PAGE_SIZE, "%u\n",
51987- atomic_read(&dev->cpu_kcycles_used));
51988+ atomic_read_unchecked(&dev->cpu_kcycles_used));
51989 }
51990
51991 static ssize_t edid_show(
51992@@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
51993 struct fb_info *fb_info = dev_get_drvdata(fbdev);
51994 struct dlfb_data *dev = fb_info->par;
51995
51996- atomic_set(&dev->bytes_rendered, 0);
51997- atomic_set(&dev->bytes_identical, 0);
51998- atomic_set(&dev->bytes_sent, 0);
51999- atomic_set(&dev->cpu_kcycles_used, 0);
52000+ atomic_set_unchecked(&dev->bytes_rendered, 0);
52001+ atomic_set_unchecked(&dev->bytes_identical, 0);
52002+ atomic_set_unchecked(&dev->bytes_sent, 0);
52003+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
52004
52005 return count;
52006 }
52007diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
52008index 7aec6f3..e3b2d55 100644
52009--- a/drivers/video/uvesafb.c
52010+++ b/drivers/video/uvesafb.c
52011@@ -19,6 +19,7 @@
52012 #include <linux/io.h>
52013 #include <linux/mutex.h>
52014 #include <linux/slab.h>
52015+#include <linux/moduleloader.h>
52016 #include <video/edid.h>
52017 #include <video/uvesafb.h>
52018 #ifdef CONFIG_X86
52019@@ -566,10 +567,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
52020 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
52021 par->pmi_setpal = par->ypan = 0;
52022 } else {
52023+
52024+#ifdef CONFIG_PAX_KERNEXEC
52025+#ifdef CONFIG_MODULES
52026+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
52027+#endif
52028+ if (!par->pmi_code) {
52029+ par->pmi_setpal = par->ypan = 0;
52030+ return 0;
52031+ }
52032+#endif
52033+
52034 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
52035 + task->t.regs.edi);
52036+
52037+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52038+ pax_open_kernel();
52039+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
52040+ pax_close_kernel();
52041+
52042+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
52043+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
52044+#else
52045 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
52046 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
52047+#endif
52048+
52049 printk(KERN_INFO "uvesafb: protected mode interface info at "
52050 "%04x:%04x\n",
52051 (u16)task->t.regs.es, (u16)task->t.regs.edi);
52052@@ -814,13 +837,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
52053 par->ypan = ypan;
52054
52055 if (par->pmi_setpal || par->ypan) {
52056+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
52057 if (__supported_pte_mask & _PAGE_NX) {
52058 par->pmi_setpal = par->ypan = 0;
52059 printk(KERN_WARNING "uvesafb: NX protection is active, "
52060 "better not use the PMI.\n");
52061- } else {
52062+ } else
52063+#endif
52064 uvesafb_vbe_getpmi(task, par);
52065- }
52066 }
52067 #else
52068 /* The protected mode interface is not available on non-x86. */
52069@@ -1454,8 +1478,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
52070 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
52071
52072 /* Disable blanking if the user requested so. */
52073- if (!blank)
52074- info->fbops->fb_blank = NULL;
52075+ if (!blank) {
52076+ pax_open_kernel();
52077+ *(void **)&info->fbops->fb_blank = NULL;
52078+ pax_close_kernel();
52079+ }
52080
52081 /*
52082 * Find out how much IO memory is required for the mode with
52083@@ -1531,8 +1558,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
52084 info->flags = FBINFO_FLAG_DEFAULT |
52085 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
52086
52087- if (!par->ypan)
52088- info->fbops->fb_pan_display = NULL;
52089+ if (!par->ypan) {
52090+ pax_open_kernel();
52091+ *(void **)&info->fbops->fb_pan_display = NULL;
52092+ pax_close_kernel();
52093+ }
52094 }
52095
52096 static void uvesafb_init_mtrr(struct fb_info *info)
52097@@ -1796,6 +1826,11 @@ out:
52098 if (par->vbe_modes)
52099 kfree(par->vbe_modes);
52100
52101+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52102+ if (par->pmi_code)
52103+ module_free_exec(NULL, par->pmi_code);
52104+#endif
52105+
52106 framebuffer_release(info);
52107 return err;
52108 }
52109@@ -1823,6 +1858,12 @@ static int uvesafb_remove(struct platform_device *dev)
52110 kfree(par->vbe_state_orig);
52111 if (par->vbe_state_saved)
52112 kfree(par->vbe_state_saved);
52113+
52114+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52115+ if (par->pmi_code)
52116+ module_free_exec(NULL, par->pmi_code);
52117+#endif
52118+
52119 }
52120
52121 framebuffer_release(info);
52122diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
52123index 501b340..d80aa17 100644
52124--- a/drivers/video/vesafb.c
52125+++ b/drivers/video/vesafb.c
52126@@ -9,6 +9,7 @@
52127 */
52128
52129 #include <linux/module.h>
52130+#include <linux/moduleloader.h>
52131 #include <linux/kernel.h>
52132 #include <linux/errno.h>
52133 #include <linux/string.h>
52134@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
52135 static int vram_total __initdata; /* Set total amount of memory */
52136 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
52137 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
52138-static void (*pmi_start)(void) __read_mostly;
52139-static void (*pmi_pal) (void) __read_mostly;
52140+static void (*pmi_start)(void) __read_only;
52141+static void (*pmi_pal) (void) __read_only;
52142 static int depth __read_mostly;
52143 static int vga_compat __read_mostly;
52144 /* --------------------------------------------------------------------- */
52145@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
52146 unsigned int size_vmode;
52147 unsigned int size_remap;
52148 unsigned int size_total;
52149+ void *pmi_code = NULL;
52150
52151 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
52152 return -ENODEV;
52153@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
52154 size_remap = size_total;
52155 vesafb_fix.smem_len = size_remap;
52156
52157-#ifndef __i386__
52158- screen_info.vesapm_seg = 0;
52159-#endif
52160-
52161 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
52162 printk(KERN_WARNING
52163 "vesafb: cannot reserve video memory at 0x%lx\n",
52164@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
52165 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
52166 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
52167
52168+#ifdef __i386__
52169+
52170+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52171+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
52172+ if (!pmi_code)
52173+#elif !defined(CONFIG_PAX_KERNEXEC)
52174+ if (0)
52175+#endif
52176+
52177+#endif
52178+ screen_info.vesapm_seg = 0;
52179+
52180 if (screen_info.vesapm_seg) {
52181- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
52182- screen_info.vesapm_seg,screen_info.vesapm_off);
52183+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
52184+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
52185 }
52186
52187 if (screen_info.vesapm_seg < 0xc000)
52188@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
52189
52190 if (ypan || pmi_setpal) {
52191 unsigned short *pmi_base;
52192+
52193 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
52194- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
52195- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
52196+
52197+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52198+ pax_open_kernel();
52199+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
52200+#else
52201+ pmi_code = pmi_base;
52202+#endif
52203+
52204+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
52205+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
52206+
52207+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52208+ pmi_start = ktva_ktla(pmi_start);
52209+ pmi_pal = ktva_ktla(pmi_pal);
52210+ pax_close_kernel();
52211+#endif
52212+
52213 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
52214 if (pmi_base[3]) {
52215 printk(KERN_INFO "vesafb: pmi: ports = ");
52216@@ -472,8 +498,11 @@ static int __init vesafb_probe(struct platform_device *dev)
52217 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
52218 (ypan ? FBINFO_HWACCEL_YPAN : 0);
52219
52220- if (!ypan)
52221- info->fbops->fb_pan_display = NULL;
52222+ if (!ypan) {
52223+ pax_open_kernel();
52224+ *(void **)&info->fbops->fb_pan_display = NULL;
52225+ pax_close_kernel();
52226+ }
52227
52228 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
52229 err = -ENOMEM;
52230@@ -488,6 +517,11 @@ static int __init vesafb_probe(struct platform_device *dev)
52231 info->node, info->fix.id);
52232 return 0;
52233 err:
52234+
52235+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
52236+ module_free_exec(NULL, pmi_code);
52237+#endif
52238+
52239 if (info->screen_base)
52240 iounmap(info->screen_base);
52241 framebuffer_release(info);
52242diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
52243index 88714ae..16c2e11 100644
52244--- a/drivers/video/via/via_clock.h
52245+++ b/drivers/video/via/via_clock.h
52246@@ -56,7 +56,7 @@ struct via_clock {
52247
52248 void (*set_engine_pll_state)(u8 state);
52249 void (*set_engine_pll)(struct via_pll_config config);
52250-};
52251+} __no_const;
52252
52253
52254 static inline u32 get_pll_internal_frequency(u32 ref_freq,
52255diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
52256index fef20db..d28b1ab 100644
52257--- a/drivers/xen/xenfs/xenstored.c
52258+++ b/drivers/xen/xenfs/xenstored.c
52259@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
52260 static int xsd_kva_open(struct inode *inode, struct file *file)
52261 {
52262 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
52263+#ifdef CONFIG_GRKERNSEC_HIDESYM
52264+ NULL);
52265+#else
52266 xen_store_interface);
52267+#endif
52268+
52269 if (!file->private_data)
52270 return -ENOMEM;
52271 return 0;
52272diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
52273index 9ff073f..05cef23 100644
52274--- a/fs/9p/vfs_addr.c
52275+++ b/fs/9p/vfs_addr.c
52276@@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
52277
52278 retval = v9fs_file_write_internal(inode,
52279 v9inode->writeback_fid,
52280- (__force const char __user *)buffer,
52281+ (const char __force_user *)buffer,
52282 len, &offset, 0);
52283 if (retval > 0)
52284 retval = 0;
52285diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
52286index 25b018e..b941525 100644
52287--- a/fs/9p/vfs_inode.c
52288+++ b/fs/9p/vfs_inode.c
52289@@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
52290 void
52291 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
52292 {
52293- char *s = nd_get_link(nd);
52294+ const char *s = nd_get_link(nd);
52295
52296 p9_debug(P9_DEBUG_VFS, " %s %s\n",
52297 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
52298diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
52299index 370b24c..ff0be7b 100644
52300--- a/fs/Kconfig.binfmt
52301+++ b/fs/Kconfig.binfmt
52302@@ -103,7 +103,7 @@ config HAVE_AOUT
52303
52304 config BINFMT_AOUT
52305 tristate "Kernel support for a.out and ECOFF binaries"
52306- depends on HAVE_AOUT
52307+ depends on HAVE_AOUT && BROKEN
52308 ---help---
52309 A.out (Assembler.OUTput) is a set of formats for libraries and
52310 executables used in the earliest versions of UNIX. Linux used
52311diff --git a/fs/afs/inode.c b/fs/afs/inode.c
52312index 789bc25..fafaeea 100644
52313--- a/fs/afs/inode.c
52314+++ b/fs/afs/inode.c
52315@@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
52316 struct afs_vnode *vnode;
52317 struct super_block *sb;
52318 struct inode *inode;
52319- static atomic_t afs_autocell_ino;
52320+ static atomic_unchecked_t afs_autocell_ino;
52321
52322 _enter("{%x:%u},%*.*s,",
52323 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
52324@@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
52325 data.fid.unique = 0;
52326 data.fid.vnode = 0;
52327
52328- inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
52329+ inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
52330 afs_iget5_autocell_test, afs_iget5_set,
52331 &data);
52332 if (!inode) {
52333diff --git a/fs/aio.c b/fs/aio.c
52334index 9b5ca11..c530886 100644
52335--- a/fs/aio.c
52336+++ b/fs/aio.c
52337@@ -162,7 +162,7 @@ static int aio_setup_ring(struct kioctx *ctx)
52338 size += sizeof(struct io_event) * nr_events;
52339 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
52340
52341- if (nr_pages < 0)
52342+ if (nr_pages <= 0)
52343 return -EINVAL;
52344
52345 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
52346@@ -952,6 +952,7 @@ static ssize_t aio_rw_vect_retry(struct kiocb *iocb, int rw, aio_rw_op *rw_op)
52347 static ssize_t aio_setup_vectored_rw(int rw, struct kiocb *kiocb, bool compat)
52348 {
52349 ssize_t ret;
52350+ struct iovec iovstack;
52351
52352 kiocb->ki_nr_segs = kiocb->ki_nbytes;
52353
52354@@ -959,17 +960,22 @@ static ssize_t aio_setup_vectored_rw(int rw, struct kiocb *kiocb, bool compat)
52355 if (compat)
52356 ret = compat_rw_copy_check_uvector(rw,
52357 (struct compat_iovec __user *)kiocb->ki_buf,
52358- kiocb->ki_nr_segs, 1, &kiocb->ki_inline_vec,
52359+ kiocb->ki_nr_segs, 1, &iovstack,
52360 &kiocb->ki_iovec);
52361 else
52362 #endif
52363 ret = rw_copy_check_uvector(rw,
52364 (struct iovec __user *)kiocb->ki_buf,
52365- kiocb->ki_nr_segs, 1, &kiocb->ki_inline_vec,
52366+ kiocb->ki_nr_segs, 1, &iovstack,
52367 &kiocb->ki_iovec);
52368 if (ret < 0)
52369 return ret;
52370
52371+ if (kiocb->ki_iovec == &iovstack) {
52372+ kiocb->ki_inline_vec = iovstack;
52373+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
52374+ }
52375+
52376 /* ki_nbytes now reflect bytes instead of segs */
52377 kiocb->ki_nbytes = ret;
52378 return 0;
52379diff --git a/fs/attr.c b/fs/attr.c
52380index 1449adb..a2038c2 100644
52381--- a/fs/attr.c
52382+++ b/fs/attr.c
52383@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
52384 unsigned long limit;
52385
52386 limit = rlimit(RLIMIT_FSIZE);
52387+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
52388 if (limit != RLIM_INFINITY && offset > limit)
52389 goto out_sig;
52390 if (offset > inode->i_sb->s_maxbytes)
52391diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
52392index 3db70da..7aeec5b 100644
52393--- a/fs/autofs4/waitq.c
52394+++ b/fs/autofs4/waitq.c
52395@@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
52396 {
52397 unsigned long sigpipe, flags;
52398 mm_segment_t fs;
52399- const char *data = (const char *)addr;
52400+ const char __user *data = (const char __force_user *)addr;
52401 ssize_t wr = 0;
52402
52403 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
52404@@ -346,6 +346,10 @@ static int validate_request(struct autofs_wait_queue **wait,
52405 return 1;
52406 }
52407
52408+#ifdef CONFIG_GRKERNSEC_HIDESYM
52409+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
52410+#endif
52411+
52412 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
52413 enum autofs_notify notify)
52414 {
52415@@ -379,7 +383,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
52416
52417 /* If this is a direct mount request create a dummy name */
52418 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
52419+#ifdef CONFIG_GRKERNSEC_HIDESYM
52420+ /* this name does get written to userland via autofs4_write() */
52421+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
52422+#else
52423 qstr.len = sprintf(name, "%p", dentry);
52424+#endif
52425 else {
52426 qstr.len = autofs4_getpath(sbi, dentry, &name);
52427 if (!qstr.len) {
52428diff --git a/fs/befs/endian.h b/fs/befs/endian.h
52429index 2722387..c8dd2a7 100644
52430--- a/fs/befs/endian.h
52431+++ b/fs/befs/endian.h
52432@@ -11,7 +11,7 @@
52433
52434 #include <asm/byteorder.h>
52435
52436-static inline u64
52437+static inline u64 __intentional_overflow(-1)
52438 fs64_to_cpu(const struct super_block *sb, fs64 n)
52439 {
52440 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
52441@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
52442 return (__force fs64)cpu_to_be64(n);
52443 }
52444
52445-static inline u32
52446+static inline u32 __intentional_overflow(-1)
52447 fs32_to_cpu(const struct super_block *sb, fs32 n)
52448 {
52449 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
52450diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
52451index e9c75e2..1baece1 100644
52452--- a/fs/befs/linuxvfs.c
52453+++ b/fs/befs/linuxvfs.c
52454@@ -514,7 +514,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
52455 {
52456 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
52457 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
52458- char *link = nd_get_link(nd);
52459+ const char *link = nd_get_link(nd);
52460 if (!IS_ERR(link))
52461 kfree(link);
52462 }
52463diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
52464index 89dec7f..361b0d75 100644
52465--- a/fs/binfmt_aout.c
52466+++ b/fs/binfmt_aout.c
52467@@ -16,6 +16,7 @@
52468 #include <linux/string.h>
52469 #include <linux/fs.h>
52470 #include <linux/file.h>
52471+#include <linux/security.h>
52472 #include <linux/stat.h>
52473 #include <linux/fcntl.h>
52474 #include <linux/ptrace.h>
52475@@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
52476 #endif
52477 # define START_STACK(u) ((void __user *)u.start_stack)
52478
52479+ memset(&dump, 0, sizeof(dump));
52480+
52481 fs = get_fs();
52482 set_fs(KERNEL_DS);
52483 has_dumped = 1;
52484@@ -69,10 +72,12 @@ static int aout_core_dump(struct coredump_params *cprm)
52485
52486 /* If the size of the dump file exceeds the rlimit, then see what would happen
52487 if we wrote the stack, but not the data area. */
52488+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
52489 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
52490 dump.u_dsize = 0;
52491
52492 /* Make sure we have enough room to write the stack and data areas. */
52493+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
52494 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
52495 dump.u_ssize = 0;
52496
52497@@ -233,6 +238,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
52498 rlim = rlimit(RLIMIT_DATA);
52499 if (rlim >= RLIM_INFINITY)
52500 rlim = ~0;
52501+
52502+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
52503 if (ex.a_data + ex.a_bss > rlim)
52504 return -ENOMEM;
52505
52506@@ -265,6 +272,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
52507
52508 install_exec_creds(bprm);
52509
52510+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
52511+ current->mm->pax_flags = 0UL;
52512+#endif
52513+
52514+#ifdef CONFIG_PAX_PAGEEXEC
52515+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
52516+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
52517+
52518+#ifdef CONFIG_PAX_EMUTRAMP
52519+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
52520+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
52521+#endif
52522+
52523+#ifdef CONFIG_PAX_MPROTECT
52524+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
52525+ current->mm->pax_flags |= MF_PAX_MPROTECT;
52526+#endif
52527+
52528+ }
52529+#endif
52530+
52531 if (N_MAGIC(ex) == OMAGIC) {
52532 unsigned long text_addr, map_size;
52533 loff_t pos;
52534@@ -322,7 +350,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
52535 }
52536
52537 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
52538- PROT_READ | PROT_WRITE | PROT_EXEC,
52539+ PROT_READ | PROT_WRITE,
52540 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
52541 fd_offset + ex.a_text);
52542 if (error != N_DATADDR(ex)) {
52543diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
52544index 100edcc..ed95731 100644
52545--- a/fs/binfmt_elf.c
52546+++ b/fs/binfmt_elf.c
52547@@ -34,6 +34,7 @@
52548 #include <linux/utsname.h>
52549 #include <linux/coredump.h>
52550 #include <linux/sched.h>
52551+#include <linux/xattr.h>
52552 #include <asm/uaccess.h>
52553 #include <asm/param.h>
52554 #include <asm/page.h>
52555@@ -60,6 +61,14 @@ static int elf_core_dump(struct coredump_params *cprm);
52556 #define elf_core_dump NULL
52557 #endif
52558
52559+#ifdef CONFIG_PAX_MPROTECT
52560+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
52561+#endif
52562+
52563+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
52564+static void elf_handle_mmap(struct file *file);
52565+#endif
52566+
52567 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
52568 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
52569 #else
52570@@ -79,6 +88,15 @@ static struct linux_binfmt elf_format = {
52571 .load_binary = load_elf_binary,
52572 .load_shlib = load_elf_library,
52573 .core_dump = elf_core_dump,
52574+
52575+#ifdef CONFIG_PAX_MPROTECT
52576+ .handle_mprotect= elf_handle_mprotect,
52577+#endif
52578+
52579+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
52580+ .handle_mmap = elf_handle_mmap,
52581+#endif
52582+
52583 .min_coredump = ELF_EXEC_PAGESIZE,
52584 };
52585
52586@@ -86,6 +104,8 @@ static struct linux_binfmt elf_format = {
52587
52588 static int set_brk(unsigned long start, unsigned long end)
52589 {
52590+ unsigned long e = end;
52591+
52592 start = ELF_PAGEALIGN(start);
52593 end = ELF_PAGEALIGN(end);
52594 if (end > start) {
52595@@ -94,7 +114,7 @@ static int set_brk(unsigned long start, unsigned long end)
52596 if (BAD_ADDR(addr))
52597 return addr;
52598 }
52599- current->mm->start_brk = current->mm->brk = end;
52600+ current->mm->start_brk = current->mm->brk = e;
52601 return 0;
52602 }
52603
52604@@ -155,12 +175,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
52605 elf_addr_t __user *u_rand_bytes;
52606 const char *k_platform = ELF_PLATFORM;
52607 const char *k_base_platform = ELF_BASE_PLATFORM;
52608- unsigned char k_rand_bytes[16];
52609+ u32 k_rand_bytes[4];
52610 int items;
52611 elf_addr_t *elf_info;
52612 int ei_index = 0;
52613 const struct cred *cred = current_cred();
52614 struct vm_area_struct *vma;
52615+ unsigned long saved_auxv[AT_VECTOR_SIZE];
52616
52617 /*
52618 * In some cases (e.g. Hyper-Threading), we want to avoid L1
52619@@ -202,8 +223,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
52620 * Generate 16 random bytes for userspace PRNG seeding.
52621 */
52622 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
52623- u_rand_bytes = (elf_addr_t __user *)
52624- STACK_ALLOC(p, sizeof(k_rand_bytes));
52625+ prandom_seed(k_rand_bytes[0] ^ prandom_u32());
52626+ prandom_seed(k_rand_bytes[1] ^ prandom_u32());
52627+ prandom_seed(k_rand_bytes[2] ^ prandom_u32());
52628+ prandom_seed(k_rand_bytes[3] ^ prandom_u32());
52629+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
52630+ u_rand_bytes = (elf_addr_t __user *) p;
52631 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
52632 return -EFAULT;
52633
52634@@ -318,9 +343,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
52635 return -EFAULT;
52636 current->mm->env_end = p;
52637
52638+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
52639+
52640 /* Put the elf_info on the stack in the right place. */
52641 sp = (elf_addr_t __user *)envp + 1;
52642- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
52643+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
52644 return -EFAULT;
52645 return 0;
52646 }
52647@@ -388,15 +415,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
52648 an ELF header */
52649
52650 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52651- struct file *interpreter, unsigned long *interp_map_addr,
52652- unsigned long no_base)
52653+ struct file *interpreter, unsigned long no_base)
52654 {
52655 struct elf_phdr *elf_phdata;
52656 struct elf_phdr *eppnt;
52657- unsigned long load_addr = 0;
52658+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
52659 int load_addr_set = 0;
52660 unsigned long last_bss = 0, elf_bss = 0;
52661- unsigned long error = ~0UL;
52662+ unsigned long error = -EINVAL;
52663 unsigned long total_size;
52664 int retval, i, size;
52665
52666@@ -442,6 +468,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52667 goto out_close;
52668 }
52669
52670+#ifdef CONFIG_PAX_SEGMEXEC
52671+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
52672+ pax_task_size = SEGMEXEC_TASK_SIZE;
52673+#endif
52674+
52675 eppnt = elf_phdata;
52676 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
52677 if (eppnt->p_type == PT_LOAD) {
52678@@ -465,8 +496,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52679 map_addr = elf_map(interpreter, load_addr + vaddr,
52680 eppnt, elf_prot, elf_type, total_size);
52681 total_size = 0;
52682- if (!*interp_map_addr)
52683- *interp_map_addr = map_addr;
52684 error = map_addr;
52685 if (BAD_ADDR(map_addr))
52686 goto out_close;
52687@@ -485,8 +514,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
52688 k = load_addr + eppnt->p_vaddr;
52689 if (BAD_ADDR(k) ||
52690 eppnt->p_filesz > eppnt->p_memsz ||
52691- eppnt->p_memsz > TASK_SIZE ||
52692- TASK_SIZE - eppnt->p_memsz < k) {
52693+ eppnt->p_memsz > pax_task_size ||
52694+ pax_task_size - eppnt->p_memsz < k) {
52695 error = -ENOMEM;
52696 goto out_close;
52697 }
52698@@ -538,6 +567,315 @@ out:
52699 return error;
52700 }
52701
52702+#ifdef CONFIG_PAX_PT_PAX_FLAGS
52703+#ifdef CONFIG_PAX_SOFTMODE
52704+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
52705+{
52706+ unsigned long pax_flags = 0UL;
52707+
52708+#ifdef CONFIG_PAX_PAGEEXEC
52709+ if (elf_phdata->p_flags & PF_PAGEEXEC)
52710+ pax_flags |= MF_PAX_PAGEEXEC;
52711+#endif
52712+
52713+#ifdef CONFIG_PAX_SEGMEXEC
52714+ if (elf_phdata->p_flags & PF_SEGMEXEC)
52715+ pax_flags |= MF_PAX_SEGMEXEC;
52716+#endif
52717+
52718+#ifdef CONFIG_PAX_EMUTRAMP
52719+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
52720+ pax_flags |= MF_PAX_EMUTRAMP;
52721+#endif
52722+
52723+#ifdef CONFIG_PAX_MPROTECT
52724+ if (elf_phdata->p_flags & PF_MPROTECT)
52725+ pax_flags |= MF_PAX_MPROTECT;
52726+#endif
52727+
52728+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
52729+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
52730+ pax_flags |= MF_PAX_RANDMMAP;
52731+#endif
52732+
52733+ return pax_flags;
52734+}
52735+#endif
52736+
52737+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
52738+{
52739+ unsigned long pax_flags = 0UL;
52740+
52741+#ifdef CONFIG_PAX_PAGEEXEC
52742+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
52743+ pax_flags |= MF_PAX_PAGEEXEC;
52744+#endif
52745+
52746+#ifdef CONFIG_PAX_SEGMEXEC
52747+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
52748+ pax_flags |= MF_PAX_SEGMEXEC;
52749+#endif
52750+
52751+#ifdef CONFIG_PAX_EMUTRAMP
52752+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
52753+ pax_flags |= MF_PAX_EMUTRAMP;
52754+#endif
52755+
52756+#ifdef CONFIG_PAX_MPROTECT
52757+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
52758+ pax_flags |= MF_PAX_MPROTECT;
52759+#endif
52760+
52761+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
52762+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
52763+ pax_flags |= MF_PAX_RANDMMAP;
52764+#endif
52765+
52766+ return pax_flags;
52767+}
52768+#endif
52769+
52770+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
52771+#ifdef CONFIG_PAX_SOFTMODE
52772+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
52773+{
52774+ unsigned long pax_flags = 0UL;
52775+
52776+#ifdef CONFIG_PAX_PAGEEXEC
52777+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
52778+ pax_flags |= MF_PAX_PAGEEXEC;
52779+#endif
52780+
52781+#ifdef CONFIG_PAX_SEGMEXEC
52782+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
52783+ pax_flags |= MF_PAX_SEGMEXEC;
52784+#endif
52785+
52786+#ifdef CONFIG_PAX_EMUTRAMP
52787+ if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
52788+ pax_flags |= MF_PAX_EMUTRAMP;
52789+#endif
52790+
52791+#ifdef CONFIG_PAX_MPROTECT
52792+ if (pax_flags_softmode & MF_PAX_MPROTECT)
52793+ pax_flags |= MF_PAX_MPROTECT;
52794+#endif
52795+
52796+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
52797+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
52798+ pax_flags |= MF_PAX_RANDMMAP;
52799+#endif
52800+
52801+ return pax_flags;
52802+}
52803+#endif
52804+
52805+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
52806+{
52807+ unsigned long pax_flags = 0UL;
52808+
52809+#ifdef CONFIG_PAX_PAGEEXEC
52810+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
52811+ pax_flags |= MF_PAX_PAGEEXEC;
52812+#endif
52813+
52814+#ifdef CONFIG_PAX_SEGMEXEC
52815+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
52816+ pax_flags |= MF_PAX_SEGMEXEC;
52817+#endif
52818+
52819+#ifdef CONFIG_PAX_EMUTRAMP
52820+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
52821+ pax_flags |= MF_PAX_EMUTRAMP;
52822+#endif
52823+
52824+#ifdef CONFIG_PAX_MPROTECT
52825+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
52826+ pax_flags |= MF_PAX_MPROTECT;
52827+#endif
52828+
52829+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
52830+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
52831+ pax_flags |= MF_PAX_RANDMMAP;
52832+#endif
52833+
52834+ return pax_flags;
52835+}
52836+#endif
52837+
52838+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
52839+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
52840+{
52841+ unsigned long pax_flags = 0UL;
52842+
52843+#ifdef CONFIG_PAX_EI_PAX
52844+
52845+#ifdef CONFIG_PAX_PAGEEXEC
52846+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
52847+ pax_flags |= MF_PAX_PAGEEXEC;
52848+#endif
52849+
52850+#ifdef CONFIG_PAX_SEGMEXEC
52851+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
52852+ pax_flags |= MF_PAX_SEGMEXEC;
52853+#endif
52854+
52855+#ifdef CONFIG_PAX_EMUTRAMP
52856+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
52857+ pax_flags |= MF_PAX_EMUTRAMP;
52858+#endif
52859+
52860+#ifdef CONFIG_PAX_MPROTECT
52861+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
52862+ pax_flags |= MF_PAX_MPROTECT;
52863+#endif
52864+
52865+#ifdef CONFIG_PAX_ASLR
52866+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
52867+ pax_flags |= MF_PAX_RANDMMAP;
52868+#endif
52869+
52870+#else
52871+
52872+#ifdef CONFIG_PAX_PAGEEXEC
52873+ pax_flags |= MF_PAX_PAGEEXEC;
52874+#endif
52875+
52876+#ifdef CONFIG_PAX_SEGMEXEC
52877+ pax_flags |= MF_PAX_SEGMEXEC;
52878+#endif
52879+
52880+#ifdef CONFIG_PAX_MPROTECT
52881+ pax_flags |= MF_PAX_MPROTECT;
52882+#endif
52883+
52884+#ifdef CONFIG_PAX_RANDMMAP
52885+ if (randomize_va_space)
52886+ pax_flags |= MF_PAX_RANDMMAP;
52887+#endif
52888+
52889+#endif
52890+
52891+ return pax_flags;
52892+}
52893+
52894+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
52895+{
52896+
52897+#ifdef CONFIG_PAX_PT_PAX_FLAGS
52898+ unsigned long i;
52899+
52900+ for (i = 0UL; i < elf_ex->e_phnum; i++)
52901+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
52902+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
52903+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
52904+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
52905+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
52906+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
52907+ return ~0UL;
52908+
52909+#ifdef CONFIG_PAX_SOFTMODE
52910+ if (pax_softmode)
52911+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
52912+ else
52913+#endif
52914+
52915+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
52916+ break;
52917+ }
52918+#endif
52919+
52920+ return ~0UL;
52921+}
52922+
52923+static unsigned long pax_parse_xattr_pax(struct file * const file)
52924+{
52925+
52926+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
52927+ ssize_t xattr_size, i;
52928+ unsigned char xattr_value[sizeof("pemrs") - 1];
52929+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
52930+
52931+ xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
52932+ if (xattr_size <= 0 || xattr_size > sizeof xattr_value)
52933+ return ~0UL;
52934+
52935+ for (i = 0; i < xattr_size; i++)
52936+ switch (xattr_value[i]) {
52937+ default:
52938+ return ~0UL;
52939+
52940+#define parse_flag(option1, option2, flag) \
52941+ case option1: \
52942+ if (pax_flags_hardmode & MF_PAX_##flag) \
52943+ return ~0UL; \
52944+ pax_flags_hardmode |= MF_PAX_##flag; \
52945+ break; \
52946+ case option2: \
52947+ if (pax_flags_softmode & MF_PAX_##flag) \
52948+ return ~0UL; \
52949+ pax_flags_softmode |= MF_PAX_##flag; \
52950+ break;
52951+
52952+ parse_flag('p', 'P', PAGEEXEC);
52953+ parse_flag('e', 'E', EMUTRAMP);
52954+ parse_flag('m', 'M', MPROTECT);
52955+ parse_flag('r', 'R', RANDMMAP);
52956+ parse_flag('s', 'S', SEGMEXEC);
52957+
52958+#undef parse_flag
52959+ }
52960+
52961+ if (pax_flags_hardmode & pax_flags_softmode)
52962+ return ~0UL;
52963+
52964+#ifdef CONFIG_PAX_SOFTMODE
52965+ if (pax_softmode)
52966+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
52967+ else
52968+#endif
52969+
52970+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
52971+#else
52972+ return ~0UL;
52973+#endif
52974+
52975+}
52976+
52977+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
52978+{
52979+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
52980+
52981+ pax_flags = pax_parse_ei_pax(elf_ex);
52982+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
52983+ xattr_pax_flags = pax_parse_xattr_pax(file);
52984+
52985+ if (pt_pax_flags == ~0UL)
52986+ pt_pax_flags = xattr_pax_flags;
52987+ else if (xattr_pax_flags == ~0UL)
52988+ xattr_pax_flags = pt_pax_flags;
52989+ if (pt_pax_flags != xattr_pax_flags)
52990+ return -EINVAL;
52991+ if (pt_pax_flags != ~0UL)
52992+ pax_flags = pt_pax_flags;
52993+
52994+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
52995+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
52996+ if ((__supported_pte_mask & _PAGE_NX))
52997+ pax_flags &= ~MF_PAX_SEGMEXEC;
52998+ else
52999+ pax_flags &= ~MF_PAX_PAGEEXEC;
53000+ }
53001+#endif
53002+
53003+ if (0 > pax_check_flags(&pax_flags))
53004+ return -EINVAL;
53005+
53006+ current->mm->pax_flags = pax_flags;
53007+ return 0;
53008+}
53009+#endif
53010+
53011 /*
53012 * These are the functions used to load ELF style executables and shared
53013 * libraries. There is no binary dependent code anywhere else.
53014@@ -554,6 +892,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
53015 {
53016 unsigned int random_variable = 0;
53017
53018+#ifdef CONFIG_PAX_RANDUSTACK
53019+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
53020+ return stack_top - current->mm->delta_stack;
53021+#endif
53022+
53023 if ((current->flags & PF_RANDOMIZE) &&
53024 !(current->personality & ADDR_NO_RANDOMIZE)) {
53025 random_variable = get_random_int() & STACK_RND_MASK;
53026@@ -572,7 +915,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
53027 unsigned long load_addr = 0, load_bias = 0;
53028 int load_addr_set = 0;
53029 char * elf_interpreter = NULL;
53030- unsigned long error;
53031+ unsigned long error = 0;
53032 struct elf_phdr *elf_ppnt, *elf_phdata;
53033 unsigned long elf_bss, elf_brk;
53034 int retval, i;
53035@@ -582,12 +925,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
53036 unsigned long start_code, end_code, start_data, end_data;
53037 unsigned long reloc_func_desc __maybe_unused = 0;
53038 int executable_stack = EXSTACK_DEFAULT;
53039- unsigned long def_flags = 0;
53040 struct pt_regs *regs = current_pt_regs();
53041 struct {
53042 struct elfhdr elf_ex;
53043 struct elfhdr interp_elf_ex;
53044 } *loc;
53045+ unsigned long pax_task_size = TASK_SIZE;
53046
53047 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
53048 if (!loc) {
53049@@ -723,11 +1066,81 @@ static int load_elf_binary(struct linux_binprm *bprm)
53050 goto out_free_dentry;
53051
53052 /* OK, This is the point of no return */
53053- current->mm->def_flags = def_flags;
53054+
53055+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
53056+ current->mm->pax_flags = 0UL;
53057+#endif
53058+
53059+#ifdef CONFIG_PAX_DLRESOLVE
53060+ current->mm->call_dl_resolve = 0UL;
53061+#endif
53062+
53063+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
53064+ current->mm->call_syscall = 0UL;
53065+#endif
53066+
53067+#ifdef CONFIG_PAX_ASLR
53068+ current->mm->delta_mmap = 0UL;
53069+ current->mm->delta_stack = 0UL;
53070+#endif
53071+
53072+ current->mm->def_flags = 0;
53073+
53074+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
53075+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
53076+ send_sig(SIGKILL, current, 0);
53077+ goto out_free_dentry;
53078+ }
53079+#endif
53080+
53081+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
53082+ pax_set_initial_flags(bprm);
53083+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
53084+ if (pax_set_initial_flags_func)
53085+ (pax_set_initial_flags_func)(bprm);
53086+#endif
53087+
53088+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
53089+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
53090+ current->mm->context.user_cs_limit = PAGE_SIZE;
53091+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
53092+ }
53093+#endif
53094+
53095+#ifdef CONFIG_PAX_SEGMEXEC
53096+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
53097+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
53098+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
53099+ pax_task_size = SEGMEXEC_TASK_SIZE;
53100+ current->mm->def_flags |= VM_NOHUGEPAGE;
53101+ }
53102+#endif
53103+
53104+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
53105+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
53106+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
53107+ put_cpu();
53108+ }
53109+#endif
53110
53111 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
53112 may depend on the personality. */
53113 SET_PERSONALITY(loc->elf_ex);
53114+
53115+#ifdef CONFIG_PAX_ASLR
53116+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
53117+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
53118+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
53119+ }
53120+#endif
53121+
53122+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
53123+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
53124+ executable_stack = EXSTACK_DISABLE_X;
53125+ current->personality &= ~READ_IMPLIES_EXEC;
53126+ } else
53127+#endif
53128+
53129 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
53130 current->personality |= READ_IMPLIES_EXEC;
53131
53132@@ -817,6 +1230,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
53133 #else
53134 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
53135 #endif
53136+
53137+#ifdef CONFIG_PAX_RANDMMAP
53138+ /* PaX: randomize base address at the default exe base if requested */
53139+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
53140+#ifdef CONFIG_SPARC64
53141+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
53142+#else
53143+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
53144+#endif
53145+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
53146+ elf_flags |= MAP_FIXED;
53147+ }
53148+#endif
53149+
53150 }
53151
53152 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
53153@@ -849,9 +1276,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
53154 * allowed task size. Note that p_filesz must always be
53155 * <= p_memsz so it is only necessary to check p_memsz.
53156 */
53157- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
53158- elf_ppnt->p_memsz > TASK_SIZE ||
53159- TASK_SIZE - elf_ppnt->p_memsz < k) {
53160+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
53161+ elf_ppnt->p_memsz > pax_task_size ||
53162+ pax_task_size - elf_ppnt->p_memsz < k) {
53163 /* set_brk can never work. Avoid overflows. */
53164 send_sig(SIGKILL, current, 0);
53165 retval = -EINVAL;
53166@@ -890,17 +1317,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
53167 goto out_free_dentry;
53168 }
53169 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
53170- send_sig(SIGSEGV, current, 0);
53171- retval = -EFAULT; /* Nobody gets to see this, but.. */
53172- goto out_free_dentry;
53173+ /*
53174+ * This bss-zeroing can fail if the ELF
53175+ * file specifies odd protections. So
53176+ * we don't check the return value
53177+ */
53178 }
53179
53180+#ifdef CONFIG_PAX_RANDMMAP
53181+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
53182+ unsigned long start, size, flags;
53183+ vm_flags_t vm_flags;
53184+
53185+ start = ELF_PAGEALIGN(elf_brk);
53186+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
53187+ flags = MAP_FIXED | MAP_PRIVATE;
53188+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
53189+
53190+ down_write(&current->mm->mmap_sem);
53191+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
53192+ retval = -ENOMEM;
53193+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
53194+// if (current->personality & ADDR_NO_RANDOMIZE)
53195+// vm_flags |= VM_READ | VM_MAYREAD;
53196+ start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
53197+ retval = IS_ERR_VALUE(start) ? start : 0;
53198+ }
53199+ up_write(&current->mm->mmap_sem);
53200+ if (retval == 0)
53201+ retval = set_brk(start + size, start + size + PAGE_SIZE);
53202+ if (retval < 0) {
53203+ send_sig(SIGKILL, current, 0);
53204+ goto out_free_dentry;
53205+ }
53206+ }
53207+#endif
53208+
53209 if (elf_interpreter) {
53210- unsigned long interp_map_addr = 0;
53211-
53212 elf_entry = load_elf_interp(&loc->interp_elf_ex,
53213 interpreter,
53214- &interp_map_addr,
53215 load_bias);
53216 if (!IS_ERR((void *)elf_entry)) {
53217 /*
53218@@ -1122,7 +1577,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
53219 * Decide what to dump of a segment, part, all or none.
53220 */
53221 static unsigned long vma_dump_size(struct vm_area_struct *vma,
53222- unsigned long mm_flags)
53223+ unsigned long mm_flags, long signr)
53224 {
53225 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
53226
53227@@ -1160,7 +1615,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
53228 if (vma->vm_file == NULL)
53229 return 0;
53230
53231- if (FILTER(MAPPED_PRIVATE))
53232+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
53233 goto whole;
53234
53235 /*
53236@@ -1385,9 +1840,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
53237 {
53238 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
53239 int i = 0;
53240- do
53241+ do {
53242 i += 2;
53243- while (auxv[i - 2] != AT_NULL);
53244+ } while (auxv[i - 2] != AT_NULL);
53245 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
53246 }
53247
53248@@ -1396,7 +1851,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
53249 {
53250 mm_segment_t old_fs = get_fs();
53251 set_fs(KERNEL_DS);
53252- copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
53253+ copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
53254 set_fs(old_fs);
53255 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
53256 }
53257@@ -2017,14 +2472,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
53258 }
53259
53260 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
53261- unsigned long mm_flags)
53262+ struct coredump_params *cprm)
53263 {
53264 struct vm_area_struct *vma;
53265 size_t size = 0;
53266
53267 for (vma = first_vma(current, gate_vma); vma != NULL;
53268 vma = next_vma(vma, gate_vma))
53269- size += vma_dump_size(vma, mm_flags);
53270+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
53271 return size;
53272 }
53273
53274@@ -2117,7 +2572,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53275
53276 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
53277
53278- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
53279+ offset += elf_core_vma_data_size(gate_vma, cprm);
53280 offset += elf_core_extra_data_size();
53281 e_shoff = offset;
53282
53283@@ -2131,10 +2586,12 @@ static int elf_core_dump(struct coredump_params *cprm)
53284 offset = dataoff;
53285
53286 size += sizeof(*elf);
53287+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
53288 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
53289 goto end_coredump;
53290
53291 size += sizeof(*phdr4note);
53292+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
53293 if (size > cprm->limit
53294 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
53295 goto end_coredump;
53296@@ -2148,7 +2605,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53297 phdr.p_offset = offset;
53298 phdr.p_vaddr = vma->vm_start;
53299 phdr.p_paddr = 0;
53300- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
53301+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
53302 phdr.p_memsz = vma->vm_end - vma->vm_start;
53303 offset += phdr.p_filesz;
53304 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
53305@@ -2159,6 +2616,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53306 phdr.p_align = ELF_EXEC_PAGESIZE;
53307
53308 size += sizeof(phdr);
53309+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
53310 if (size > cprm->limit
53311 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
53312 goto end_coredump;
53313@@ -2183,7 +2641,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53314 unsigned long addr;
53315 unsigned long end;
53316
53317- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
53318+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
53319
53320 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
53321 struct page *page;
53322@@ -2192,6 +2650,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53323 page = get_dump_page(addr);
53324 if (page) {
53325 void *kaddr = kmap(page);
53326+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
53327 stop = ((size += PAGE_SIZE) > cprm->limit) ||
53328 !dump_write(cprm->file, kaddr,
53329 PAGE_SIZE);
53330@@ -2209,6 +2668,7 @@ static int elf_core_dump(struct coredump_params *cprm)
53331
53332 if (e_phnum == PN_XNUM) {
53333 size += sizeof(*shdr4extnum);
53334+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
53335 if (size > cprm->limit
53336 || !dump_write(cprm->file, shdr4extnum,
53337 sizeof(*shdr4extnum)))
53338@@ -2229,6 +2689,167 @@ out:
53339
53340 #endif /* CONFIG_ELF_CORE */
53341
53342+#ifdef CONFIG_PAX_MPROTECT
53343+/* PaX: non-PIC ELF libraries need relocations on their executable segments
53344+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
53345+ * we'll remove VM_MAYWRITE for good on RELRO segments.
53346+ *
53347+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
53348+ * basis because we want to allow the common case and not the special ones.
53349+ */
53350+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
53351+{
53352+ struct elfhdr elf_h;
53353+ struct elf_phdr elf_p;
53354+ unsigned long i;
53355+ unsigned long oldflags;
53356+ bool is_textrel_rw, is_textrel_rx, is_relro;
53357+
53358+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
53359+ return;
53360+
53361+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
53362+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
53363+
53364+#ifdef CONFIG_PAX_ELFRELOCS
53365+ /* possible TEXTREL */
53366+ is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
53367+ is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
53368+#else
53369+ is_textrel_rw = false;
53370+ is_textrel_rx = false;
53371+#endif
53372+
53373+ /* possible RELRO */
53374+ is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
53375+
53376+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
53377+ return;
53378+
53379+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
53380+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
53381+
53382+#ifdef CONFIG_PAX_ETEXECRELOCS
53383+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
53384+#else
53385+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
53386+#endif
53387+
53388+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
53389+ !elf_check_arch(&elf_h) ||
53390+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
53391+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
53392+ return;
53393+
53394+ for (i = 0UL; i < elf_h.e_phnum; i++) {
53395+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
53396+ return;
53397+ switch (elf_p.p_type) {
53398+ case PT_DYNAMIC:
53399+ if (!is_textrel_rw && !is_textrel_rx)
53400+ continue;
53401+ i = 0UL;
53402+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
53403+ elf_dyn dyn;
53404+
53405+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
53406+ break;
53407+ if (dyn.d_tag == DT_NULL)
53408+ break;
53409+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
53410+ gr_log_textrel(vma);
53411+ if (is_textrel_rw)
53412+ vma->vm_flags |= VM_MAYWRITE;
53413+ else
53414+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
53415+ vma->vm_flags &= ~VM_MAYWRITE;
53416+ break;
53417+ }
53418+ i++;
53419+ }
53420+ is_textrel_rw = false;
53421+ is_textrel_rx = false;
53422+ continue;
53423+
53424+ case PT_GNU_RELRO:
53425+ if (!is_relro)
53426+ continue;
53427+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
53428+ vma->vm_flags &= ~VM_MAYWRITE;
53429+ is_relro = false;
53430+ continue;
53431+
53432+#ifdef CONFIG_PAX_PT_PAX_FLAGS
53433+ case PT_PAX_FLAGS: {
53434+ const char *msg_mprotect = "", *msg_emutramp = "";
53435+ char *buffer_lib, *buffer_exe;
53436+
53437+ if (elf_p.p_flags & PF_NOMPROTECT)
53438+ msg_mprotect = "MPROTECT disabled";
53439+
53440+#ifdef CONFIG_PAX_EMUTRAMP
53441+ if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
53442+ msg_emutramp = "EMUTRAMP enabled";
53443+#endif
53444+
53445+ if (!msg_mprotect[0] && !msg_emutramp[0])
53446+ continue;
53447+
53448+ if (!printk_ratelimit())
53449+ continue;
53450+
53451+ buffer_lib = (char *)__get_free_page(GFP_KERNEL);
53452+ buffer_exe = (char *)__get_free_page(GFP_KERNEL);
53453+ if (buffer_lib && buffer_exe) {
53454+ char *path_lib, *path_exe;
53455+
53456+ path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
53457+ path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
53458+
53459+ pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
53460+ (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
53461+
53462+ }
53463+ free_page((unsigned long)buffer_exe);
53464+ free_page((unsigned long)buffer_lib);
53465+ continue;
53466+ }
53467+#endif
53468+
53469+ }
53470+ }
53471+}
53472+#endif
53473+
53474+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
53475+
53476+extern int grsec_enable_log_rwxmaps;
53477+
53478+static void elf_handle_mmap(struct file *file)
53479+{
53480+ struct elfhdr elf_h;
53481+ struct elf_phdr elf_p;
53482+ unsigned long i;
53483+
53484+ if (!grsec_enable_log_rwxmaps)
53485+ return;
53486+
53487+ if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
53488+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
53489+ (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
53490+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
53491+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
53492+ return;
53493+
53494+ for (i = 0UL; i < elf_h.e_phnum; i++) {
53495+ if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
53496+ return;
53497+ if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
53498+ gr_log_ptgnustack(file);
53499+ }
53500+}
53501+#endif
53502+
53503 static int __init init_elf_binfmt(void)
53504 {
53505 register_binfmt(&elf_format);
53506diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
53507index d50bbe5..af3b649 100644
53508--- a/fs/binfmt_flat.c
53509+++ b/fs/binfmt_flat.c
53510@@ -566,7 +566,9 @@ static int load_flat_file(struct linux_binprm * bprm,
53511 realdatastart = (unsigned long) -ENOMEM;
53512 printk("Unable to allocate RAM for process data, errno %d\n",
53513 (int)-realdatastart);
53514+ down_write(&current->mm->mmap_sem);
53515 vm_munmap(textpos, text_len);
53516+ up_write(&current->mm->mmap_sem);
53517 ret = realdatastart;
53518 goto err;
53519 }
53520@@ -590,8 +592,10 @@ static int load_flat_file(struct linux_binprm * bprm,
53521 }
53522 if (IS_ERR_VALUE(result)) {
53523 printk("Unable to read data+bss, errno %d\n", (int)-result);
53524+ down_write(&current->mm->mmap_sem);
53525 vm_munmap(textpos, text_len);
53526 vm_munmap(realdatastart, len);
53527+ up_write(&current->mm->mmap_sem);
53528 ret = result;
53529 goto err;
53530 }
53531@@ -653,8 +657,10 @@ static int load_flat_file(struct linux_binprm * bprm,
53532 }
53533 if (IS_ERR_VALUE(result)) {
53534 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
53535+ down_write(&current->mm->mmap_sem);
53536 vm_munmap(textpos, text_len + data_len + extra +
53537 MAX_SHARED_LIBS * sizeof(unsigned long));
53538+ up_write(&current->mm->mmap_sem);
53539 ret = result;
53540 goto err;
53541 }
53542diff --git a/fs/bio.c b/fs/bio.c
53543index c5eae72..599e3cf 100644
53544--- a/fs/bio.c
53545+++ b/fs/bio.c
53546@@ -1106,7 +1106,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
53547 /*
53548 * Overflow, abort
53549 */
53550- if (end < start)
53551+ if (end < start || end - start > INT_MAX - nr_pages)
53552 return ERR_PTR(-EINVAL);
53553
53554 nr_pages += end - start;
53555@@ -1240,7 +1240,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
53556 /*
53557 * Overflow, abort
53558 */
53559- if (end < start)
53560+ if (end < start || end - start > INT_MAX - nr_pages)
53561 return ERR_PTR(-EINVAL);
53562
53563 nr_pages += end - start;
53564@@ -1502,7 +1502,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
53565 const int read = bio_data_dir(bio) == READ;
53566 struct bio_map_data *bmd = bio->bi_private;
53567 int i;
53568- char *p = bmd->sgvecs[0].iov_base;
53569+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
53570
53571 bio_for_each_segment_all(bvec, bio, i) {
53572 char *addr = page_address(bvec->bv_page);
53573diff --git a/fs/block_dev.c b/fs/block_dev.c
53574index c7bda5c..2121e94 100644
53575--- a/fs/block_dev.c
53576+++ b/fs/block_dev.c
53577@@ -637,7 +637,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
53578 else if (bdev->bd_contains == bdev)
53579 return true; /* is a whole device which isn't held */
53580
53581- else if (whole->bd_holder == bd_may_claim)
53582+ else if (whole->bd_holder == (void *)bd_may_claim)
53583 return true; /* is a partition of a device that is being partitioned */
53584 else if (whole->bd_holder != NULL)
53585 return false; /* is a partition of a held device */
53586diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
53587index ed50460..fe84385 100644
53588--- a/fs/btrfs/ctree.c
53589+++ b/fs/btrfs/ctree.c
53590@@ -1076,9 +1076,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
53591 free_extent_buffer(buf);
53592 add_root_to_dirty_list(root);
53593 } else {
53594- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
53595- parent_start = parent->start;
53596- else
53597+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
53598+ if (parent)
53599+ parent_start = parent->start;
53600+ else
53601+ parent_start = 0;
53602+ } else
53603 parent_start = 0;
53604
53605 WARN_ON(trans->transid != btrfs_header_generation(parent));
53606diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
53607index 3755109..e3d457f 100644
53608--- a/fs/btrfs/delayed-inode.c
53609+++ b/fs/btrfs/delayed-inode.c
53610@@ -458,7 +458,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
53611
53612 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
53613 {
53614- int seq = atomic_inc_return(&delayed_root->items_seq);
53615+ int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
53616 if ((atomic_dec_return(&delayed_root->items) <
53617 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
53618 waitqueue_active(&delayed_root->wait))
53619@@ -1377,7 +1377,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
53620 static int refs_newer(struct btrfs_delayed_root *delayed_root,
53621 int seq, int count)
53622 {
53623- int val = atomic_read(&delayed_root->items_seq);
53624+ int val = atomic_read_unchecked(&delayed_root->items_seq);
53625
53626 if (val < seq || val >= seq + count)
53627 return 1;
53628@@ -1394,7 +1394,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
53629 if (atomic_read(&delayed_root->items) < BTRFS_DELAYED_BACKGROUND)
53630 return;
53631
53632- seq = atomic_read(&delayed_root->items_seq);
53633+ seq = atomic_read_unchecked(&delayed_root->items_seq);
53634
53635 if (atomic_read(&delayed_root->items) >= BTRFS_DELAYED_WRITEBACK) {
53636 int ret;
53637diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
53638index a4b38f9..f86a509 100644
53639--- a/fs/btrfs/delayed-inode.h
53640+++ b/fs/btrfs/delayed-inode.h
53641@@ -43,7 +43,7 @@ struct btrfs_delayed_root {
53642 */
53643 struct list_head prepare_list;
53644 atomic_t items; /* for delayed items */
53645- atomic_t items_seq; /* for delayed items */
53646+ atomic_unchecked_t items_seq; /* for delayed items */
53647 int nodes; /* for delayed nodes */
53648 wait_queue_head_t wait;
53649 };
53650@@ -87,7 +87,7 @@ static inline void btrfs_init_delayed_root(
53651 struct btrfs_delayed_root *delayed_root)
53652 {
53653 atomic_set(&delayed_root->items, 0);
53654- atomic_set(&delayed_root->items_seq, 0);
53655+ atomic_set_unchecked(&delayed_root->items_seq, 0);
53656 delayed_root->nodes = 0;
53657 spin_lock_init(&delayed_root->lock);
53658 init_waitqueue_head(&delayed_root->wait);
53659diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
53660index 238a055..1e33cd5 100644
53661--- a/fs/btrfs/ioctl.c
53662+++ b/fs/btrfs/ioctl.c
53663@@ -3097,9 +3097,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
53664 for (i = 0; i < num_types; i++) {
53665 struct btrfs_space_info *tmp;
53666
53667+ /* Don't copy in more than we allocated */
53668 if (!slot_count)
53669 break;
53670
53671+ slot_count--;
53672+
53673 info = NULL;
53674 rcu_read_lock();
53675 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
53676@@ -3121,10 +3124,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
53677 memcpy(dest, &space, sizeof(space));
53678 dest++;
53679 space_args.total_spaces++;
53680- slot_count--;
53681 }
53682- if (!slot_count)
53683- break;
53684 }
53685 up_read(&info->groups_sem);
53686 }
53687diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
53688index 8eb6191..eda91e2 100644
53689--- a/fs/btrfs/super.c
53690+++ b/fs/btrfs/super.c
53691@@ -264,7 +264,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
53692 function, line, errstr);
53693 return;
53694 }
53695- ACCESS_ONCE(trans->transaction->aborted) = errno;
53696+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
53697 /* Wake up anybody who may be waiting on this transaction */
53698 wake_up(&root->fs_info->transaction_wait);
53699 wake_up(&root->fs_info->transaction_blocked_wait);
53700diff --git a/fs/buffer.c b/fs/buffer.c
53701index 4d74335..b0df7f9 100644
53702--- a/fs/buffer.c
53703+++ b/fs/buffer.c
53704@@ -3416,7 +3416,7 @@ void __init buffer_init(void)
53705 bh_cachep = kmem_cache_create("buffer_head",
53706 sizeof(struct buffer_head), 0,
53707 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
53708- SLAB_MEM_SPREAD),
53709+ SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
53710 NULL);
53711
53712 /*
53713diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
53714index 622f469..e8d2d55 100644
53715--- a/fs/cachefiles/bind.c
53716+++ b/fs/cachefiles/bind.c
53717@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
53718 args);
53719
53720 /* start by checking things over */
53721- ASSERT(cache->fstop_percent >= 0 &&
53722- cache->fstop_percent < cache->fcull_percent &&
53723+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
53724 cache->fcull_percent < cache->frun_percent &&
53725 cache->frun_percent < 100);
53726
53727- ASSERT(cache->bstop_percent >= 0 &&
53728- cache->bstop_percent < cache->bcull_percent &&
53729+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
53730 cache->bcull_percent < cache->brun_percent &&
53731 cache->brun_percent < 100);
53732
53733diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
53734index 0a1467b..6a53245 100644
53735--- a/fs/cachefiles/daemon.c
53736+++ b/fs/cachefiles/daemon.c
53737@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
53738 if (n > buflen)
53739 return -EMSGSIZE;
53740
53741- if (copy_to_user(_buffer, buffer, n) != 0)
53742+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
53743 return -EFAULT;
53744
53745 return n;
53746@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
53747 if (test_bit(CACHEFILES_DEAD, &cache->flags))
53748 return -EIO;
53749
53750- if (datalen < 0 || datalen > PAGE_SIZE - 1)
53751+ if (datalen > PAGE_SIZE - 1)
53752 return -EOPNOTSUPP;
53753
53754 /* drag the command string into the kernel so we can parse it */
53755@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
53756 if (args[0] != '%' || args[1] != '\0')
53757 return -EINVAL;
53758
53759- if (fstop < 0 || fstop >= cache->fcull_percent)
53760+ if (fstop >= cache->fcull_percent)
53761 return cachefiles_daemon_range_error(cache, args);
53762
53763 cache->fstop_percent = fstop;
53764@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
53765 if (args[0] != '%' || args[1] != '\0')
53766 return -EINVAL;
53767
53768- if (bstop < 0 || bstop >= cache->bcull_percent)
53769+ if (bstop >= cache->bcull_percent)
53770 return cachefiles_daemon_range_error(cache, args);
53771
53772 cache->bstop_percent = bstop;
53773diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
53774index 4938251..7e01445 100644
53775--- a/fs/cachefiles/internal.h
53776+++ b/fs/cachefiles/internal.h
53777@@ -59,7 +59,7 @@ struct cachefiles_cache {
53778 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
53779 struct rb_root active_nodes; /* active nodes (can't be culled) */
53780 rwlock_t active_lock; /* lock for active_nodes */
53781- atomic_t gravecounter; /* graveyard uniquifier */
53782+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
53783 unsigned frun_percent; /* when to stop culling (% files) */
53784 unsigned fcull_percent; /* when to start culling (% files) */
53785 unsigned fstop_percent; /* when to stop allocating (% files) */
53786@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
53787 * proc.c
53788 */
53789 #ifdef CONFIG_CACHEFILES_HISTOGRAM
53790-extern atomic_t cachefiles_lookup_histogram[HZ];
53791-extern atomic_t cachefiles_mkdir_histogram[HZ];
53792-extern atomic_t cachefiles_create_histogram[HZ];
53793+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
53794+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
53795+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
53796
53797 extern int __init cachefiles_proc_init(void);
53798 extern void cachefiles_proc_cleanup(void);
53799 static inline
53800-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
53801+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
53802 {
53803 unsigned long jif = jiffies - start_jif;
53804 if (jif >= HZ)
53805 jif = HZ - 1;
53806- atomic_inc(&histogram[jif]);
53807+ atomic_inc_unchecked(&histogram[jif]);
53808 }
53809
53810 #else
53811diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
53812index 25badd1..d70d918 100644
53813--- a/fs/cachefiles/namei.c
53814+++ b/fs/cachefiles/namei.c
53815@@ -317,7 +317,7 @@ try_again:
53816 /* first step is to make up a grave dentry in the graveyard */
53817 sprintf(nbuffer, "%08x%08x",
53818 (uint32_t) get_seconds(),
53819- (uint32_t) atomic_inc_return(&cache->gravecounter));
53820+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
53821
53822 /* do the multiway lock magic */
53823 trap = lock_rename(cache->graveyard, dir);
53824diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
53825index eccd339..4c1d995 100644
53826--- a/fs/cachefiles/proc.c
53827+++ b/fs/cachefiles/proc.c
53828@@ -14,9 +14,9 @@
53829 #include <linux/seq_file.h>
53830 #include "internal.h"
53831
53832-atomic_t cachefiles_lookup_histogram[HZ];
53833-atomic_t cachefiles_mkdir_histogram[HZ];
53834-atomic_t cachefiles_create_histogram[HZ];
53835+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
53836+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
53837+atomic_unchecked_t cachefiles_create_histogram[HZ];
53838
53839 /*
53840 * display the latency histogram
53841@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
53842 return 0;
53843 default:
53844 index = (unsigned long) v - 3;
53845- x = atomic_read(&cachefiles_lookup_histogram[index]);
53846- y = atomic_read(&cachefiles_mkdir_histogram[index]);
53847- z = atomic_read(&cachefiles_create_histogram[index]);
53848+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
53849+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
53850+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
53851 if (x == 0 && y == 0 && z == 0)
53852 return 0;
53853
53854diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
53855index ebaff36..7e3ea26 100644
53856--- a/fs/cachefiles/rdwr.c
53857+++ b/fs/cachefiles/rdwr.c
53858@@ -950,7 +950,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
53859 old_fs = get_fs();
53860 set_fs(KERNEL_DS);
53861 ret = file->f_op->write(
53862- file, (const void __user *) data, len, &pos);
53863+ file, (const void __force_user *) data, len, &pos);
53864 set_fs(old_fs);
53865 kunmap(page);
53866 file_end_write(file);
53867diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
53868index a40ceda..f43d17c 100644
53869--- a/fs/ceph/dir.c
53870+++ b/fs/ceph/dir.c
53871@@ -240,7 +240,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
53872 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
53873 struct ceph_mds_client *mdsc = fsc->mdsc;
53874 unsigned frag = fpos_frag(ctx->pos);
53875- int off = fpos_off(ctx->pos);
53876+ unsigned int off = fpos_off(ctx->pos);
53877 int err;
53878 u32 ftype;
53879 struct ceph_mds_reply_info_parsed *rinfo;
53880diff --git a/fs/ceph/super.c b/fs/ceph/super.c
53881index 6627b26..634ec4b 100644
53882--- a/fs/ceph/super.c
53883+++ b/fs/ceph/super.c
53884@@ -839,7 +839,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
53885 /*
53886 * construct our own bdi so we can control readahead, etc.
53887 */
53888-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
53889+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
53890
53891 static int ceph_register_bdi(struct super_block *sb,
53892 struct ceph_fs_client *fsc)
53893@@ -856,7 +856,7 @@ static int ceph_register_bdi(struct super_block *sb,
53894 default_backing_dev_info.ra_pages;
53895
53896 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
53897- atomic_long_inc_return(&bdi_seq));
53898+ atomic_long_inc_return_unchecked(&bdi_seq));
53899 if (!err)
53900 sb->s_bdi = &fsc->backing_dev_info;
53901 return err;
53902diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
53903index f3ac415..3d2420c 100644
53904--- a/fs/cifs/cifs_debug.c
53905+++ b/fs/cifs/cifs_debug.c
53906@@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
53907
53908 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
53909 #ifdef CONFIG_CIFS_STATS2
53910- atomic_set(&totBufAllocCount, 0);
53911- atomic_set(&totSmBufAllocCount, 0);
53912+ atomic_set_unchecked(&totBufAllocCount, 0);
53913+ atomic_set_unchecked(&totSmBufAllocCount, 0);
53914 #endif /* CONFIG_CIFS_STATS2 */
53915 spin_lock(&cifs_tcp_ses_lock);
53916 list_for_each(tmp1, &cifs_tcp_ses_list) {
53917@@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
53918 tcon = list_entry(tmp3,
53919 struct cifs_tcon,
53920 tcon_list);
53921- atomic_set(&tcon->num_smbs_sent, 0);
53922+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
53923 if (server->ops->clear_stats)
53924 server->ops->clear_stats(tcon);
53925 }
53926@@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
53927 smBufAllocCount.counter, cifs_min_small);
53928 #ifdef CONFIG_CIFS_STATS2
53929 seq_printf(m, "Total Large %d Small %d Allocations\n",
53930- atomic_read(&totBufAllocCount),
53931- atomic_read(&totSmBufAllocCount));
53932+ atomic_read_unchecked(&totBufAllocCount),
53933+ atomic_read_unchecked(&totSmBufAllocCount));
53934 #endif /* CONFIG_CIFS_STATS2 */
53935
53936 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
53937@@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
53938 if (tcon->need_reconnect)
53939 seq_puts(m, "\tDISCONNECTED ");
53940 seq_printf(m, "\nSMBs: %d",
53941- atomic_read(&tcon->num_smbs_sent));
53942+ atomic_read_unchecked(&tcon->num_smbs_sent));
53943 if (server->ops->print_stats)
53944 server->ops->print_stats(m, tcon);
53945 }
53946diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
53947index 85ea98d..b3ed4d6 100644
53948--- a/fs/cifs/cifsfs.c
53949+++ b/fs/cifs/cifsfs.c
53950@@ -1037,7 +1037,7 @@ cifs_init_request_bufs(void)
53951 */
53952 cifs_req_cachep = kmem_cache_create("cifs_request",
53953 CIFSMaxBufSize + max_hdr_size, 0,
53954- SLAB_HWCACHE_ALIGN, NULL);
53955+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
53956 if (cifs_req_cachep == NULL)
53957 return -ENOMEM;
53958
53959@@ -1064,7 +1064,7 @@ cifs_init_request_bufs(void)
53960 efficient to alloc 1 per page off the slab compared to 17K (5page)
53961 alloc of large cifs buffers even when page debugging is on */
53962 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
53963- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
53964+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
53965 NULL);
53966 if (cifs_sm_req_cachep == NULL) {
53967 mempool_destroy(cifs_req_poolp);
53968@@ -1149,8 +1149,8 @@ init_cifs(void)
53969 atomic_set(&bufAllocCount, 0);
53970 atomic_set(&smBufAllocCount, 0);
53971 #ifdef CONFIG_CIFS_STATS2
53972- atomic_set(&totBufAllocCount, 0);
53973- atomic_set(&totSmBufAllocCount, 0);
53974+ atomic_set_unchecked(&totBufAllocCount, 0);
53975+ atomic_set_unchecked(&totSmBufAllocCount, 0);
53976 #endif /* CONFIG_CIFS_STATS2 */
53977
53978 atomic_set(&midCount, 0);
53979diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
53980index 52ca861..47f309c 100644
53981--- a/fs/cifs/cifsglob.h
53982+++ b/fs/cifs/cifsglob.h
53983@@ -756,35 +756,35 @@ struct cifs_tcon {
53984 __u16 Flags; /* optional support bits */
53985 enum statusEnum tidStatus;
53986 #ifdef CONFIG_CIFS_STATS
53987- atomic_t num_smbs_sent;
53988+ atomic_unchecked_t num_smbs_sent;
53989 union {
53990 struct {
53991- atomic_t num_writes;
53992- atomic_t num_reads;
53993- atomic_t num_flushes;
53994- atomic_t num_oplock_brks;
53995- atomic_t num_opens;
53996- atomic_t num_closes;
53997- atomic_t num_deletes;
53998- atomic_t num_mkdirs;
53999- atomic_t num_posixopens;
54000- atomic_t num_posixmkdirs;
54001- atomic_t num_rmdirs;
54002- atomic_t num_renames;
54003- atomic_t num_t2renames;
54004- atomic_t num_ffirst;
54005- atomic_t num_fnext;
54006- atomic_t num_fclose;
54007- atomic_t num_hardlinks;
54008- atomic_t num_symlinks;
54009- atomic_t num_locks;
54010- atomic_t num_acl_get;
54011- atomic_t num_acl_set;
54012+ atomic_unchecked_t num_writes;
54013+ atomic_unchecked_t num_reads;
54014+ atomic_unchecked_t num_flushes;
54015+ atomic_unchecked_t num_oplock_brks;
54016+ atomic_unchecked_t num_opens;
54017+ atomic_unchecked_t num_closes;
54018+ atomic_unchecked_t num_deletes;
54019+ atomic_unchecked_t num_mkdirs;
54020+ atomic_unchecked_t num_posixopens;
54021+ atomic_unchecked_t num_posixmkdirs;
54022+ atomic_unchecked_t num_rmdirs;
54023+ atomic_unchecked_t num_renames;
54024+ atomic_unchecked_t num_t2renames;
54025+ atomic_unchecked_t num_ffirst;
54026+ atomic_unchecked_t num_fnext;
54027+ atomic_unchecked_t num_fclose;
54028+ atomic_unchecked_t num_hardlinks;
54029+ atomic_unchecked_t num_symlinks;
54030+ atomic_unchecked_t num_locks;
54031+ atomic_unchecked_t num_acl_get;
54032+ atomic_unchecked_t num_acl_set;
54033 } cifs_stats;
54034 #ifdef CONFIG_CIFS_SMB2
54035 struct {
54036- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
54037- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
54038+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
54039+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
54040 } smb2_stats;
54041 #endif /* CONFIG_CIFS_SMB2 */
54042 } stats;
54043@@ -1096,7 +1096,7 @@ convert_delimiter(char *path, char delim)
54044 }
54045
54046 #ifdef CONFIG_CIFS_STATS
54047-#define cifs_stats_inc atomic_inc
54048+#define cifs_stats_inc atomic_inc_unchecked
54049
54050 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
54051 unsigned int bytes)
54052@@ -1461,8 +1461,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
54053 /* Various Debug counters */
54054 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
54055 #ifdef CONFIG_CIFS_STATS2
54056-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
54057-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
54058+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
54059+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
54060 #endif
54061 GLOBAL_EXTERN atomic_t smBufAllocCount;
54062 GLOBAL_EXTERN atomic_t midCount;
54063diff --git a/fs/cifs/link.c b/fs/cifs/link.c
54064index 562044f..4af6a17 100644
54065--- a/fs/cifs/link.c
54066+++ b/fs/cifs/link.c
54067@@ -638,7 +638,7 @@ symlink_exit:
54068
54069 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
54070 {
54071- char *p = nd_get_link(nd);
54072+ const char *p = nd_get_link(nd);
54073 if (!IS_ERR(p))
54074 kfree(p);
54075 }
54076diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
54077index f7d4b22..1254377 100644
54078--- a/fs/cifs/misc.c
54079+++ b/fs/cifs/misc.c
54080@@ -169,7 +169,7 @@ cifs_buf_get(void)
54081 memset(ret_buf, 0, buf_size + 3);
54082 atomic_inc(&bufAllocCount);
54083 #ifdef CONFIG_CIFS_STATS2
54084- atomic_inc(&totBufAllocCount);
54085+ atomic_inc_unchecked(&totBufAllocCount);
54086 #endif /* CONFIG_CIFS_STATS2 */
54087 }
54088
54089@@ -204,7 +204,7 @@ cifs_small_buf_get(void)
54090 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
54091 atomic_inc(&smBufAllocCount);
54092 #ifdef CONFIG_CIFS_STATS2
54093- atomic_inc(&totSmBufAllocCount);
54094+ atomic_inc_unchecked(&totSmBufAllocCount);
54095 #endif /* CONFIG_CIFS_STATS2 */
54096
54097 }
54098diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
54099index 6094397..51e576f 100644
54100--- a/fs/cifs/smb1ops.c
54101+++ b/fs/cifs/smb1ops.c
54102@@ -590,27 +590,27 @@ static void
54103 cifs_clear_stats(struct cifs_tcon *tcon)
54104 {
54105 #ifdef CONFIG_CIFS_STATS
54106- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
54107- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
54108- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
54109- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
54110- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
54111- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
54112- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
54113- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
54114- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
54115- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
54116- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
54117- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
54118- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
54119- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
54120- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
54121- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
54122- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
54123- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
54124- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
54125- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
54126- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
54127+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
54128+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
54129+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
54130+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
54131+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
54132+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
54133+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
54134+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
54135+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
54136+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
54137+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
54138+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
54139+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
54140+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
54141+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
54142+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
54143+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
54144+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
54145+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
54146+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
54147+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
54148 #endif
54149 }
54150
54151@@ -619,36 +619,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
54152 {
54153 #ifdef CONFIG_CIFS_STATS
54154 seq_printf(m, " Oplocks breaks: %d",
54155- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
54156+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
54157 seq_printf(m, "\nReads: %d Bytes: %llu",
54158- atomic_read(&tcon->stats.cifs_stats.num_reads),
54159+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
54160 (long long)(tcon->bytes_read));
54161 seq_printf(m, "\nWrites: %d Bytes: %llu",
54162- atomic_read(&tcon->stats.cifs_stats.num_writes),
54163+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
54164 (long long)(tcon->bytes_written));
54165 seq_printf(m, "\nFlushes: %d",
54166- atomic_read(&tcon->stats.cifs_stats.num_flushes));
54167+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
54168 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
54169- atomic_read(&tcon->stats.cifs_stats.num_locks),
54170- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
54171- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
54172+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
54173+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
54174+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
54175 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
54176- atomic_read(&tcon->stats.cifs_stats.num_opens),
54177- atomic_read(&tcon->stats.cifs_stats.num_closes),
54178- atomic_read(&tcon->stats.cifs_stats.num_deletes));
54179+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
54180+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
54181+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
54182 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
54183- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
54184- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
54185+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
54186+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
54187 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
54188- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
54189- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
54190+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
54191+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
54192 seq_printf(m, "\nRenames: %d T2 Renames %d",
54193- atomic_read(&tcon->stats.cifs_stats.num_renames),
54194- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
54195+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
54196+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
54197 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
54198- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
54199- atomic_read(&tcon->stats.cifs_stats.num_fnext),
54200- atomic_read(&tcon->stats.cifs_stats.num_fclose));
54201+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
54202+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
54203+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
54204 #endif
54205 }
54206
54207diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
54208index f259e6c..ca948ff 100644
54209--- a/fs/cifs/smb2ops.c
54210+++ b/fs/cifs/smb2ops.c
54211@@ -281,8 +281,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
54212 #ifdef CONFIG_CIFS_STATS
54213 int i;
54214 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
54215- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
54216- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
54217+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
54218+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
54219 }
54220 #endif
54221 }
54222@@ -310,65 +310,65 @@ static void
54223 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
54224 {
54225 #ifdef CONFIG_CIFS_STATS
54226- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
54227- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
54228+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
54229+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
54230 seq_printf(m, "\nNegotiates: %d sent %d failed",
54231- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
54232- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
54233+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
54234+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
54235 seq_printf(m, "\nSessionSetups: %d sent %d failed",
54236- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
54237- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
54238+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
54239+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
54240 seq_printf(m, "\nLogoffs: %d sent %d failed",
54241- atomic_read(&sent[SMB2_LOGOFF_HE]),
54242- atomic_read(&failed[SMB2_LOGOFF_HE]));
54243+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
54244+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
54245 seq_printf(m, "\nTreeConnects: %d sent %d failed",
54246- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
54247- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
54248+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
54249+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
54250 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
54251- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
54252- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
54253+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
54254+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
54255 seq_printf(m, "\nCreates: %d sent %d failed",
54256- atomic_read(&sent[SMB2_CREATE_HE]),
54257- atomic_read(&failed[SMB2_CREATE_HE]));
54258+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
54259+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
54260 seq_printf(m, "\nCloses: %d sent %d failed",
54261- atomic_read(&sent[SMB2_CLOSE_HE]),
54262- atomic_read(&failed[SMB2_CLOSE_HE]));
54263+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
54264+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
54265 seq_printf(m, "\nFlushes: %d sent %d failed",
54266- atomic_read(&sent[SMB2_FLUSH_HE]),
54267- atomic_read(&failed[SMB2_FLUSH_HE]));
54268+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
54269+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
54270 seq_printf(m, "\nReads: %d sent %d failed",
54271- atomic_read(&sent[SMB2_READ_HE]),
54272- atomic_read(&failed[SMB2_READ_HE]));
54273+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
54274+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
54275 seq_printf(m, "\nWrites: %d sent %d failed",
54276- atomic_read(&sent[SMB2_WRITE_HE]),
54277- atomic_read(&failed[SMB2_WRITE_HE]));
54278+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
54279+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
54280 seq_printf(m, "\nLocks: %d sent %d failed",
54281- atomic_read(&sent[SMB2_LOCK_HE]),
54282- atomic_read(&failed[SMB2_LOCK_HE]));
54283+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
54284+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
54285 seq_printf(m, "\nIOCTLs: %d sent %d failed",
54286- atomic_read(&sent[SMB2_IOCTL_HE]),
54287- atomic_read(&failed[SMB2_IOCTL_HE]));
54288+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
54289+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
54290 seq_printf(m, "\nCancels: %d sent %d failed",
54291- atomic_read(&sent[SMB2_CANCEL_HE]),
54292- atomic_read(&failed[SMB2_CANCEL_HE]));
54293+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
54294+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
54295 seq_printf(m, "\nEchos: %d sent %d failed",
54296- atomic_read(&sent[SMB2_ECHO_HE]),
54297- atomic_read(&failed[SMB2_ECHO_HE]));
54298+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
54299+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
54300 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
54301- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
54302- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
54303+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
54304+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
54305 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
54306- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
54307- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
54308+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
54309+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
54310 seq_printf(m, "\nQueryInfos: %d sent %d failed",
54311- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
54312- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
54313+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
54314+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
54315 seq_printf(m, "\nSetInfos: %d sent %d failed",
54316- atomic_read(&sent[SMB2_SET_INFO_HE]),
54317- atomic_read(&failed[SMB2_SET_INFO_HE]));
54318+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
54319+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
54320 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
54321- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
54322- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
54323+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
54324+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
54325 #endif
54326 }
54327
54328diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
54329index abc9c28..3fdae28 100644
54330--- a/fs/cifs/smb2pdu.c
54331+++ b/fs/cifs/smb2pdu.c
54332@@ -1946,8 +1946,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
54333 default:
54334 cifs_dbg(VFS, "info level %u isn't supported\n",
54335 srch_inf->info_level);
54336- rc = -EINVAL;
54337- goto qdir_exit;
54338+ return -EINVAL;
54339 }
54340
54341 req->FileIndex = cpu_to_le32(index);
54342diff --git a/fs/coda/cache.c b/fs/coda/cache.c
54343index 1da168c..8bc7ff6 100644
54344--- a/fs/coda/cache.c
54345+++ b/fs/coda/cache.c
54346@@ -24,7 +24,7 @@
54347 #include "coda_linux.h"
54348 #include "coda_cache.h"
54349
54350-static atomic_t permission_epoch = ATOMIC_INIT(0);
54351+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
54352
54353 /* replace or extend an acl cache hit */
54354 void coda_cache_enter(struct inode *inode, int mask)
54355@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
54356 struct coda_inode_info *cii = ITOC(inode);
54357
54358 spin_lock(&cii->c_lock);
54359- cii->c_cached_epoch = atomic_read(&permission_epoch);
54360+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
54361 if (!uid_eq(cii->c_uid, current_fsuid())) {
54362 cii->c_uid = current_fsuid();
54363 cii->c_cached_perm = mask;
54364@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
54365 {
54366 struct coda_inode_info *cii = ITOC(inode);
54367 spin_lock(&cii->c_lock);
54368- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
54369+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
54370 spin_unlock(&cii->c_lock);
54371 }
54372
54373 /* remove all acl caches */
54374 void coda_cache_clear_all(struct super_block *sb)
54375 {
54376- atomic_inc(&permission_epoch);
54377+ atomic_inc_unchecked(&permission_epoch);
54378 }
54379
54380
54381@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
54382 spin_lock(&cii->c_lock);
54383 hit = (mask & cii->c_cached_perm) == mask &&
54384 uid_eq(cii->c_uid, current_fsuid()) &&
54385- cii->c_cached_epoch == atomic_read(&permission_epoch);
54386+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
54387 spin_unlock(&cii->c_lock);
54388
54389 return hit;
54390diff --git a/fs/compat.c b/fs/compat.c
54391index 6af20de..fec3fbb 100644
54392--- a/fs/compat.c
54393+++ b/fs/compat.c
54394@@ -54,7 +54,7 @@
54395 #include <asm/ioctls.h>
54396 #include "internal.h"
54397
54398-int compat_log = 1;
54399+int compat_log = 0;
54400
54401 int compat_printk(const char *fmt, ...)
54402 {
54403@@ -488,7 +488,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
54404
54405 set_fs(KERNEL_DS);
54406 /* The __user pointer cast is valid because of the set_fs() */
54407- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
54408+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
54409 set_fs(oldfs);
54410 /* truncating is ok because it's a user address */
54411 if (!ret)
54412@@ -546,7 +546,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
54413 goto out;
54414
54415 ret = -EINVAL;
54416- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
54417+ if (nr_segs > UIO_MAXIOV)
54418 goto out;
54419 if (nr_segs > fast_segs) {
54420 ret = -ENOMEM;
54421@@ -834,6 +834,7 @@ struct compat_old_linux_dirent {
54422 struct compat_readdir_callback {
54423 struct dir_context ctx;
54424 struct compat_old_linux_dirent __user *dirent;
54425+ struct file * file;
54426 int result;
54427 };
54428
54429@@ -851,6 +852,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
54430 buf->result = -EOVERFLOW;
54431 return -EOVERFLOW;
54432 }
54433+
54434+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
54435+ return 0;
54436+
54437 buf->result++;
54438 dirent = buf->dirent;
54439 if (!access_ok(VERIFY_WRITE, dirent,
54440@@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
54441 if (!f.file)
54442 return -EBADF;
54443
54444+ buf.file = f.file;
54445 error = iterate_dir(f.file, &buf.ctx);
54446 if (buf.result)
54447 error = buf.result;
54448@@ -901,6 +907,7 @@ struct compat_getdents_callback {
54449 struct dir_context ctx;
54450 struct compat_linux_dirent __user *current_dir;
54451 struct compat_linux_dirent __user *previous;
54452+ struct file * file;
54453 int count;
54454 int error;
54455 };
54456@@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
54457 buf->error = -EOVERFLOW;
54458 return -EOVERFLOW;
54459 }
54460+
54461+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
54462+ return 0;
54463+
54464 dirent = buf->previous;
54465 if (dirent) {
54466 if (__put_user(offset, &dirent->d_off))
54467@@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
54468 if (!f.file)
54469 return -EBADF;
54470
54471+ buf.file = f.file;
54472 error = iterate_dir(f.file, &buf.ctx);
54473 if (error >= 0)
54474 error = buf.error;
54475@@ -987,6 +999,7 @@ struct compat_getdents_callback64 {
54476 struct dir_context ctx;
54477 struct linux_dirent64 __user *current_dir;
54478 struct linux_dirent64 __user *previous;
54479+ struct file * file;
54480 int count;
54481 int error;
54482 };
54483@@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
54484 buf->error = -EINVAL; /* only used if we fail.. */
54485 if (reclen > buf->count)
54486 return -EINVAL;
54487+
54488+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
54489+ return 0;
54490+
54491 dirent = buf->previous;
54492
54493 if (dirent) {
54494@@ -1052,6 +1069,7 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
54495 if (!f.file)
54496 return -EBADF;
54497
54498+ buf.file = f.file;
54499 error = iterate_dir(f.file, &buf.ctx);
54500 if (error >= 0)
54501 error = buf.error;
54502diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
54503index a81147e..20bf2b5 100644
54504--- a/fs/compat_binfmt_elf.c
54505+++ b/fs/compat_binfmt_elf.c
54506@@ -30,11 +30,13 @@
54507 #undef elf_phdr
54508 #undef elf_shdr
54509 #undef elf_note
54510+#undef elf_dyn
54511 #undef elf_addr_t
54512 #define elfhdr elf32_hdr
54513 #define elf_phdr elf32_phdr
54514 #define elf_shdr elf32_shdr
54515 #define elf_note elf32_note
54516+#define elf_dyn Elf32_Dyn
54517 #define elf_addr_t Elf32_Addr
54518
54519 /*
54520diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
54521index 5d19acf..9ab093b 100644
54522--- a/fs/compat_ioctl.c
54523+++ b/fs/compat_ioctl.c
54524@@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
54525 return -EFAULT;
54526 if (__get_user(udata, &ss32->iomem_base))
54527 return -EFAULT;
54528- ss.iomem_base = compat_ptr(udata);
54529+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
54530 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
54531 __get_user(ss.port_high, &ss32->port_high))
54532 return -EFAULT;
54533@@ -702,8 +702,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
54534 for (i = 0; i < nmsgs; i++) {
54535 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
54536 return -EFAULT;
54537- if (get_user(datap, &umsgs[i].buf) ||
54538- put_user(compat_ptr(datap), &tmsgs[i].buf))
54539+ if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
54540+ put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
54541 return -EFAULT;
54542 }
54543 return sys_ioctl(fd, cmd, (unsigned long)tdata);
54544@@ -796,7 +796,7 @@ static int compat_ioctl_preallocate(struct file *file,
54545 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
54546 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
54547 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
54548- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
54549+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
54550 return -EFAULT;
54551
54552 return ioctl_preallocate(file, p);
54553@@ -1616,8 +1616,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
54554 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
54555 {
54556 unsigned int a, b;
54557- a = *(unsigned int *)p;
54558- b = *(unsigned int *)q;
54559+ a = *(const unsigned int *)p;
54560+ b = *(const unsigned int *)q;
54561 if (a > b)
54562 return 1;
54563 if (a < b)
54564diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
54565index 277bd1b..f312c9e 100644
54566--- a/fs/configfs/dir.c
54567+++ b/fs/configfs/dir.c
54568@@ -1546,7 +1546,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
54569 }
54570 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
54571 struct configfs_dirent *next;
54572- const char *name;
54573+ const unsigned char * name;
54574+ char d_name[sizeof(next->s_dentry->d_iname)];
54575 int len;
54576 struct inode *inode = NULL;
54577
54578@@ -1555,7 +1556,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
54579 continue;
54580
54581 name = configfs_get_name(next);
54582- len = strlen(name);
54583+ if (next->s_dentry && name == next->s_dentry->d_iname) {
54584+ len = next->s_dentry->d_name.len;
54585+ memcpy(d_name, name, len);
54586+ name = d_name;
54587+ } else
54588+ len = strlen(name);
54589
54590 /*
54591 * We'll have a dentry and an inode for
54592diff --git a/fs/coredump.c b/fs/coredump.c
54593index 72f816d..1ba8eff 100644
54594--- a/fs/coredump.c
54595+++ b/fs/coredump.c
54596@@ -433,8 +433,8 @@ static void wait_for_dump_helpers(struct file *file)
54597 struct pipe_inode_info *pipe = file->private_data;
54598
54599 pipe_lock(pipe);
54600- pipe->readers++;
54601- pipe->writers--;
54602+ atomic_inc(&pipe->readers);
54603+ atomic_dec(&pipe->writers);
54604 wake_up_interruptible_sync(&pipe->wait);
54605 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
54606 pipe_unlock(pipe);
54607@@ -443,11 +443,11 @@ static void wait_for_dump_helpers(struct file *file)
54608 * We actually want wait_event_freezable() but then we need
54609 * to clear TIF_SIGPENDING and improve dump_interrupted().
54610 */
54611- wait_event_interruptible(pipe->wait, pipe->readers == 1);
54612+ wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
54613
54614 pipe_lock(pipe);
54615- pipe->readers--;
54616- pipe->writers++;
54617+ atomic_dec(&pipe->readers);
54618+ atomic_inc(&pipe->writers);
54619 pipe_unlock(pipe);
54620 }
54621
54622@@ -494,7 +494,8 @@ void do_coredump(siginfo_t *siginfo)
54623 struct files_struct *displaced;
54624 bool need_nonrelative = false;
54625 bool core_dumped = false;
54626- static atomic_t core_dump_count = ATOMIC_INIT(0);
54627+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
54628+ long signr = siginfo->si_signo;
54629 struct coredump_params cprm = {
54630 .siginfo = siginfo,
54631 .regs = signal_pt_regs(),
54632@@ -507,7 +508,10 @@ void do_coredump(siginfo_t *siginfo)
54633 .mm_flags = mm->flags,
54634 };
54635
54636- audit_core_dumps(siginfo->si_signo);
54637+ audit_core_dumps(signr);
54638+
54639+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
54640+ gr_handle_brute_attach(cprm.mm_flags);
54641
54642 binfmt = mm->binfmt;
54643 if (!binfmt || !binfmt->core_dump)
54644@@ -531,7 +535,7 @@ void do_coredump(siginfo_t *siginfo)
54645 need_nonrelative = true;
54646 }
54647
54648- retval = coredump_wait(siginfo->si_signo, &core_state);
54649+ retval = coredump_wait(signr, &core_state);
54650 if (retval < 0)
54651 goto fail_creds;
54652
54653@@ -574,7 +578,7 @@ void do_coredump(siginfo_t *siginfo)
54654 }
54655 cprm.limit = RLIM_INFINITY;
54656
54657- dump_count = atomic_inc_return(&core_dump_count);
54658+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
54659 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
54660 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
54661 task_tgid_vnr(current), current->comm);
54662@@ -606,6 +610,8 @@ void do_coredump(siginfo_t *siginfo)
54663 } else {
54664 struct inode *inode;
54665
54666+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
54667+
54668 if (cprm.limit < binfmt->min_coredump)
54669 goto fail_unlock;
54670
54671@@ -664,7 +670,7 @@ close_fail:
54672 filp_close(cprm.file, NULL);
54673 fail_dropcount:
54674 if (ispipe)
54675- atomic_dec(&core_dump_count);
54676+ atomic_dec_unchecked(&core_dump_count);
54677 fail_unlock:
54678 kfree(cn.corename);
54679 coredump_finish(mm, core_dumped);
54680@@ -684,7 +690,7 @@ int dump_write(struct file *file, const void *addr, int nr)
54681 {
54682 return !dump_interrupted() &&
54683 access_ok(VERIFY_READ, addr, nr) &&
54684- file->f_op->write(file, addr, nr, &file->f_pos) == nr;
54685+ file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
54686 }
54687 EXPORT_SYMBOL(dump_write);
54688
54689diff --git a/fs/dcache.c b/fs/dcache.c
54690index b949af8..5978926 100644
54691--- a/fs/dcache.c
54692+++ b/fs/dcache.c
54693@@ -3073,7 +3073,8 @@ void __init vfs_caches_init(unsigned long mempages)
54694 mempages -= reserve;
54695
54696 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
54697- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
54698+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
54699+ SLAB_NO_SANITIZE, NULL);
54700
54701 dcache_init();
54702 inode_init();
54703diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
54704index c7c83ff..bda9461 100644
54705--- a/fs/debugfs/inode.c
54706+++ b/fs/debugfs/inode.c
54707@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
54708 */
54709 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
54710 {
54711+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
54712+ return __create_file(name, S_IFDIR | S_IRWXU,
54713+#else
54714 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
54715+#endif
54716 parent, NULL, NULL);
54717 }
54718 EXPORT_SYMBOL_GPL(debugfs_create_dir);
54719diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
54720index 67e9b63..a9adb68 100644
54721--- a/fs/ecryptfs/inode.c
54722+++ b/fs/ecryptfs/inode.c
54723@@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
54724 old_fs = get_fs();
54725 set_fs(get_ds());
54726 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
54727- (char __user *)lower_buf,
54728+ (char __force_user *)lower_buf,
54729 PATH_MAX);
54730 set_fs(old_fs);
54731 if (rc < 0)
54732@@ -706,7 +706,7 @@ out:
54733 static void
54734 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
54735 {
54736- char *buf = nd_get_link(nd);
54737+ const char *buf = nd_get_link(nd);
54738 if (!IS_ERR(buf)) {
54739 /* Free the char* */
54740 kfree(buf);
54741diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
54742index e4141f2..d8263e8 100644
54743--- a/fs/ecryptfs/miscdev.c
54744+++ b/fs/ecryptfs/miscdev.c
54745@@ -304,7 +304,7 @@ check_list:
54746 goto out_unlock_msg_ctx;
54747 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
54748 if (msg_ctx->msg) {
54749- if (copy_to_user(&buf[i], packet_length, packet_length_size))
54750+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
54751 goto out_unlock_msg_ctx;
54752 i += packet_length_size;
54753 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
54754diff --git a/fs/exec.c b/fs/exec.c
54755index fd774c7..1c6a7bf 100644
54756--- a/fs/exec.c
54757+++ b/fs/exec.c
54758@@ -55,8 +55,20 @@
54759 #include <linux/pipe_fs_i.h>
54760 #include <linux/oom.h>
54761 #include <linux/compat.h>
54762+#include <linux/random.h>
54763+#include <linux/seq_file.h>
54764+#include <linux/coredump.h>
54765+#include <linux/mman.h>
54766+
54767+#ifdef CONFIG_PAX_REFCOUNT
54768+#include <linux/kallsyms.h>
54769+#include <linux/kdebug.h>
54770+#endif
54771+
54772+#include <trace/events/fs.h>
54773
54774 #include <asm/uaccess.h>
54775+#include <asm/sections.h>
54776 #include <asm/mmu_context.h>
54777 #include <asm/tlb.h>
54778
54779@@ -66,17 +78,32 @@
54780
54781 #include <trace/events/sched.h>
54782
54783+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
54784+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
54785+{
54786+ 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");
54787+}
54788+#endif
54789+
54790+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
54791+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
54792+EXPORT_SYMBOL(pax_set_initial_flags_func);
54793+#endif
54794+
54795 int suid_dumpable = 0;
54796
54797 static LIST_HEAD(formats);
54798 static DEFINE_RWLOCK(binfmt_lock);
54799
54800+extern int gr_process_kernel_exec_ban(void);
54801+extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
54802+
54803 void __register_binfmt(struct linux_binfmt * fmt, int insert)
54804 {
54805 BUG_ON(!fmt);
54806 write_lock(&binfmt_lock);
54807- insert ? list_add(&fmt->lh, &formats) :
54808- list_add_tail(&fmt->lh, &formats);
54809+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
54810+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
54811 write_unlock(&binfmt_lock);
54812 }
54813
54814@@ -85,7 +112,7 @@ EXPORT_SYMBOL(__register_binfmt);
54815 void unregister_binfmt(struct linux_binfmt * fmt)
54816 {
54817 write_lock(&binfmt_lock);
54818- list_del(&fmt->lh);
54819+ pax_list_del((struct list_head *)&fmt->lh);
54820 write_unlock(&binfmt_lock);
54821 }
54822
54823@@ -181,18 +208,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
54824 int write)
54825 {
54826 struct page *page;
54827- int ret;
54828
54829-#ifdef CONFIG_STACK_GROWSUP
54830- if (write) {
54831- ret = expand_downwards(bprm->vma, pos);
54832- if (ret < 0)
54833- return NULL;
54834- }
54835-#endif
54836- ret = get_user_pages(current, bprm->mm, pos,
54837- 1, write, 1, &page, NULL);
54838- if (ret <= 0)
54839+ if (0 > expand_downwards(bprm->vma, pos))
54840+ return NULL;
54841+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
54842 return NULL;
54843
54844 if (write) {
54845@@ -208,6 +227,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
54846 if (size <= ARG_MAX)
54847 return page;
54848
54849+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54850+ // only allow 512KB for argv+env on suid/sgid binaries
54851+ // to prevent easy ASLR exhaustion
54852+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
54853+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
54854+ (size > (512 * 1024))) {
54855+ put_page(page);
54856+ return NULL;
54857+ }
54858+#endif
54859+
54860 /*
54861 * Limit to 1/4-th the stack size for the argv+env strings.
54862 * This ensures that:
54863@@ -267,6 +297,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
54864 vma->vm_end = STACK_TOP_MAX;
54865 vma->vm_start = vma->vm_end - PAGE_SIZE;
54866 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
54867+
54868+#ifdef CONFIG_PAX_SEGMEXEC
54869+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
54870+#endif
54871+
54872 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
54873 INIT_LIST_HEAD(&vma->anon_vma_chain);
54874
54875@@ -277,6 +312,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
54876 mm->stack_vm = mm->total_vm = 1;
54877 up_write(&mm->mmap_sem);
54878 bprm->p = vma->vm_end - sizeof(void *);
54879+
54880+#ifdef CONFIG_PAX_RANDUSTACK
54881+ if (randomize_va_space)
54882+ bprm->p ^= prandom_u32() & ~PAGE_MASK;
54883+#endif
54884+
54885 return 0;
54886 err:
54887 up_write(&mm->mmap_sem);
54888@@ -397,7 +438,7 @@ struct user_arg_ptr {
54889 } ptr;
54890 };
54891
54892-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
54893+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
54894 {
54895 const char __user *native;
54896
54897@@ -406,14 +447,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
54898 compat_uptr_t compat;
54899
54900 if (get_user(compat, argv.ptr.compat + nr))
54901- return ERR_PTR(-EFAULT);
54902+ return (const char __force_user *)ERR_PTR(-EFAULT);
54903
54904 return compat_ptr(compat);
54905 }
54906 #endif
54907
54908 if (get_user(native, argv.ptr.native + nr))
54909- return ERR_PTR(-EFAULT);
54910+ return (const char __force_user *)ERR_PTR(-EFAULT);
54911
54912 return native;
54913 }
54914@@ -432,7 +473,7 @@ static int count(struct user_arg_ptr argv, int max)
54915 if (!p)
54916 break;
54917
54918- if (IS_ERR(p))
54919+ if (IS_ERR((const char __force_kernel *)p))
54920 return -EFAULT;
54921
54922 if (i >= max)
54923@@ -467,7 +508,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
54924
54925 ret = -EFAULT;
54926 str = get_user_arg_ptr(argv, argc);
54927- if (IS_ERR(str))
54928+ if (IS_ERR((const char __force_kernel *)str))
54929 goto out;
54930
54931 len = strnlen_user(str, MAX_ARG_STRLEN);
54932@@ -549,7 +590,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
54933 int r;
54934 mm_segment_t oldfs = get_fs();
54935 struct user_arg_ptr argv = {
54936- .ptr.native = (const char __user *const __user *)__argv,
54937+ .ptr.native = (const char __force_user * const __force_user *)__argv,
54938 };
54939
54940 set_fs(KERNEL_DS);
54941@@ -584,7 +625,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
54942 unsigned long new_end = old_end - shift;
54943 struct mmu_gather tlb;
54944
54945- BUG_ON(new_start > new_end);
54946+ if (new_start >= new_end || new_start < mmap_min_addr)
54947+ return -ENOMEM;
54948
54949 /*
54950 * ensure there are no vmas between where we want to go
54951@@ -593,6 +635,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
54952 if (vma != find_vma(mm, new_start))
54953 return -EFAULT;
54954
54955+#ifdef CONFIG_PAX_SEGMEXEC
54956+ BUG_ON(pax_find_mirror_vma(vma));
54957+#endif
54958+
54959 /*
54960 * cover the whole range: [new_start, old_end)
54961 */
54962@@ -673,10 +719,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
54963 stack_top = arch_align_stack(stack_top);
54964 stack_top = PAGE_ALIGN(stack_top);
54965
54966- if (unlikely(stack_top < mmap_min_addr) ||
54967- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
54968- return -ENOMEM;
54969-
54970 stack_shift = vma->vm_end - stack_top;
54971
54972 bprm->p -= stack_shift;
54973@@ -688,8 +730,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
54974 bprm->exec -= stack_shift;
54975
54976 down_write(&mm->mmap_sem);
54977+
54978+ /* Move stack pages down in memory. */
54979+ if (stack_shift) {
54980+ ret = shift_arg_pages(vma, stack_shift);
54981+ if (ret)
54982+ goto out_unlock;
54983+ }
54984+
54985 vm_flags = VM_STACK_FLAGS;
54986
54987+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
54988+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
54989+ vm_flags &= ~VM_EXEC;
54990+
54991+#ifdef CONFIG_PAX_MPROTECT
54992+ if (mm->pax_flags & MF_PAX_MPROTECT)
54993+ vm_flags &= ~VM_MAYEXEC;
54994+#endif
54995+
54996+ }
54997+#endif
54998+
54999 /*
55000 * Adjust stack execute permissions; explicitly enable for
55001 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
55002@@ -708,13 +770,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
55003 goto out_unlock;
55004 BUG_ON(prev != vma);
55005
55006- /* Move stack pages down in memory. */
55007- if (stack_shift) {
55008- ret = shift_arg_pages(vma, stack_shift);
55009- if (ret)
55010- goto out_unlock;
55011- }
55012-
55013 /* mprotect_fixup is overkill to remove the temporary stack flags */
55014 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
55015
55016@@ -738,6 +793,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
55017 #endif
55018 current->mm->start_stack = bprm->p;
55019 ret = expand_stack(vma, stack_base);
55020+
55021+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
55022+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
55023+ unsigned long size;
55024+ vm_flags_t vm_flags;
55025+
55026+ size = STACK_TOP - vma->vm_end;
55027+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
55028+
55029+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
55030+
55031+#ifdef CONFIG_X86
55032+ if (!ret) {
55033+ size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
55034+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
55035+ }
55036+#endif
55037+
55038+ }
55039+#endif
55040+
55041 if (ret)
55042 ret = -EFAULT;
55043
55044@@ -774,6 +850,8 @@ struct file *open_exec(const char *name)
55045
55046 fsnotify_open(file);
55047
55048+ trace_open_exec(name);
55049+
55050 err = deny_write_access(file);
55051 if (err)
55052 goto exit;
55053@@ -797,7 +875,7 @@ int kernel_read(struct file *file, loff_t offset,
55054 old_fs = get_fs();
55055 set_fs(get_ds());
55056 /* The cast to a user pointer is valid due to the set_fs() */
55057- result = vfs_read(file, (void __user *)addr, count, &pos);
55058+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
55059 set_fs(old_fs);
55060 return result;
55061 }
55062@@ -1253,7 +1331,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
55063 }
55064 rcu_read_unlock();
55065
55066- if (p->fs->users > n_fs) {
55067+ if (atomic_read(&p->fs->users) > n_fs) {
55068 bprm->unsafe |= LSM_UNSAFE_SHARE;
55069 } else {
55070 res = -EAGAIN;
55071@@ -1453,6 +1531,31 @@ int search_binary_handler(struct linux_binprm *bprm)
55072
55073 EXPORT_SYMBOL(search_binary_handler);
55074
55075+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55076+static DEFINE_PER_CPU(u64, exec_counter);
55077+static int __init init_exec_counters(void)
55078+{
55079+ unsigned int cpu;
55080+
55081+ for_each_possible_cpu(cpu) {
55082+ per_cpu(exec_counter, cpu) = (u64)cpu;
55083+ }
55084+
55085+ return 0;
55086+}
55087+early_initcall(init_exec_counters);
55088+static inline void increment_exec_counter(void)
55089+{
55090+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
55091+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
55092+}
55093+#else
55094+static inline void increment_exec_counter(void) {}
55095+#endif
55096+
55097+extern void gr_handle_exec_args(struct linux_binprm *bprm,
55098+ struct user_arg_ptr argv);
55099+
55100 /*
55101 * sys_execve() executes a new program.
55102 */
55103@@ -1460,12 +1563,19 @@ static int do_execve_common(const char *filename,
55104 struct user_arg_ptr argv,
55105 struct user_arg_ptr envp)
55106 {
55107+#ifdef CONFIG_GRKERNSEC
55108+ struct file *old_exec_file;
55109+ struct acl_subject_label *old_acl;
55110+ struct rlimit old_rlim[RLIM_NLIMITS];
55111+#endif
55112 struct linux_binprm *bprm;
55113 struct file *file;
55114 struct files_struct *displaced;
55115 bool clear_in_exec;
55116 int retval;
55117
55118+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
55119+
55120 /*
55121 * We move the actual failure in case of RLIMIT_NPROC excess from
55122 * set*uid() to execve() because too many poorly written programs
55123@@ -1506,12 +1616,22 @@ static int do_execve_common(const char *filename,
55124 if (IS_ERR(file))
55125 goto out_unmark;
55126
55127+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
55128+ retval = -EPERM;
55129+ goto out_file;
55130+ }
55131+
55132 sched_exec();
55133
55134 bprm->file = file;
55135 bprm->filename = filename;
55136 bprm->interp = filename;
55137
55138+ if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
55139+ retval = -EACCES;
55140+ goto out_file;
55141+ }
55142+
55143 retval = bprm_mm_init(bprm);
55144 if (retval)
55145 goto out_file;
55146@@ -1528,24 +1648,70 @@ static int do_execve_common(const char *filename,
55147 if (retval < 0)
55148 goto out;
55149
55150+#ifdef CONFIG_GRKERNSEC
55151+ old_acl = current->acl;
55152+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
55153+ old_exec_file = current->exec_file;
55154+ get_file(file);
55155+ current->exec_file = file;
55156+#endif
55157+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55158+ /* limit suid stack to 8MB
55159+ * we saved the old limits above and will restore them if this exec fails
55160+ */
55161+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
55162+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
55163+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
55164+#endif
55165+
55166+ if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
55167+ retval = -EPERM;
55168+ goto out_fail;
55169+ }
55170+
55171+ if (!gr_tpe_allow(file)) {
55172+ retval = -EACCES;
55173+ goto out_fail;
55174+ }
55175+
55176+ if (gr_check_crash_exec(file)) {
55177+ retval = -EACCES;
55178+ goto out_fail;
55179+ }
55180+
55181+ retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
55182+ bprm->unsafe);
55183+ if (retval < 0)
55184+ goto out_fail;
55185+
55186 retval = copy_strings_kernel(1, &bprm->filename, bprm);
55187 if (retval < 0)
55188- goto out;
55189+ goto out_fail;
55190
55191 bprm->exec = bprm->p;
55192 retval = copy_strings(bprm->envc, envp, bprm);
55193 if (retval < 0)
55194- goto out;
55195+ goto out_fail;
55196
55197 retval = copy_strings(bprm->argc, argv, bprm);
55198 if (retval < 0)
55199- goto out;
55200+ goto out_fail;
55201+
55202+ gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
55203+
55204+ gr_handle_exec_args(bprm, argv);
55205
55206 retval = search_binary_handler(bprm);
55207 if (retval < 0)
55208- goto out;
55209+ goto out_fail;
55210+#ifdef CONFIG_GRKERNSEC
55211+ if (old_exec_file)
55212+ fput(old_exec_file);
55213+#endif
55214
55215 /* execve succeeded */
55216+
55217+ increment_exec_counter();
55218 current->fs->in_exec = 0;
55219 current->in_execve = 0;
55220 acct_update_integrals(current);
55221@@ -1554,6 +1720,14 @@ static int do_execve_common(const char *filename,
55222 put_files_struct(displaced);
55223 return retval;
55224
55225+out_fail:
55226+#ifdef CONFIG_GRKERNSEC
55227+ current->acl = old_acl;
55228+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
55229+ fput(current->exec_file);
55230+ current->exec_file = old_exec_file;
55231+#endif
55232+
55233 out:
55234 if (bprm->mm) {
55235 acct_arg_size(bprm, 0);
55236@@ -1702,3 +1876,287 @@ asmlinkage long compat_sys_execve(const char __user * filename,
55237 return error;
55238 }
55239 #endif
55240+
55241+int pax_check_flags(unsigned long *flags)
55242+{
55243+ int retval = 0;
55244+
55245+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
55246+ if (*flags & MF_PAX_SEGMEXEC)
55247+ {
55248+ *flags &= ~MF_PAX_SEGMEXEC;
55249+ retval = -EINVAL;
55250+ }
55251+#endif
55252+
55253+ if ((*flags & MF_PAX_PAGEEXEC)
55254+
55255+#ifdef CONFIG_PAX_PAGEEXEC
55256+ && (*flags & MF_PAX_SEGMEXEC)
55257+#endif
55258+
55259+ )
55260+ {
55261+ *flags &= ~MF_PAX_PAGEEXEC;
55262+ retval = -EINVAL;
55263+ }
55264+
55265+ if ((*flags & MF_PAX_MPROTECT)
55266+
55267+#ifdef CONFIG_PAX_MPROTECT
55268+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
55269+#endif
55270+
55271+ )
55272+ {
55273+ *flags &= ~MF_PAX_MPROTECT;
55274+ retval = -EINVAL;
55275+ }
55276+
55277+ if ((*flags & MF_PAX_EMUTRAMP)
55278+
55279+#ifdef CONFIG_PAX_EMUTRAMP
55280+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
55281+#endif
55282+
55283+ )
55284+ {
55285+ *flags &= ~MF_PAX_EMUTRAMP;
55286+ retval = -EINVAL;
55287+ }
55288+
55289+ return retval;
55290+}
55291+
55292+EXPORT_SYMBOL(pax_check_flags);
55293+
55294+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
55295+char *pax_get_path(const struct path *path, char *buf, int buflen)
55296+{
55297+ char *pathname = d_path(path, buf, buflen);
55298+
55299+ if (IS_ERR(pathname))
55300+ goto toolong;
55301+
55302+ pathname = mangle_path(buf, pathname, "\t\n\\");
55303+ if (!pathname)
55304+ goto toolong;
55305+
55306+ *pathname = 0;
55307+ return buf;
55308+
55309+toolong:
55310+ return "<path too long>";
55311+}
55312+EXPORT_SYMBOL(pax_get_path);
55313+
55314+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
55315+{
55316+ struct task_struct *tsk = current;
55317+ struct mm_struct *mm = current->mm;
55318+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
55319+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
55320+ char *path_exec = NULL;
55321+ char *path_fault = NULL;
55322+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
55323+ siginfo_t info = { };
55324+
55325+ if (buffer_exec && buffer_fault) {
55326+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
55327+
55328+ down_read(&mm->mmap_sem);
55329+ vma = mm->mmap;
55330+ while (vma && (!vma_exec || !vma_fault)) {
55331+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
55332+ vma_exec = vma;
55333+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
55334+ vma_fault = vma;
55335+ vma = vma->vm_next;
55336+ }
55337+ if (vma_exec)
55338+ path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
55339+ if (vma_fault) {
55340+ start = vma_fault->vm_start;
55341+ end = vma_fault->vm_end;
55342+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
55343+ if (vma_fault->vm_file)
55344+ path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
55345+ else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
55346+ path_fault = "<heap>";
55347+ else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
55348+ path_fault = "<stack>";
55349+ else
55350+ path_fault = "<anonymous mapping>";
55351+ }
55352+ up_read(&mm->mmap_sem);
55353+ }
55354+ if (tsk->signal->curr_ip)
55355+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
55356+ else
55357+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
55358+ 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),
55359+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
55360+ free_page((unsigned long)buffer_exec);
55361+ free_page((unsigned long)buffer_fault);
55362+ pax_report_insns(regs, pc, sp);
55363+ info.si_signo = SIGKILL;
55364+ info.si_errno = 0;
55365+ info.si_code = SI_KERNEL;
55366+ info.si_pid = 0;
55367+ info.si_uid = 0;
55368+ do_coredump(&info);
55369+}
55370+#endif
55371+
55372+#ifdef CONFIG_PAX_REFCOUNT
55373+void pax_report_refcount_overflow(struct pt_regs *regs)
55374+{
55375+ if (current->signal->curr_ip)
55376+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
55377+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
55378+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
55379+ else
55380+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
55381+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
55382+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
55383+ preempt_disable();
55384+ show_regs(regs);
55385+ preempt_enable();
55386+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
55387+}
55388+#endif
55389+
55390+#ifdef CONFIG_PAX_USERCOPY
55391+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
55392+static noinline int check_stack_object(const void *obj, unsigned long len)
55393+{
55394+ const void * const stack = task_stack_page(current);
55395+ const void * const stackend = stack + THREAD_SIZE;
55396+
55397+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
55398+ const void *frame = NULL;
55399+ const void *oldframe;
55400+#endif
55401+
55402+ if (obj + len < obj)
55403+ return -1;
55404+
55405+ if (obj + len <= stack || stackend <= obj)
55406+ return 0;
55407+
55408+ if (obj < stack || stackend < obj + len)
55409+ return -1;
55410+
55411+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
55412+ oldframe = __builtin_frame_address(1);
55413+ if (oldframe)
55414+ frame = __builtin_frame_address(2);
55415+ /*
55416+ low ----------------------------------------------> high
55417+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
55418+ ^----------------^
55419+ allow copies only within here
55420+ */
55421+ while (stack <= frame && frame < stackend) {
55422+ /* if obj + len extends past the last frame, this
55423+ check won't pass and the next frame will be 0,
55424+ causing us to bail out and correctly report
55425+ the copy as invalid
55426+ */
55427+ if (obj + len <= frame)
55428+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
55429+ oldframe = frame;
55430+ frame = *(const void * const *)frame;
55431+ }
55432+ return -1;
55433+#else
55434+ return 1;
55435+#endif
55436+}
55437+
55438+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
55439+{
55440+ if (current->signal->curr_ip)
55441+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
55442+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
55443+ else
55444+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
55445+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
55446+ dump_stack();
55447+ gr_handle_kernel_exploit();
55448+ do_group_exit(SIGKILL);
55449+}
55450+#endif
55451+
55452+#ifdef CONFIG_PAX_USERCOPY
55453+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
55454+{
55455+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
55456+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
55457+#ifdef CONFIG_MODULES
55458+ unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
55459+#else
55460+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
55461+#endif
55462+
55463+#else
55464+ unsigned long textlow = (unsigned long)_stext;
55465+ unsigned long texthigh = (unsigned long)_etext;
55466+#endif
55467+
55468+ if (high <= textlow || low > texthigh)
55469+ return false;
55470+ else
55471+ return true;
55472+}
55473+#endif
55474+
55475+void __check_object_size(const void *ptr, unsigned long n, bool to_user)
55476+{
55477+
55478+#ifdef CONFIG_PAX_USERCOPY
55479+ const char *type;
55480+
55481+ if (!n)
55482+ return;
55483+
55484+ type = check_heap_object(ptr, n);
55485+ if (!type) {
55486+ int ret = check_stack_object(ptr, n);
55487+ if (ret == 1 || ret == 2)
55488+ return;
55489+ if (ret == 0) {
55490+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
55491+ type = "<kernel text>";
55492+ else
55493+ return;
55494+ } else
55495+ type = "<process stack>";
55496+ }
55497+
55498+ pax_report_usercopy(ptr, n, to_user, type);
55499+#endif
55500+
55501+}
55502+EXPORT_SYMBOL(__check_object_size);
55503+
55504+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
55505+void pax_track_stack(void)
55506+{
55507+ unsigned long sp = (unsigned long)&sp;
55508+ if (sp < current_thread_info()->lowest_stack &&
55509+ sp > (unsigned long)task_stack_page(current))
55510+ current_thread_info()->lowest_stack = sp;
55511+}
55512+EXPORT_SYMBOL(pax_track_stack);
55513+#endif
55514+
55515+#ifdef CONFIG_PAX_SIZE_OVERFLOW
55516+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
55517+{
55518+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
55519+ dump_stack();
55520+ do_group_exit(SIGKILL);
55521+}
55522+EXPORT_SYMBOL(report_size_overflow);
55523+#endif
55524diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
55525index 9f9992b..8b59411 100644
55526--- a/fs/ext2/balloc.c
55527+++ b/fs/ext2/balloc.c
55528@@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
55529
55530 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
55531 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
55532- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
55533+ if (free_blocks < root_blocks + 1 &&
55534 !uid_eq(sbi->s_resuid, current_fsuid()) &&
55535 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
55536- !in_group_p (sbi->s_resgid))) {
55537+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
55538 return 0;
55539 }
55540 return 1;
55541diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
55542index 22548f5..41521d8 100644
55543--- a/fs/ext3/balloc.c
55544+++ b/fs/ext3/balloc.c
55545@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
55546
55547 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
55548 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
55549- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
55550+ if (free_blocks < root_blocks + 1 &&
55551 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
55552 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
55553- !in_group_p (sbi->s_resgid))) {
55554+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
55555 return 0;
55556 }
55557 return 1;
55558diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
55559index ddd715e..c772f88 100644
55560--- a/fs/ext4/balloc.c
55561+++ b/fs/ext4/balloc.c
55562@@ -528,8 +528,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
55563 /* Hm, nope. Are (enough) root reserved clusters available? */
55564 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
55565 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
55566- capable(CAP_SYS_RESOURCE) ||
55567- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
55568+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
55569+ capable_nolog(CAP_SYS_RESOURCE)) {
55570
55571 if (free_clusters >= (nclusters + dirty_clusters +
55572 resv_clusters))
55573diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
55574index 0ab26fb..b6ecb39 100644
55575--- a/fs/ext4/ext4.h
55576+++ b/fs/ext4/ext4.h
55577@@ -1247,19 +1247,19 @@ struct ext4_sb_info {
55578 unsigned long s_mb_last_start;
55579
55580 /* stats for buddy allocator */
55581- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
55582- atomic_t s_bal_success; /* we found long enough chunks */
55583- atomic_t s_bal_allocated; /* in blocks */
55584- atomic_t s_bal_ex_scanned; /* total extents scanned */
55585- atomic_t s_bal_goals; /* goal hits */
55586- atomic_t s_bal_breaks; /* too long searches */
55587- atomic_t s_bal_2orders; /* 2^order hits */
55588+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
55589+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
55590+ atomic_unchecked_t s_bal_allocated; /* in blocks */
55591+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
55592+ atomic_unchecked_t s_bal_goals; /* goal hits */
55593+ atomic_unchecked_t s_bal_breaks; /* too long searches */
55594+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
55595 spinlock_t s_bal_lock;
55596 unsigned long s_mb_buddies_generated;
55597 unsigned long long s_mb_generation_time;
55598- atomic_t s_mb_lost_chunks;
55599- atomic_t s_mb_preallocated;
55600- atomic_t s_mb_discarded;
55601+ atomic_unchecked_t s_mb_lost_chunks;
55602+ atomic_unchecked_t s_mb_preallocated;
55603+ atomic_unchecked_t s_mb_discarded;
55604 atomic_t s_lock_busy;
55605
55606 /* locality groups */
55607diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
55608index 4bbbf13b..dcceaeb 100644
55609--- a/fs/ext4/mballoc.c
55610+++ b/fs/ext4/mballoc.c
55611@@ -1865,7 +1865,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
55612 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
55613
55614 if (EXT4_SB(sb)->s_mb_stats)
55615- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
55616+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
55617
55618 break;
55619 }
55620@@ -2171,7 +2171,7 @@ repeat:
55621 ac->ac_status = AC_STATUS_CONTINUE;
55622 ac->ac_flags |= EXT4_MB_HINT_FIRST;
55623 cr = 3;
55624- atomic_inc(&sbi->s_mb_lost_chunks);
55625+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
55626 goto repeat;
55627 }
55628 }
55629@@ -2679,25 +2679,25 @@ int ext4_mb_release(struct super_block *sb)
55630 if (sbi->s_mb_stats) {
55631 ext4_msg(sb, KERN_INFO,
55632 "mballoc: %u blocks %u reqs (%u success)",
55633- atomic_read(&sbi->s_bal_allocated),
55634- atomic_read(&sbi->s_bal_reqs),
55635- atomic_read(&sbi->s_bal_success));
55636+ atomic_read_unchecked(&sbi->s_bal_allocated),
55637+ atomic_read_unchecked(&sbi->s_bal_reqs),
55638+ atomic_read_unchecked(&sbi->s_bal_success));
55639 ext4_msg(sb, KERN_INFO,
55640 "mballoc: %u extents scanned, %u goal hits, "
55641 "%u 2^N hits, %u breaks, %u lost",
55642- atomic_read(&sbi->s_bal_ex_scanned),
55643- atomic_read(&sbi->s_bal_goals),
55644- atomic_read(&sbi->s_bal_2orders),
55645- atomic_read(&sbi->s_bal_breaks),
55646- atomic_read(&sbi->s_mb_lost_chunks));
55647+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
55648+ atomic_read_unchecked(&sbi->s_bal_goals),
55649+ atomic_read_unchecked(&sbi->s_bal_2orders),
55650+ atomic_read_unchecked(&sbi->s_bal_breaks),
55651+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
55652 ext4_msg(sb, KERN_INFO,
55653 "mballoc: %lu generated and it took %Lu",
55654 sbi->s_mb_buddies_generated,
55655 sbi->s_mb_generation_time);
55656 ext4_msg(sb, KERN_INFO,
55657 "mballoc: %u preallocated, %u discarded",
55658- atomic_read(&sbi->s_mb_preallocated),
55659- atomic_read(&sbi->s_mb_discarded));
55660+ atomic_read_unchecked(&sbi->s_mb_preallocated),
55661+ atomic_read_unchecked(&sbi->s_mb_discarded));
55662 }
55663
55664 free_percpu(sbi->s_locality_groups);
55665@@ -3151,16 +3151,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
55666 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
55667
55668 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
55669- atomic_inc(&sbi->s_bal_reqs);
55670- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
55671+ atomic_inc_unchecked(&sbi->s_bal_reqs);
55672+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
55673 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
55674- atomic_inc(&sbi->s_bal_success);
55675- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
55676+ atomic_inc_unchecked(&sbi->s_bal_success);
55677+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
55678 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
55679 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
55680- atomic_inc(&sbi->s_bal_goals);
55681+ atomic_inc_unchecked(&sbi->s_bal_goals);
55682 if (ac->ac_found > sbi->s_mb_max_to_scan)
55683- atomic_inc(&sbi->s_bal_breaks);
55684+ atomic_inc_unchecked(&sbi->s_bal_breaks);
55685 }
55686
55687 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
55688@@ -3560,7 +3560,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
55689 trace_ext4_mb_new_inode_pa(ac, pa);
55690
55691 ext4_mb_use_inode_pa(ac, pa);
55692- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
55693+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
55694
55695 ei = EXT4_I(ac->ac_inode);
55696 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
55697@@ -3620,7 +3620,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
55698 trace_ext4_mb_new_group_pa(ac, pa);
55699
55700 ext4_mb_use_group_pa(ac, pa);
55701- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
55702+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
55703
55704 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
55705 lg = ac->ac_lg;
55706@@ -3709,7 +3709,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
55707 * from the bitmap and continue.
55708 */
55709 }
55710- atomic_add(free, &sbi->s_mb_discarded);
55711+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
55712
55713 return err;
55714 }
55715@@ -3727,7 +3727,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
55716 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
55717 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
55718 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
55719- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
55720+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
55721 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
55722
55723 return 0;
55724diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
55725index 214461e..3614c89 100644
55726--- a/fs/ext4/mmp.c
55727+++ b/fs/ext4/mmp.c
55728@@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
55729 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
55730 const char *function, unsigned int line, const char *msg)
55731 {
55732- __ext4_warning(sb, function, line, msg);
55733+ __ext4_warning(sb, function, line, "%s", msg);
55734 __ext4_warning(sb, function, line,
55735 "MMP failure info: last update time: %llu, last update "
55736 "node: %s, last update device: %s\n",
55737diff --git a/fs/ext4/super.c b/fs/ext4/super.c
55738index b59373b..f41c2b5 100644
55739--- a/fs/ext4/super.c
55740+++ b/fs/ext4/super.c
55741@@ -1254,7 +1254,7 @@ static ext4_fsblk_t get_sb_block(void **data)
55742 }
55743
55744 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
55745-static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
55746+static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
55747 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
55748
55749 #ifdef CONFIG_QUOTA
55750@@ -2394,7 +2394,7 @@ struct ext4_attr {
55751 int offset;
55752 int deprecated_val;
55753 } u;
55754-};
55755+} __do_const;
55756
55757 static int parse_strtoull(const char *buf,
55758 unsigned long long max, unsigned long long *value)
55759diff --git a/fs/fcntl.c b/fs/fcntl.c
55760index 65343c3..9969dcf 100644
55761--- a/fs/fcntl.c
55762+++ b/fs/fcntl.c
55763@@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
55764 if (err)
55765 return err;
55766
55767+ if (gr_handle_chroot_fowner(pid, type))
55768+ return -ENOENT;
55769+ if (gr_check_protected_task_fowner(pid, type))
55770+ return -EACCES;
55771+
55772 f_modown(filp, pid, type, force);
55773 return 0;
55774 }
55775diff --git a/fs/fhandle.c b/fs/fhandle.c
55776index 999ff5c..41f4109 100644
55777--- a/fs/fhandle.c
55778+++ b/fs/fhandle.c
55779@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
55780 } else
55781 retval = 0;
55782 /* copy the mount id */
55783- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
55784- sizeof(*mnt_id)) ||
55785+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
55786 copy_to_user(ufh, handle,
55787 sizeof(struct file_handle) + handle_bytes))
55788 retval = -EFAULT;
55789diff --git a/fs/file.c b/fs/file.c
55790index 4a78f98..9447397 100644
55791--- a/fs/file.c
55792+++ b/fs/file.c
55793@@ -16,6 +16,7 @@
55794 #include <linux/slab.h>
55795 #include <linux/vmalloc.h>
55796 #include <linux/file.h>
55797+#include <linux/security.h>
55798 #include <linux/fdtable.h>
55799 #include <linux/bitops.h>
55800 #include <linux/interrupt.h>
55801@@ -828,6 +829,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
55802 if (!file)
55803 return __close_fd(files, fd);
55804
55805+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
55806 if (fd >= rlimit(RLIMIT_NOFILE))
55807 return -EBADF;
55808
55809@@ -854,6 +856,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
55810 if (unlikely(oldfd == newfd))
55811 return -EINVAL;
55812
55813+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
55814 if (newfd >= rlimit(RLIMIT_NOFILE))
55815 return -EBADF;
55816
55817@@ -909,6 +912,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
55818 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
55819 {
55820 int err;
55821+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
55822 if (from >= rlimit(RLIMIT_NOFILE))
55823 return -EINVAL;
55824 err = alloc_fd(from, flags);
55825diff --git a/fs/filesystems.c b/fs/filesystems.c
55826index 92567d9..fcd8cbf 100644
55827--- a/fs/filesystems.c
55828+++ b/fs/filesystems.c
55829@@ -273,7 +273,11 @@ struct file_system_type *get_fs_type(const char *name)
55830 int len = dot ? dot - name : strlen(name);
55831
55832 fs = __get_fs_type(name, len);
55833+#ifdef CONFIG_GRKERNSEC_MODHARDEN
55834+ if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
55835+#else
55836 if (!fs && (request_module("fs-%.*s", len, name) == 0))
55837+#endif
55838 fs = __get_fs_type(name, len);
55839
55840 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
55841diff --git a/fs/fs_struct.c b/fs/fs_struct.c
55842index d8ac61d..79a36f0 100644
55843--- a/fs/fs_struct.c
55844+++ b/fs/fs_struct.c
55845@@ -4,6 +4,7 @@
55846 #include <linux/path.h>
55847 #include <linux/slab.h>
55848 #include <linux/fs_struct.h>
55849+#include <linux/grsecurity.h>
55850 #include "internal.h"
55851
55852 /*
55853@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
55854 write_seqcount_begin(&fs->seq);
55855 old_root = fs->root;
55856 fs->root = *path;
55857+ gr_set_chroot_entries(current, path);
55858 write_seqcount_end(&fs->seq);
55859 spin_unlock(&fs->lock);
55860 if (old_root.dentry)
55861@@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
55862 int hits = 0;
55863 spin_lock(&fs->lock);
55864 write_seqcount_begin(&fs->seq);
55865+ /* this root replacement is only done by pivot_root,
55866+ leave grsec's chroot tagging alone for this task
55867+ so that a pivoted root isn't treated as a chroot
55868+ */
55869 hits += replace_path(&fs->root, old_root, new_root);
55870 hits += replace_path(&fs->pwd, old_root, new_root);
55871 write_seqcount_end(&fs->seq);
55872@@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
55873 task_lock(tsk);
55874 spin_lock(&fs->lock);
55875 tsk->fs = NULL;
55876- kill = !--fs->users;
55877+ gr_clear_chroot_entries(tsk);
55878+ kill = !atomic_dec_return(&fs->users);
55879 spin_unlock(&fs->lock);
55880 task_unlock(tsk);
55881 if (kill)
55882@@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
55883 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
55884 /* We don't need to lock fs - think why ;-) */
55885 if (fs) {
55886- fs->users = 1;
55887+ atomic_set(&fs->users, 1);
55888 fs->in_exec = 0;
55889 spin_lock_init(&fs->lock);
55890 seqcount_init(&fs->seq);
55891@@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
55892 spin_lock(&old->lock);
55893 fs->root = old->root;
55894 path_get(&fs->root);
55895+ /* instead of calling gr_set_chroot_entries here,
55896+ we call it from every caller of this function
55897+ */
55898 fs->pwd = old->pwd;
55899 path_get(&fs->pwd);
55900 spin_unlock(&old->lock);
55901@@ -139,8 +149,9 @@ int unshare_fs_struct(void)
55902
55903 task_lock(current);
55904 spin_lock(&fs->lock);
55905- kill = !--fs->users;
55906+ kill = !atomic_dec_return(&fs->users);
55907 current->fs = new_fs;
55908+ gr_set_chroot_entries(current, &new_fs->root);
55909 spin_unlock(&fs->lock);
55910 task_unlock(current);
55911
55912@@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
55913
55914 int current_umask(void)
55915 {
55916- return current->fs->umask;
55917+ return current->fs->umask | gr_acl_umask();
55918 }
55919 EXPORT_SYMBOL(current_umask);
55920
55921 /* to be mentioned only in INIT_TASK */
55922 struct fs_struct init_fs = {
55923- .users = 1,
55924+ .users = ATOMIC_INIT(1),
55925 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
55926 .seq = SEQCNT_ZERO,
55927 .umask = 0022,
55928diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
55929index 0e91a3c..6c6d2e0 100644
55930--- a/fs/fscache/cookie.c
55931+++ b/fs/fscache/cookie.c
55932@@ -19,7 +19,7 @@
55933
55934 struct kmem_cache *fscache_cookie_jar;
55935
55936-static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
55937+static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
55938
55939 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
55940 static int fscache_alloc_object(struct fscache_cache *cache,
55941@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
55942 parent ? (char *) parent->def->name : "<no-parent>",
55943 def->name, netfs_data);
55944
55945- fscache_stat(&fscache_n_acquires);
55946+ fscache_stat_unchecked(&fscache_n_acquires);
55947
55948 /* if there's no parent cookie, then we don't create one here either */
55949 if (!parent) {
55950- fscache_stat(&fscache_n_acquires_null);
55951+ fscache_stat_unchecked(&fscache_n_acquires_null);
55952 _leave(" [no parent]");
55953 return NULL;
55954 }
55955@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
55956 /* allocate and initialise a cookie */
55957 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
55958 if (!cookie) {
55959- fscache_stat(&fscache_n_acquires_oom);
55960+ fscache_stat_unchecked(&fscache_n_acquires_oom);
55961 _leave(" [ENOMEM]");
55962 return NULL;
55963 }
55964@@ -114,13 +114,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
55965
55966 switch (cookie->def->type) {
55967 case FSCACHE_COOKIE_TYPE_INDEX:
55968- fscache_stat(&fscache_n_cookie_index);
55969+ fscache_stat_unchecked(&fscache_n_cookie_index);
55970 break;
55971 case FSCACHE_COOKIE_TYPE_DATAFILE:
55972- fscache_stat(&fscache_n_cookie_data);
55973+ fscache_stat_unchecked(&fscache_n_cookie_data);
55974 break;
55975 default:
55976- fscache_stat(&fscache_n_cookie_special);
55977+ fscache_stat_unchecked(&fscache_n_cookie_special);
55978 break;
55979 }
55980
55981@@ -131,13 +131,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
55982 if (fscache_acquire_non_index_cookie(cookie) < 0) {
55983 atomic_dec(&parent->n_children);
55984 __fscache_cookie_put(cookie);
55985- fscache_stat(&fscache_n_acquires_nobufs);
55986+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
55987 _leave(" = NULL");
55988 return NULL;
55989 }
55990 }
55991
55992- fscache_stat(&fscache_n_acquires_ok);
55993+ fscache_stat_unchecked(&fscache_n_acquires_ok);
55994 _leave(" = %p", cookie);
55995 return cookie;
55996 }
55997@@ -173,7 +173,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
55998 cache = fscache_select_cache_for_object(cookie->parent);
55999 if (!cache) {
56000 up_read(&fscache_addremove_sem);
56001- fscache_stat(&fscache_n_acquires_no_cache);
56002+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
56003 _leave(" = -ENOMEDIUM [no cache]");
56004 return -ENOMEDIUM;
56005 }
56006@@ -259,14 +259,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
56007 object = cache->ops->alloc_object(cache, cookie);
56008 fscache_stat_d(&fscache_n_cop_alloc_object);
56009 if (IS_ERR(object)) {
56010- fscache_stat(&fscache_n_object_no_alloc);
56011+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
56012 ret = PTR_ERR(object);
56013 goto error;
56014 }
56015
56016- fscache_stat(&fscache_n_object_alloc);
56017+ fscache_stat_unchecked(&fscache_n_object_alloc);
56018
56019- object->debug_id = atomic_inc_return(&fscache_object_debug_id);
56020+ object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
56021
56022 _debug("ALLOC OBJ%x: %s {%lx}",
56023 object->debug_id, cookie->def->name, object->events);
56024@@ -380,7 +380,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
56025
56026 _enter("{%s}", cookie->def->name);
56027
56028- fscache_stat(&fscache_n_invalidates);
56029+ fscache_stat_unchecked(&fscache_n_invalidates);
56030
56031 /* Only permit invalidation of data files. Invalidating an index will
56032 * require the caller to release all its attachments to the tree rooted
56033@@ -438,10 +438,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
56034 {
56035 struct fscache_object *object;
56036
56037- fscache_stat(&fscache_n_updates);
56038+ fscache_stat_unchecked(&fscache_n_updates);
56039
56040 if (!cookie) {
56041- fscache_stat(&fscache_n_updates_null);
56042+ fscache_stat_unchecked(&fscache_n_updates_null);
56043 _leave(" [no cookie]");
56044 return;
56045 }
56046@@ -473,12 +473,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
56047 {
56048 struct fscache_object *object;
56049
56050- fscache_stat(&fscache_n_relinquishes);
56051+ fscache_stat_unchecked(&fscache_n_relinquishes);
56052 if (retire)
56053- fscache_stat(&fscache_n_relinquishes_retire);
56054+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
56055
56056 if (!cookie) {
56057- fscache_stat(&fscache_n_relinquishes_null);
56058+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
56059 _leave(" [no cookie]");
56060 return;
56061 }
56062diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
56063index 12d505b..86473a3 100644
56064--- a/fs/fscache/internal.h
56065+++ b/fs/fscache/internal.h
56066@@ -147,101 +147,101 @@ extern void fscache_proc_cleanup(void);
56067 * stats.c
56068 */
56069 #ifdef CONFIG_FSCACHE_STATS
56070-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
56071-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
56072+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
56073+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
56074
56075-extern atomic_t fscache_n_op_pend;
56076-extern atomic_t fscache_n_op_run;
56077-extern atomic_t fscache_n_op_enqueue;
56078-extern atomic_t fscache_n_op_deferred_release;
56079-extern atomic_t fscache_n_op_release;
56080-extern atomic_t fscache_n_op_gc;
56081-extern atomic_t fscache_n_op_cancelled;
56082-extern atomic_t fscache_n_op_rejected;
56083+extern atomic_unchecked_t fscache_n_op_pend;
56084+extern atomic_unchecked_t fscache_n_op_run;
56085+extern atomic_unchecked_t fscache_n_op_enqueue;
56086+extern atomic_unchecked_t fscache_n_op_deferred_release;
56087+extern atomic_unchecked_t fscache_n_op_release;
56088+extern atomic_unchecked_t fscache_n_op_gc;
56089+extern atomic_unchecked_t fscache_n_op_cancelled;
56090+extern atomic_unchecked_t fscache_n_op_rejected;
56091
56092-extern atomic_t fscache_n_attr_changed;
56093-extern atomic_t fscache_n_attr_changed_ok;
56094-extern atomic_t fscache_n_attr_changed_nobufs;
56095-extern atomic_t fscache_n_attr_changed_nomem;
56096-extern atomic_t fscache_n_attr_changed_calls;
56097+extern atomic_unchecked_t fscache_n_attr_changed;
56098+extern atomic_unchecked_t fscache_n_attr_changed_ok;
56099+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
56100+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
56101+extern atomic_unchecked_t fscache_n_attr_changed_calls;
56102
56103-extern atomic_t fscache_n_allocs;
56104-extern atomic_t fscache_n_allocs_ok;
56105-extern atomic_t fscache_n_allocs_wait;
56106-extern atomic_t fscache_n_allocs_nobufs;
56107-extern atomic_t fscache_n_allocs_intr;
56108-extern atomic_t fscache_n_allocs_object_dead;
56109-extern atomic_t fscache_n_alloc_ops;
56110-extern atomic_t fscache_n_alloc_op_waits;
56111+extern atomic_unchecked_t fscache_n_allocs;
56112+extern atomic_unchecked_t fscache_n_allocs_ok;
56113+extern atomic_unchecked_t fscache_n_allocs_wait;
56114+extern atomic_unchecked_t fscache_n_allocs_nobufs;
56115+extern atomic_unchecked_t fscache_n_allocs_intr;
56116+extern atomic_unchecked_t fscache_n_allocs_object_dead;
56117+extern atomic_unchecked_t fscache_n_alloc_ops;
56118+extern atomic_unchecked_t fscache_n_alloc_op_waits;
56119
56120-extern atomic_t fscache_n_retrievals;
56121-extern atomic_t fscache_n_retrievals_ok;
56122-extern atomic_t fscache_n_retrievals_wait;
56123-extern atomic_t fscache_n_retrievals_nodata;
56124-extern atomic_t fscache_n_retrievals_nobufs;
56125-extern atomic_t fscache_n_retrievals_intr;
56126-extern atomic_t fscache_n_retrievals_nomem;
56127-extern atomic_t fscache_n_retrievals_object_dead;
56128-extern atomic_t fscache_n_retrieval_ops;
56129-extern atomic_t fscache_n_retrieval_op_waits;
56130+extern atomic_unchecked_t fscache_n_retrievals;
56131+extern atomic_unchecked_t fscache_n_retrievals_ok;
56132+extern atomic_unchecked_t fscache_n_retrievals_wait;
56133+extern atomic_unchecked_t fscache_n_retrievals_nodata;
56134+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
56135+extern atomic_unchecked_t fscache_n_retrievals_intr;
56136+extern atomic_unchecked_t fscache_n_retrievals_nomem;
56137+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
56138+extern atomic_unchecked_t fscache_n_retrieval_ops;
56139+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
56140
56141-extern atomic_t fscache_n_stores;
56142-extern atomic_t fscache_n_stores_ok;
56143-extern atomic_t fscache_n_stores_again;
56144-extern atomic_t fscache_n_stores_nobufs;
56145-extern atomic_t fscache_n_stores_oom;
56146-extern atomic_t fscache_n_store_ops;
56147-extern atomic_t fscache_n_store_calls;
56148-extern atomic_t fscache_n_store_pages;
56149-extern atomic_t fscache_n_store_radix_deletes;
56150-extern atomic_t fscache_n_store_pages_over_limit;
56151+extern atomic_unchecked_t fscache_n_stores;
56152+extern atomic_unchecked_t fscache_n_stores_ok;
56153+extern atomic_unchecked_t fscache_n_stores_again;
56154+extern atomic_unchecked_t fscache_n_stores_nobufs;
56155+extern atomic_unchecked_t fscache_n_stores_oom;
56156+extern atomic_unchecked_t fscache_n_store_ops;
56157+extern atomic_unchecked_t fscache_n_store_calls;
56158+extern atomic_unchecked_t fscache_n_store_pages;
56159+extern atomic_unchecked_t fscache_n_store_radix_deletes;
56160+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
56161
56162-extern atomic_t fscache_n_store_vmscan_not_storing;
56163-extern atomic_t fscache_n_store_vmscan_gone;
56164-extern atomic_t fscache_n_store_vmscan_busy;
56165-extern atomic_t fscache_n_store_vmscan_cancelled;
56166-extern atomic_t fscache_n_store_vmscan_wait;
56167+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
56168+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
56169+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
56170+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
56171+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
56172
56173-extern atomic_t fscache_n_marks;
56174-extern atomic_t fscache_n_uncaches;
56175+extern atomic_unchecked_t fscache_n_marks;
56176+extern atomic_unchecked_t fscache_n_uncaches;
56177
56178-extern atomic_t fscache_n_acquires;
56179-extern atomic_t fscache_n_acquires_null;
56180-extern atomic_t fscache_n_acquires_no_cache;
56181-extern atomic_t fscache_n_acquires_ok;
56182-extern atomic_t fscache_n_acquires_nobufs;
56183-extern atomic_t fscache_n_acquires_oom;
56184+extern atomic_unchecked_t fscache_n_acquires;
56185+extern atomic_unchecked_t fscache_n_acquires_null;
56186+extern atomic_unchecked_t fscache_n_acquires_no_cache;
56187+extern atomic_unchecked_t fscache_n_acquires_ok;
56188+extern atomic_unchecked_t fscache_n_acquires_nobufs;
56189+extern atomic_unchecked_t fscache_n_acquires_oom;
56190
56191-extern atomic_t fscache_n_invalidates;
56192-extern atomic_t fscache_n_invalidates_run;
56193+extern atomic_unchecked_t fscache_n_invalidates;
56194+extern atomic_unchecked_t fscache_n_invalidates_run;
56195
56196-extern atomic_t fscache_n_updates;
56197-extern atomic_t fscache_n_updates_null;
56198-extern atomic_t fscache_n_updates_run;
56199+extern atomic_unchecked_t fscache_n_updates;
56200+extern atomic_unchecked_t fscache_n_updates_null;
56201+extern atomic_unchecked_t fscache_n_updates_run;
56202
56203-extern atomic_t fscache_n_relinquishes;
56204-extern atomic_t fscache_n_relinquishes_null;
56205-extern atomic_t fscache_n_relinquishes_waitcrt;
56206-extern atomic_t fscache_n_relinquishes_retire;
56207+extern atomic_unchecked_t fscache_n_relinquishes;
56208+extern atomic_unchecked_t fscache_n_relinquishes_null;
56209+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
56210+extern atomic_unchecked_t fscache_n_relinquishes_retire;
56211
56212-extern atomic_t fscache_n_cookie_index;
56213-extern atomic_t fscache_n_cookie_data;
56214-extern atomic_t fscache_n_cookie_special;
56215+extern atomic_unchecked_t fscache_n_cookie_index;
56216+extern atomic_unchecked_t fscache_n_cookie_data;
56217+extern atomic_unchecked_t fscache_n_cookie_special;
56218
56219-extern atomic_t fscache_n_object_alloc;
56220-extern atomic_t fscache_n_object_no_alloc;
56221-extern atomic_t fscache_n_object_lookups;
56222-extern atomic_t fscache_n_object_lookups_negative;
56223-extern atomic_t fscache_n_object_lookups_positive;
56224-extern atomic_t fscache_n_object_lookups_timed_out;
56225-extern atomic_t fscache_n_object_created;
56226-extern atomic_t fscache_n_object_avail;
56227-extern atomic_t fscache_n_object_dead;
56228+extern atomic_unchecked_t fscache_n_object_alloc;
56229+extern atomic_unchecked_t fscache_n_object_no_alloc;
56230+extern atomic_unchecked_t fscache_n_object_lookups;
56231+extern atomic_unchecked_t fscache_n_object_lookups_negative;
56232+extern atomic_unchecked_t fscache_n_object_lookups_positive;
56233+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
56234+extern atomic_unchecked_t fscache_n_object_created;
56235+extern atomic_unchecked_t fscache_n_object_avail;
56236+extern atomic_unchecked_t fscache_n_object_dead;
56237
56238-extern atomic_t fscache_n_checkaux_none;
56239-extern atomic_t fscache_n_checkaux_okay;
56240-extern atomic_t fscache_n_checkaux_update;
56241-extern atomic_t fscache_n_checkaux_obsolete;
56242+extern atomic_unchecked_t fscache_n_checkaux_none;
56243+extern atomic_unchecked_t fscache_n_checkaux_okay;
56244+extern atomic_unchecked_t fscache_n_checkaux_update;
56245+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
56246
56247 extern atomic_t fscache_n_cop_alloc_object;
56248 extern atomic_t fscache_n_cop_lookup_object;
56249@@ -266,6 +266,11 @@ static inline void fscache_stat(atomic_t *stat)
56250 atomic_inc(stat);
56251 }
56252
56253+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
56254+{
56255+ atomic_inc_unchecked(stat);
56256+}
56257+
56258 static inline void fscache_stat_d(atomic_t *stat)
56259 {
56260 atomic_dec(stat);
56261@@ -278,6 +283,7 @@ extern const struct file_operations fscache_stats_fops;
56262
56263 #define __fscache_stat(stat) (NULL)
56264 #define fscache_stat(stat) do {} while (0)
56265+#define fscache_stat_unchecked(stat) do {} while (0)
56266 #define fscache_stat_d(stat) do {} while (0)
56267 #endif
56268
56269diff --git a/fs/fscache/object.c b/fs/fscache/object.c
56270index 86d75a6..5f3d7a0 100644
56271--- a/fs/fscache/object.c
56272+++ b/fs/fscache/object.c
56273@@ -451,7 +451,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
56274 _debug("LOOKUP \"%s\" in \"%s\"",
56275 cookie->def->name, object->cache->tag->name);
56276
56277- fscache_stat(&fscache_n_object_lookups);
56278+ fscache_stat_unchecked(&fscache_n_object_lookups);
56279 fscache_stat(&fscache_n_cop_lookup_object);
56280 ret = object->cache->ops->lookup_object(object);
56281 fscache_stat_d(&fscache_n_cop_lookup_object);
56282@@ -461,7 +461,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
56283 if (ret == -ETIMEDOUT) {
56284 /* probably stuck behind another object, so move this one to
56285 * the back of the queue */
56286- fscache_stat(&fscache_n_object_lookups_timed_out);
56287+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
56288 _leave(" [timeout]");
56289 return NO_TRANSIT;
56290 }
56291@@ -489,7 +489,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
56292 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
56293
56294 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
56295- fscache_stat(&fscache_n_object_lookups_negative);
56296+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
56297
56298 /* Allow write requests to begin stacking up and read requests to begin
56299 * returning ENODATA.
56300@@ -523,7 +523,7 @@ void fscache_obtained_object(struct fscache_object *object)
56301 /* if we were still looking up, then we must have a positive lookup
56302 * result, in which case there may be data available */
56303 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
56304- fscache_stat(&fscache_n_object_lookups_positive);
56305+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
56306
56307 /* We do (presumably) have data */
56308 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
56309@@ -534,7 +534,7 @@ void fscache_obtained_object(struct fscache_object *object)
56310 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
56311 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
56312 } else {
56313- fscache_stat(&fscache_n_object_created);
56314+ fscache_stat_unchecked(&fscache_n_object_created);
56315 }
56316
56317 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
56318@@ -570,7 +570,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
56319 fscache_stat_d(&fscache_n_cop_lookup_complete);
56320
56321 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
56322- fscache_stat(&fscache_n_object_avail);
56323+ fscache_stat_unchecked(&fscache_n_object_avail);
56324
56325 _leave("");
56326 return transit_to(JUMPSTART_DEPS);
56327@@ -716,7 +716,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
56328
56329 /* this just shifts the object release to the work processor */
56330 fscache_put_object(object);
56331- fscache_stat(&fscache_n_object_dead);
56332+ fscache_stat_unchecked(&fscache_n_object_dead);
56333
56334 _leave("");
56335 return transit_to(OBJECT_DEAD);
56336@@ -881,7 +881,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
56337 enum fscache_checkaux result;
56338
56339 if (!object->cookie->def->check_aux) {
56340- fscache_stat(&fscache_n_checkaux_none);
56341+ fscache_stat_unchecked(&fscache_n_checkaux_none);
56342 return FSCACHE_CHECKAUX_OKAY;
56343 }
56344
56345@@ -890,17 +890,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
56346 switch (result) {
56347 /* entry okay as is */
56348 case FSCACHE_CHECKAUX_OKAY:
56349- fscache_stat(&fscache_n_checkaux_okay);
56350+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
56351 break;
56352
56353 /* entry requires update */
56354 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
56355- fscache_stat(&fscache_n_checkaux_update);
56356+ fscache_stat_unchecked(&fscache_n_checkaux_update);
56357 break;
56358
56359 /* entry requires deletion */
56360 case FSCACHE_CHECKAUX_OBSOLETE:
56361- fscache_stat(&fscache_n_checkaux_obsolete);
56362+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
56363 break;
56364
56365 default:
56366@@ -986,7 +986,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
56367 {
56368 const struct fscache_state *s;
56369
56370- fscache_stat(&fscache_n_invalidates_run);
56371+ fscache_stat_unchecked(&fscache_n_invalidates_run);
56372 fscache_stat(&fscache_n_cop_invalidate_object);
56373 s = _fscache_invalidate_object(object, event);
56374 fscache_stat_d(&fscache_n_cop_invalidate_object);
56375@@ -1001,7 +1001,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
56376 {
56377 _enter("{OBJ%x},%d", object->debug_id, event);
56378
56379- fscache_stat(&fscache_n_updates_run);
56380+ fscache_stat_unchecked(&fscache_n_updates_run);
56381 fscache_stat(&fscache_n_cop_update_object);
56382 object->cache->ops->update_object(object);
56383 fscache_stat_d(&fscache_n_cop_update_object);
56384diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
56385index 318071a..379938b 100644
56386--- a/fs/fscache/operation.c
56387+++ b/fs/fscache/operation.c
56388@@ -17,7 +17,7 @@
56389 #include <linux/slab.h>
56390 #include "internal.h"
56391
56392-atomic_t fscache_op_debug_id;
56393+atomic_unchecked_t fscache_op_debug_id;
56394 EXPORT_SYMBOL(fscache_op_debug_id);
56395
56396 /**
56397@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
56398 ASSERTCMP(atomic_read(&op->usage), >, 0);
56399 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
56400
56401- fscache_stat(&fscache_n_op_enqueue);
56402+ fscache_stat_unchecked(&fscache_n_op_enqueue);
56403 switch (op->flags & FSCACHE_OP_TYPE) {
56404 case FSCACHE_OP_ASYNC:
56405 _debug("queue async");
56406@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
56407 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
56408 if (op->processor)
56409 fscache_enqueue_operation(op);
56410- fscache_stat(&fscache_n_op_run);
56411+ fscache_stat_unchecked(&fscache_n_op_run);
56412 }
56413
56414 /*
56415@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
56416 if (object->n_in_progress > 0) {
56417 atomic_inc(&op->usage);
56418 list_add_tail(&op->pend_link, &object->pending_ops);
56419- fscache_stat(&fscache_n_op_pend);
56420+ fscache_stat_unchecked(&fscache_n_op_pend);
56421 } else if (!list_empty(&object->pending_ops)) {
56422 atomic_inc(&op->usage);
56423 list_add_tail(&op->pend_link, &object->pending_ops);
56424- fscache_stat(&fscache_n_op_pend);
56425+ fscache_stat_unchecked(&fscache_n_op_pend);
56426 fscache_start_operations(object);
56427 } else {
56428 ASSERTCMP(object->n_in_progress, ==, 0);
56429@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
56430 object->n_exclusive++; /* reads and writes must wait */
56431 atomic_inc(&op->usage);
56432 list_add_tail(&op->pend_link, &object->pending_ops);
56433- fscache_stat(&fscache_n_op_pend);
56434+ fscache_stat_unchecked(&fscache_n_op_pend);
56435 ret = 0;
56436 } else {
56437 /* If we're in any other state, there must have been an I/O
56438@@ -212,11 +212,11 @@ int fscache_submit_op(struct fscache_object *object,
56439 if (object->n_exclusive > 0) {
56440 atomic_inc(&op->usage);
56441 list_add_tail(&op->pend_link, &object->pending_ops);
56442- fscache_stat(&fscache_n_op_pend);
56443+ fscache_stat_unchecked(&fscache_n_op_pend);
56444 } else if (!list_empty(&object->pending_ops)) {
56445 atomic_inc(&op->usage);
56446 list_add_tail(&op->pend_link, &object->pending_ops);
56447- fscache_stat(&fscache_n_op_pend);
56448+ fscache_stat_unchecked(&fscache_n_op_pend);
56449 fscache_start_operations(object);
56450 } else {
56451 ASSERTCMP(object->n_exclusive, ==, 0);
56452@@ -228,10 +228,10 @@ int fscache_submit_op(struct fscache_object *object,
56453 object->n_ops++;
56454 atomic_inc(&op->usage);
56455 list_add_tail(&op->pend_link, &object->pending_ops);
56456- fscache_stat(&fscache_n_op_pend);
56457+ fscache_stat_unchecked(&fscache_n_op_pend);
56458 ret = 0;
56459 } else if (fscache_object_is_dying(object)) {
56460- fscache_stat(&fscache_n_op_rejected);
56461+ fscache_stat_unchecked(&fscache_n_op_rejected);
56462 op->state = FSCACHE_OP_ST_CANCELLED;
56463 ret = -ENOBUFS;
56464 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
56465@@ -310,7 +310,7 @@ int fscache_cancel_op(struct fscache_operation *op,
56466 ret = -EBUSY;
56467 if (op->state == FSCACHE_OP_ST_PENDING) {
56468 ASSERT(!list_empty(&op->pend_link));
56469- fscache_stat(&fscache_n_op_cancelled);
56470+ fscache_stat_unchecked(&fscache_n_op_cancelled);
56471 list_del_init(&op->pend_link);
56472 if (do_cancel)
56473 do_cancel(op);
56474@@ -342,7 +342,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
56475 while (!list_empty(&object->pending_ops)) {
56476 op = list_entry(object->pending_ops.next,
56477 struct fscache_operation, pend_link);
56478- fscache_stat(&fscache_n_op_cancelled);
56479+ fscache_stat_unchecked(&fscache_n_op_cancelled);
56480 list_del_init(&op->pend_link);
56481
56482 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
56483@@ -414,7 +414,7 @@ void fscache_put_operation(struct fscache_operation *op)
56484 op->state, ==, FSCACHE_OP_ST_CANCELLED);
56485 op->state = FSCACHE_OP_ST_DEAD;
56486
56487- fscache_stat(&fscache_n_op_release);
56488+ fscache_stat_unchecked(&fscache_n_op_release);
56489
56490 if (op->release) {
56491 op->release(op);
56492@@ -433,7 +433,7 @@ void fscache_put_operation(struct fscache_operation *op)
56493 * lock, and defer it otherwise */
56494 if (!spin_trylock(&object->lock)) {
56495 _debug("defer put");
56496- fscache_stat(&fscache_n_op_deferred_release);
56497+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
56498
56499 cache = object->cache;
56500 spin_lock(&cache->op_gc_list_lock);
56501@@ -486,7 +486,7 @@ void fscache_operation_gc(struct work_struct *work)
56502
56503 _debug("GC DEFERRED REL OBJ%x OP%x",
56504 object->debug_id, op->debug_id);
56505- fscache_stat(&fscache_n_op_gc);
56506+ fscache_stat_unchecked(&fscache_n_op_gc);
56507
56508 ASSERTCMP(atomic_read(&op->usage), ==, 0);
56509 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
56510diff --git a/fs/fscache/page.c b/fs/fscache/page.c
56511index d479ab3..727a7f2 100644
56512--- a/fs/fscache/page.c
56513+++ b/fs/fscache/page.c
56514@@ -61,7 +61,7 @@ try_again:
56515 val = radix_tree_lookup(&cookie->stores, page->index);
56516 if (!val) {
56517 rcu_read_unlock();
56518- fscache_stat(&fscache_n_store_vmscan_not_storing);
56519+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
56520 __fscache_uncache_page(cookie, page);
56521 return true;
56522 }
56523@@ -91,11 +91,11 @@ try_again:
56524 spin_unlock(&cookie->stores_lock);
56525
56526 if (xpage) {
56527- fscache_stat(&fscache_n_store_vmscan_cancelled);
56528- fscache_stat(&fscache_n_store_radix_deletes);
56529+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
56530+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
56531 ASSERTCMP(xpage, ==, page);
56532 } else {
56533- fscache_stat(&fscache_n_store_vmscan_gone);
56534+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
56535 }
56536
56537 wake_up_bit(&cookie->flags, 0);
56538@@ -110,11 +110,11 @@ page_busy:
56539 * sleeping on memory allocation, so we may need to impose a timeout
56540 * too. */
56541 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
56542- fscache_stat(&fscache_n_store_vmscan_busy);
56543+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
56544 return false;
56545 }
56546
56547- fscache_stat(&fscache_n_store_vmscan_wait);
56548+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
56549 __fscache_wait_on_page_write(cookie, page);
56550 gfp &= ~__GFP_WAIT;
56551 goto try_again;
56552@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
56553 FSCACHE_COOKIE_STORING_TAG);
56554 if (!radix_tree_tag_get(&cookie->stores, page->index,
56555 FSCACHE_COOKIE_PENDING_TAG)) {
56556- fscache_stat(&fscache_n_store_radix_deletes);
56557+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
56558 xpage = radix_tree_delete(&cookie->stores, page->index);
56559 }
56560 spin_unlock(&cookie->stores_lock);
56561@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
56562
56563 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
56564
56565- fscache_stat(&fscache_n_attr_changed_calls);
56566+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
56567
56568 if (fscache_object_is_active(object) &&
56569 fscache_use_cookie(object)) {
56570@@ -189,11 +189,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
56571
56572 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
56573
56574- fscache_stat(&fscache_n_attr_changed);
56575+ fscache_stat_unchecked(&fscache_n_attr_changed);
56576
56577 op = kzalloc(sizeof(*op), GFP_KERNEL);
56578 if (!op) {
56579- fscache_stat(&fscache_n_attr_changed_nomem);
56580+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
56581 _leave(" = -ENOMEM");
56582 return -ENOMEM;
56583 }
56584@@ -211,7 +211,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
56585 if (fscache_submit_exclusive_op(object, op) < 0)
56586 goto nobufs;
56587 spin_unlock(&cookie->lock);
56588- fscache_stat(&fscache_n_attr_changed_ok);
56589+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
56590 fscache_put_operation(op);
56591 _leave(" = 0");
56592 return 0;
56593@@ -219,7 +219,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
56594 nobufs:
56595 spin_unlock(&cookie->lock);
56596 kfree(op);
56597- fscache_stat(&fscache_n_attr_changed_nobufs);
56598+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
56599 _leave(" = %d", -ENOBUFS);
56600 return -ENOBUFS;
56601 }
56602@@ -258,7 +258,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
56603 /* allocate a retrieval operation and attempt to submit it */
56604 op = kzalloc(sizeof(*op), GFP_NOIO);
56605 if (!op) {
56606- fscache_stat(&fscache_n_retrievals_nomem);
56607+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
56608 return NULL;
56609 }
56610
56611@@ -289,13 +289,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
56612 return 0;
56613 }
56614
56615- fscache_stat(&fscache_n_retrievals_wait);
56616+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
56617
56618 jif = jiffies;
56619 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
56620 fscache_wait_bit_interruptible,
56621 TASK_INTERRUPTIBLE) != 0) {
56622- fscache_stat(&fscache_n_retrievals_intr);
56623+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
56624 _leave(" = -ERESTARTSYS");
56625 return -ERESTARTSYS;
56626 }
56627@@ -324,8 +324,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
56628 */
56629 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
56630 struct fscache_retrieval *op,
56631- atomic_t *stat_op_waits,
56632- atomic_t *stat_object_dead)
56633+ atomic_unchecked_t *stat_op_waits,
56634+ atomic_unchecked_t *stat_object_dead)
56635 {
56636 int ret;
56637
56638@@ -333,7 +333,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
56639 goto check_if_dead;
56640
56641 _debug(">>> WT");
56642- fscache_stat(stat_op_waits);
56643+ fscache_stat_unchecked(stat_op_waits);
56644 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
56645 fscache_wait_bit_interruptible,
56646 TASK_INTERRUPTIBLE) != 0) {
56647@@ -350,14 +350,14 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
56648
56649 check_if_dead:
56650 if (op->op.state == FSCACHE_OP_ST_CANCELLED) {
56651- fscache_stat(stat_object_dead);
56652+ fscache_stat_unchecked(stat_object_dead);
56653 _leave(" = -ENOBUFS [cancelled]");
56654 return -ENOBUFS;
56655 }
56656 if (unlikely(fscache_object_is_dead(object))) {
56657 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->op.state);
56658 fscache_cancel_op(&op->op, fscache_do_cancel_retrieval);
56659- fscache_stat(stat_object_dead);
56660+ fscache_stat_unchecked(stat_object_dead);
56661 return -ENOBUFS;
56662 }
56663 return 0;
56664@@ -384,7 +384,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
56665
56666 _enter("%p,%p,,,", cookie, page);
56667
56668- fscache_stat(&fscache_n_retrievals);
56669+ fscache_stat_unchecked(&fscache_n_retrievals);
56670
56671 if (hlist_empty(&cookie->backing_objects))
56672 goto nobufs;
56673@@ -424,7 +424,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
56674 goto nobufs_unlock_dec;
56675 spin_unlock(&cookie->lock);
56676
56677- fscache_stat(&fscache_n_retrieval_ops);
56678+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
56679
56680 /* pin the netfs read context in case we need to do the actual netfs
56681 * read because we've encountered a cache read failure */
56682@@ -454,15 +454,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
56683
56684 error:
56685 if (ret == -ENOMEM)
56686- fscache_stat(&fscache_n_retrievals_nomem);
56687+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
56688 else if (ret == -ERESTARTSYS)
56689- fscache_stat(&fscache_n_retrievals_intr);
56690+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
56691 else if (ret == -ENODATA)
56692- fscache_stat(&fscache_n_retrievals_nodata);
56693+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
56694 else if (ret < 0)
56695- fscache_stat(&fscache_n_retrievals_nobufs);
56696+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
56697 else
56698- fscache_stat(&fscache_n_retrievals_ok);
56699+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
56700
56701 fscache_put_retrieval(op);
56702 _leave(" = %d", ret);
56703@@ -475,7 +475,7 @@ nobufs_unlock:
56704 atomic_dec(&cookie->n_active);
56705 kfree(op);
56706 nobufs:
56707- fscache_stat(&fscache_n_retrievals_nobufs);
56708+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
56709 _leave(" = -ENOBUFS");
56710 return -ENOBUFS;
56711 }
56712@@ -513,7 +513,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
56713
56714 _enter("%p,,%d,,,", cookie, *nr_pages);
56715
56716- fscache_stat(&fscache_n_retrievals);
56717+ fscache_stat_unchecked(&fscache_n_retrievals);
56718
56719 if (hlist_empty(&cookie->backing_objects))
56720 goto nobufs;
56721@@ -549,7 +549,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
56722 goto nobufs_unlock_dec;
56723 spin_unlock(&cookie->lock);
56724
56725- fscache_stat(&fscache_n_retrieval_ops);
56726+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
56727
56728 /* pin the netfs read context in case we need to do the actual netfs
56729 * read because we've encountered a cache read failure */
56730@@ -579,15 +579,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
56731
56732 error:
56733 if (ret == -ENOMEM)
56734- fscache_stat(&fscache_n_retrievals_nomem);
56735+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
56736 else if (ret == -ERESTARTSYS)
56737- fscache_stat(&fscache_n_retrievals_intr);
56738+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
56739 else if (ret == -ENODATA)
56740- fscache_stat(&fscache_n_retrievals_nodata);
56741+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
56742 else if (ret < 0)
56743- fscache_stat(&fscache_n_retrievals_nobufs);
56744+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
56745 else
56746- fscache_stat(&fscache_n_retrievals_ok);
56747+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
56748
56749 fscache_put_retrieval(op);
56750 _leave(" = %d", ret);
56751@@ -600,7 +600,7 @@ nobufs_unlock:
56752 atomic_dec(&cookie->n_active);
56753 kfree(op);
56754 nobufs:
56755- fscache_stat(&fscache_n_retrievals_nobufs);
56756+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
56757 _leave(" = -ENOBUFS");
56758 return -ENOBUFS;
56759 }
56760@@ -624,7 +624,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
56761
56762 _enter("%p,%p,,,", cookie, page);
56763
56764- fscache_stat(&fscache_n_allocs);
56765+ fscache_stat_unchecked(&fscache_n_allocs);
56766
56767 if (hlist_empty(&cookie->backing_objects))
56768 goto nobufs;
56769@@ -656,7 +656,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
56770 goto nobufs_unlock;
56771 spin_unlock(&cookie->lock);
56772
56773- fscache_stat(&fscache_n_alloc_ops);
56774+ fscache_stat_unchecked(&fscache_n_alloc_ops);
56775
56776 ret = fscache_wait_for_retrieval_activation(
56777 object, op,
56778@@ -672,11 +672,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
56779
56780 error:
56781 if (ret == -ERESTARTSYS)
56782- fscache_stat(&fscache_n_allocs_intr);
56783+ fscache_stat_unchecked(&fscache_n_allocs_intr);
56784 else if (ret < 0)
56785- fscache_stat(&fscache_n_allocs_nobufs);
56786+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
56787 else
56788- fscache_stat(&fscache_n_allocs_ok);
56789+ fscache_stat_unchecked(&fscache_n_allocs_ok);
56790
56791 fscache_put_retrieval(op);
56792 _leave(" = %d", ret);
56793@@ -687,7 +687,7 @@ nobufs_unlock:
56794 atomic_dec(&cookie->n_active);
56795 kfree(op);
56796 nobufs:
56797- fscache_stat(&fscache_n_allocs_nobufs);
56798+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
56799 _leave(" = -ENOBUFS");
56800 return -ENOBUFS;
56801 }
56802@@ -747,7 +747,7 @@ static void fscache_write_op(struct fscache_operation *_op)
56803
56804 spin_lock(&cookie->stores_lock);
56805
56806- fscache_stat(&fscache_n_store_calls);
56807+ fscache_stat_unchecked(&fscache_n_store_calls);
56808
56809 /* find a page to store */
56810 page = NULL;
56811@@ -758,7 +758,7 @@ static void fscache_write_op(struct fscache_operation *_op)
56812 page = results[0];
56813 _debug("gang %d [%lx]", n, page->index);
56814 if (page->index > op->store_limit) {
56815- fscache_stat(&fscache_n_store_pages_over_limit);
56816+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
56817 goto superseded;
56818 }
56819
56820@@ -770,7 +770,7 @@ static void fscache_write_op(struct fscache_operation *_op)
56821 spin_unlock(&cookie->stores_lock);
56822 spin_unlock(&object->lock);
56823
56824- fscache_stat(&fscache_n_store_pages);
56825+ fscache_stat_unchecked(&fscache_n_store_pages);
56826 fscache_stat(&fscache_n_cop_write_page);
56827 ret = object->cache->ops->write_page(op, page);
56828 fscache_stat_d(&fscache_n_cop_write_page);
56829@@ -873,7 +873,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
56830 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
56831 ASSERT(PageFsCache(page));
56832
56833- fscache_stat(&fscache_n_stores);
56834+ fscache_stat_unchecked(&fscache_n_stores);
56835
56836 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
56837 _leave(" = -ENOBUFS [invalidating]");
56838@@ -931,7 +931,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
56839 spin_unlock(&cookie->stores_lock);
56840 spin_unlock(&object->lock);
56841
56842- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
56843+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
56844 op->store_limit = object->store_limit;
56845
56846 atomic_inc(&cookie->n_active);
56847@@ -940,8 +940,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
56848
56849 spin_unlock(&cookie->lock);
56850 radix_tree_preload_end();
56851- fscache_stat(&fscache_n_store_ops);
56852- fscache_stat(&fscache_n_stores_ok);
56853+ fscache_stat_unchecked(&fscache_n_store_ops);
56854+ fscache_stat_unchecked(&fscache_n_stores_ok);
56855
56856 /* the work queue now carries its own ref on the object */
56857 fscache_put_operation(&op->op);
56858@@ -949,14 +949,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
56859 return 0;
56860
56861 already_queued:
56862- fscache_stat(&fscache_n_stores_again);
56863+ fscache_stat_unchecked(&fscache_n_stores_again);
56864 already_pending:
56865 spin_unlock(&cookie->stores_lock);
56866 spin_unlock(&object->lock);
56867 spin_unlock(&cookie->lock);
56868 radix_tree_preload_end();
56869 kfree(op);
56870- fscache_stat(&fscache_n_stores_ok);
56871+ fscache_stat_unchecked(&fscache_n_stores_ok);
56872 _leave(" = 0");
56873 return 0;
56874
56875@@ -976,14 +976,14 @@ nobufs:
56876 spin_unlock(&cookie->lock);
56877 radix_tree_preload_end();
56878 kfree(op);
56879- fscache_stat(&fscache_n_stores_nobufs);
56880+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
56881 _leave(" = -ENOBUFS");
56882 return -ENOBUFS;
56883
56884 nomem_free:
56885 kfree(op);
56886 nomem:
56887- fscache_stat(&fscache_n_stores_oom);
56888+ fscache_stat_unchecked(&fscache_n_stores_oom);
56889 _leave(" = -ENOMEM");
56890 return -ENOMEM;
56891 }
56892@@ -1001,7 +1001,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
56893 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
56894 ASSERTCMP(page, !=, NULL);
56895
56896- fscache_stat(&fscache_n_uncaches);
56897+ fscache_stat_unchecked(&fscache_n_uncaches);
56898
56899 /* cache withdrawal may beat us to it */
56900 if (!PageFsCache(page))
56901@@ -1052,7 +1052,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
56902 struct fscache_cookie *cookie = op->op.object->cookie;
56903
56904 #ifdef CONFIG_FSCACHE_STATS
56905- atomic_inc(&fscache_n_marks);
56906+ atomic_inc_unchecked(&fscache_n_marks);
56907 #endif
56908
56909 _debug("- mark %p{%lx}", page, page->index);
56910diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
56911index 40d13c7..ddf52b9 100644
56912--- a/fs/fscache/stats.c
56913+++ b/fs/fscache/stats.c
56914@@ -18,99 +18,99 @@
56915 /*
56916 * operation counters
56917 */
56918-atomic_t fscache_n_op_pend;
56919-atomic_t fscache_n_op_run;
56920-atomic_t fscache_n_op_enqueue;
56921-atomic_t fscache_n_op_requeue;
56922-atomic_t fscache_n_op_deferred_release;
56923-atomic_t fscache_n_op_release;
56924-atomic_t fscache_n_op_gc;
56925-atomic_t fscache_n_op_cancelled;
56926-atomic_t fscache_n_op_rejected;
56927+atomic_unchecked_t fscache_n_op_pend;
56928+atomic_unchecked_t fscache_n_op_run;
56929+atomic_unchecked_t fscache_n_op_enqueue;
56930+atomic_unchecked_t fscache_n_op_requeue;
56931+atomic_unchecked_t fscache_n_op_deferred_release;
56932+atomic_unchecked_t fscache_n_op_release;
56933+atomic_unchecked_t fscache_n_op_gc;
56934+atomic_unchecked_t fscache_n_op_cancelled;
56935+atomic_unchecked_t fscache_n_op_rejected;
56936
56937-atomic_t fscache_n_attr_changed;
56938-atomic_t fscache_n_attr_changed_ok;
56939-atomic_t fscache_n_attr_changed_nobufs;
56940-atomic_t fscache_n_attr_changed_nomem;
56941-atomic_t fscache_n_attr_changed_calls;
56942+atomic_unchecked_t fscache_n_attr_changed;
56943+atomic_unchecked_t fscache_n_attr_changed_ok;
56944+atomic_unchecked_t fscache_n_attr_changed_nobufs;
56945+atomic_unchecked_t fscache_n_attr_changed_nomem;
56946+atomic_unchecked_t fscache_n_attr_changed_calls;
56947
56948-atomic_t fscache_n_allocs;
56949-atomic_t fscache_n_allocs_ok;
56950-atomic_t fscache_n_allocs_wait;
56951-atomic_t fscache_n_allocs_nobufs;
56952-atomic_t fscache_n_allocs_intr;
56953-atomic_t fscache_n_allocs_object_dead;
56954-atomic_t fscache_n_alloc_ops;
56955-atomic_t fscache_n_alloc_op_waits;
56956+atomic_unchecked_t fscache_n_allocs;
56957+atomic_unchecked_t fscache_n_allocs_ok;
56958+atomic_unchecked_t fscache_n_allocs_wait;
56959+atomic_unchecked_t fscache_n_allocs_nobufs;
56960+atomic_unchecked_t fscache_n_allocs_intr;
56961+atomic_unchecked_t fscache_n_allocs_object_dead;
56962+atomic_unchecked_t fscache_n_alloc_ops;
56963+atomic_unchecked_t fscache_n_alloc_op_waits;
56964
56965-atomic_t fscache_n_retrievals;
56966-atomic_t fscache_n_retrievals_ok;
56967-atomic_t fscache_n_retrievals_wait;
56968-atomic_t fscache_n_retrievals_nodata;
56969-atomic_t fscache_n_retrievals_nobufs;
56970-atomic_t fscache_n_retrievals_intr;
56971-atomic_t fscache_n_retrievals_nomem;
56972-atomic_t fscache_n_retrievals_object_dead;
56973-atomic_t fscache_n_retrieval_ops;
56974-atomic_t fscache_n_retrieval_op_waits;
56975+atomic_unchecked_t fscache_n_retrievals;
56976+atomic_unchecked_t fscache_n_retrievals_ok;
56977+atomic_unchecked_t fscache_n_retrievals_wait;
56978+atomic_unchecked_t fscache_n_retrievals_nodata;
56979+atomic_unchecked_t fscache_n_retrievals_nobufs;
56980+atomic_unchecked_t fscache_n_retrievals_intr;
56981+atomic_unchecked_t fscache_n_retrievals_nomem;
56982+atomic_unchecked_t fscache_n_retrievals_object_dead;
56983+atomic_unchecked_t fscache_n_retrieval_ops;
56984+atomic_unchecked_t fscache_n_retrieval_op_waits;
56985
56986-atomic_t fscache_n_stores;
56987-atomic_t fscache_n_stores_ok;
56988-atomic_t fscache_n_stores_again;
56989-atomic_t fscache_n_stores_nobufs;
56990-atomic_t fscache_n_stores_oom;
56991-atomic_t fscache_n_store_ops;
56992-atomic_t fscache_n_store_calls;
56993-atomic_t fscache_n_store_pages;
56994-atomic_t fscache_n_store_radix_deletes;
56995-atomic_t fscache_n_store_pages_over_limit;
56996+atomic_unchecked_t fscache_n_stores;
56997+atomic_unchecked_t fscache_n_stores_ok;
56998+atomic_unchecked_t fscache_n_stores_again;
56999+atomic_unchecked_t fscache_n_stores_nobufs;
57000+atomic_unchecked_t fscache_n_stores_oom;
57001+atomic_unchecked_t fscache_n_store_ops;
57002+atomic_unchecked_t fscache_n_store_calls;
57003+atomic_unchecked_t fscache_n_store_pages;
57004+atomic_unchecked_t fscache_n_store_radix_deletes;
57005+atomic_unchecked_t fscache_n_store_pages_over_limit;
57006
57007-atomic_t fscache_n_store_vmscan_not_storing;
57008-atomic_t fscache_n_store_vmscan_gone;
57009-atomic_t fscache_n_store_vmscan_busy;
57010-atomic_t fscache_n_store_vmscan_cancelled;
57011-atomic_t fscache_n_store_vmscan_wait;
57012+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
57013+atomic_unchecked_t fscache_n_store_vmscan_gone;
57014+atomic_unchecked_t fscache_n_store_vmscan_busy;
57015+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
57016+atomic_unchecked_t fscache_n_store_vmscan_wait;
57017
57018-atomic_t fscache_n_marks;
57019-atomic_t fscache_n_uncaches;
57020+atomic_unchecked_t fscache_n_marks;
57021+atomic_unchecked_t fscache_n_uncaches;
57022
57023-atomic_t fscache_n_acquires;
57024-atomic_t fscache_n_acquires_null;
57025-atomic_t fscache_n_acquires_no_cache;
57026-atomic_t fscache_n_acquires_ok;
57027-atomic_t fscache_n_acquires_nobufs;
57028-atomic_t fscache_n_acquires_oom;
57029+atomic_unchecked_t fscache_n_acquires;
57030+atomic_unchecked_t fscache_n_acquires_null;
57031+atomic_unchecked_t fscache_n_acquires_no_cache;
57032+atomic_unchecked_t fscache_n_acquires_ok;
57033+atomic_unchecked_t fscache_n_acquires_nobufs;
57034+atomic_unchecked_t fscache_n_acquires_oom;
57035
57036-atomic_t fscache_n_invalidates;
57037-atomic_t fscache_n_invalidates_run;
57038+atomic_unchecked_t fscache_n_invalidates;
57039+atomic_unchecked_t fscache_n_invalidates_run;
57040
57041-atomic_t fscache_n_updates;
57042-atomic_t fscache_n_updates_null;
57043-atomic_t fscache_n_updates_run;
57044+atomic_unchecked_t fscache_n_updates;
57045+atomic_unchecked_t fscache_n_updates_null;
57046+atomic_unchecked_t fscache_n_updates_run;
57047
57048-atomic_t fscache_n_relinquishes;
57049-atomic_t fscache_n_relinquishes_null;
57050-atomic_t fscache_n_relinquishes_waitcrt;
57051-atomic_t fscache_n_relinquishes_retire;
57052+atomic_unchecked_t fscache_n_relinquishes;
57053+atomic_unchecked_t fscache_n_relinquishes_null;
57054+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
57055+atomic_unchecked_t fscache_n_relinquishes_retire;
57056
57057-atomic_t fscache_n_cookie_index;
57058-atomic_t fscache_n_cookie_data;
57059-atomic_t fscache_n_cookie_special;
57060+atomic_unchecked_t fscache_n_cookie_index;
57061+atomic_unchecked_t fscache_n_cookie_data;
57062+atomic_unchecked_t fscache_n_cookie_special;
57063
57064-atomic_t fscache_n_object_alloc;
57065-atomic_t fscache_n_object_no_alloc;
57066-atomic_t fscache_n_object_lookups;
57067-atomic_t fscache_n_object_lookups_negative;
57068-atomic_t fscache_n_object_lookups_positive;
57069-atomic_t fscache_n_object_lookups_timed_out;
57070-atomic_t fscache_n_object_created;
57071-atomic_t fscache_n_object_avail;
57072-atomic_t fscache_n_object_dead;
57073+atomic_unchecked_t fscache_n_object_alloc;
57074+atomic_unchecked_t fscache_n_object_no_alloc;
57075+atomic_unchecked_t fscache_n_object_lookups;
57076+atomic_unchecked_t fscache_n_object_lookups_negative;
57077+atomic_unchecked_t fscache_n_object_lookups_positive;
57078+atomic_unchecked_t fscache_n_object_lookups_timed_out;
57079+atomic_unchecked_t fscache_n_object_created;
57080+atomic_unchecked_t fscache_n_object_avail;
57081+atomic_unchecked_t fscache_n_object_dead;
57082
57083-atomic_t fscache_n_checkaux_none;
57084-atomic_t fscache_n_checkaux_okay;
57085-atomic_t fscache_n_checkaux_update;
57086-atomic_t fscache_n_checkaux_obsolete;
57087+atomic_unchecked_t fscache_n_checkaux_none;
57088+atomic_unchecked_t fscache_n_checkaux_okay;
57089+atomic_unchecked_t fscache_n_checkaux_update;
57090+atomic_unchecked_t fscache_n_checkaux_obsolete;
57091
57092 atomic_t fscache_n_cop_alloc_object;
57093 atomic_t fscache_n_cop_lookup_object;
57094@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
57095 seq_puts(m, "FS-Cache statistics\n");
57096
57097 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
57098- atomic_read(&fscache_n_cookie_index),
57099- atomic_read(&fscache_n_cookie_data),
57100- atomic_read(&fscache_n_cookie_special));
57101+ atomic_read_unchecked(&fscache_n_cookie_index),
57102+ atomic_read_unchecked(&fscache_n_cookie_data),
57103+ atomic_read_unchecked(&fscache_n_cookie_special));
57104
57105 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
57106- atomic_read(&fscache_n_object_alloc),
57107- atomic_read(&fscache_n_object_no_alloc),
57108- atomic_read(&fscache_n_object_avail),
57109- atomic_read(&fscache_n_object_dead));
57110+ atomic_read_unchecked(&fscache_n_object_alloc),
57111+ atomic_read_unchecked(&fscache_n_object_no_alloc),
57112+ atomic_read_unchecked(&fscache_n_object_avail),
57113+ atomic_read_unchecked(&fscache_n_object_dead));
57114 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
57115- atomic_read(&fscache_n_checkaux_none),
57116- atomic_read(&fscache_n_checkaux_okay),
57117- atomic_read(&fscache_n_checkaux_update),
57118- atomic_read(&fscache_n_checkaux_obsolete));
57119+ atomic_read_unchecked(&fscache_n_checkaux_none),
57120+ atomic_read_unchecked(&fscache_n_checkaux_okay),
57121+ atomic_read_unchecked(&fscache_n_checkaux_update),
57122+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
57123
57124 seq_printf(m, "Pages : mrk=%u unc=%u\n",
57125- atomic_read(&fscache_n_marks),
57126- atomic_read(&fscache_n_uncaches));
57127+ atomic_read_unchecked(&fscache_n_marks),
57128+ atomic_read_unchecked(&fscache_n_uncaches));
57129
57130 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
57131 " oom=%u\n",
57132- atomic_read(&fscache_n_acquires),
57133- atomic_read(&fscache_n_acquires_null),
57134- atomic_read(&fscache_n_acquires_no_cache),
57135- atomic_read(&fscache_n_acquires_ok),
57136- atomic_read(&fscache_n_acquires_nobufs),
57137- atomic_read(&fscache_n_acquires_oom));
57138+ atomic_read_unchecked(&fscache_n_acquires),
57139+ atomic_read_unchecked(&fscache_n_acquires_null),
57140+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
57141+ atomic_read_unchecked(&fscache_n_acquires_ok),
57142+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
57143+ atomic_read_unchecked(&fscache_n_acquires_oom));
57144
57145 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
57146- atomic_read(&fscache_n_object_lookups),
57147- atomic_read(&fscache_n_object_lookups_negative),
57148- atomic_read(&fscache_n_object_lookups_positive),
57149- atomic_read(&fscache_n_object_created),
57150- atomic_read(&fscache_n_object_lookups_timed_out));
57151+ atomic_read_unchecked(&fscache_n_object_lookups),
57152+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
57153+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
57154+ atomic_read_unchecked(&fscache_n_object_created),
57155+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
57156
57157 seq_printf(m, "Invals : n=%u run=%u\n",
57158- atomic_read(&fscache_n_invalidates),
57159- atomic_read(&fscache_n_invalidates_run));
57160+ atomic_read_unchecked(&fscache_n_invalidates),
57161+ atomic_read_unchecked(&fscache_n_invalidates_run));
57162
57163 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
57164- atomic_read(&fscache_n_updates),
57165- atomic_read(&fscache_n_updates_null),
57166- atomic_read(&fscache_n_updates_run));
57167+ atomic_read_unchecked(&fscache_n_updates),
57168+ atomic_read_unchecked(&fscache_n_updates_null),
57169+ atomic_read_unchecked(&fscache_n_updates_run));
57170
57171 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
57172- atomic_read(&fscache_n_relinquishes),
57173- atomic_read(&fscache_n_relinquishes_null),
57174- atomic_read(&fscache_n_relinquishes_waitcrt),
57175- atomic_read(&fscache_n_relinquishes_retire));
57176+ atomic_read_unchecked(&fscache_n_relinquishes),
57177+ atomic_read_unchecked(&fscache_n_relinquishes_null),
57178+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
57179+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
57180
57181 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
57182- atomic_read(&fscache_n_attr_changed),
57183- atomic_read(&fscache_n_attr_changed_ok),
57184- atomic_read(&fscache_n_attr_changed_nobufs),
57185- atomic_read(&fscache_n_attr_changed_nomem),
57186- atomic_read(&fscache_n_attr_changed_calls));
57187+ atomic_read_unchecked(&fscache_n_attr_changed),
57188+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
57189+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
57190+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
57191+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
57192
57193 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
57194- atomic_read(&fscache_n_allocs),
57195- atomic_read(&fscache_n_allocs_ok),
57196- atomic_read(&fscache_n_allocs_wait),
57197- atomic_read(&fscache_n_allocs_nobufs),
57198- atomic_read(&fscache_n_allocs_intr));
57199+ atomic_read_unchecked(&fscache_n_allocs),
57200+ atomic_read_unchecked(&fscache_n_allocs_ok),
57201+ atomic_read_unchecked(&fscache_n_allocs_wait),
57202+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
57203+ atomic_read_unchecked(&fscache_n_allocs_intr));
57204 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
57205- atomic_read(&fscache_n_alloc_ops),
57206- atomic_read(&fscache_n_alloc_op_waits),
57207- atomic_read(&fscache_n_allocs_object_dead));
57208+ atomic_read_unchecked(&fscache_n_alloc_ops),
57209+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
57210+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
57211
57212 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
57213 " int=%u oom=%u\n",
57214- atomic_read(&fscache_n_retrievals),
57215- atomic_read(&fscache_n_retrievals_ok),
57216- atomic_read(&fscache_n_retrievals_wait),
57217- atomic_read(&fscache_n_retrievals_nodata),
57218- atomic_read(&fscache_n_retrievals_nobufs),
57219- atomic_read(&fscache_n_retrievals_intr),
57220- atomic_read(&fscache_n_retrievals_nomem));
57221+ atomic_read_unchecked(&fscache_n_retrievals),
57222+ atomic_read_unchecked(&fscache_n_retrievals_ok),
57223+ atomic_read_unchecked(&fscache_n_retrievals_wait),
57224+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
57225+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
57226+ atomic_read_unchecked(&fscache_n_retrievals_intr),
57227+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
57228 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
57229- atomic_read(&fscache_n_retrieval_ops),
57230- atomic_read(&fscache_n_retrieval_op_waits),
57231- atomic_read(&fscache_n_retrievals_object_dead));
57232+ atomic_read_unchecked(&fscache_n_retrieval_ops),
57233+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
57234+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
57235
57236 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
57237- atomic_read(&fscache_n_stores),
57238- atomic_read(&fscache_n_stores_ok),
57239- atomic_read(&fscache_n_stores_again),
57240- atomic_read(&fscache_n_stores_nobufs),
57241- atomic_read(&fscache_n_stores_oom));
57242+ atomic_read_unchecked(&fscache_n_stores),
57243+ atomic_read_unchecked(&fscache_n_stores_ok),
57244+ atomic_read_unchecked(&fscache_n_stores_again),
57245+ atomic_read_unchecked(&fscache_n_stores_nobufs),
57246+ atomic_read_unchecked(&fscache_n_stores_oom));
57247 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
57248- atomic_read(&fscache_n_store_ops),
57249- atomic_read(&fscache_n_store_calls),
57250- atomic_read(&fscache_n_store_pages),
57251- atomic_read(&fscache_n_store_radix_deletes),
57252- atomic_read(&fscache_n_store_pages_over_limit));
57253+ atomic_read_unchecked(&fscache_n_store_ops),
57254+ atomic_read_unchecked(&fscache_n_store_calls),
57255+ atomic_read_unchecked(&fscache_n_store_pages),
57256+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
57257+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
57258
57259 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
57260- atomic_read(&fscache_n_store_vmscan_not_storing),
57261- atomic_read(&fscache_n_store_vmscan_gone),
57262- atomic_read(&fscache_n_store_vmscan_busy),
57263- atomic_read(&fscache_n_store_vmscan_cancelled),
57264- atomic_read(&fscache_n_store_vmscan_wait));
57265+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
57266+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
57267+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
57268+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
57269+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
57270
57271 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
57272- atomic_read(&fscache_n_op_pend),
57273- atomic_read(&fscache_n_op_run),
57274- atomic_read(&fscache_n_op_enqueue),
57275- atomic_read(&fscache_n_op_cancelled),
57276- atomic_read(&fscache_n_op_rejected));
57277+ atomic_read_unchecked(&fscache_n_op_pend),
57278+ atomic_read_unchecked(&fscache_n_op_run),
57279+ atomic_read_unchecked(&fscache_n_op_enqueue),
57280+ atomic_read_unchecked(&fscache_n_op_cancelled),
57281+ atomic_read_unchecked(&fscache_n_op_rejected));
57282 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
57283- atomic_read(&fscache_n_op_deferred_release),
57284- atomic_read(&fscache_n_op_release),
57285- atomic_read(&fscache_n_op_gc));
57286+ atomic_read_unchecked(&fscache_n_op_deferred_release),
57287+ atomic_read_unchecked(&fscache_n_op_release),
57288+ atomic_read_unchecked(&fscache_n_op_gc));
57289
57290 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
57291 atomic_read(&fscache_n_cop_alloc_object),
57292diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
57293index aef34b1..59bfd7b 100644
57294--- a/fs/fuse/cuse.c
57295+++ b/fs/fuse/cuse.c
57296@@ -600,10 +600,12 @@ static int __init cuse_init(void)
57297 INIT_LIST_HEAD(&cuse_conntbl[i]);
57298
57299 /* inherit and extend fuse_dev_operations */
57300- cuse_channel_fops = fuse_dev_operations;
57301- cuse_channel_fops.owner = THIS_MODULE;
57302- cuse_channel_fops.open = cuse_channel_open;
57303- cuse_channel_fops.release = cuse_channel_release;
57304+ pax_open_kernel();
57305+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
57306+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
57307+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
57308+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
57309+ pax_close_kernel();
57310
57311 cuse_class = class_create(THIS_MODULE, "cuse");
57312 if (IS_ERR(cuse_class))
57313diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
57314index 1d55f94..088da65 100644
57315--- a/fs/fuse/dev.c
57316+++ b/fs/fuse/dev.c
57317@@ -1339,7 +1339,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
57318 ret = 0;
57319 pipe_lock(pipe);
57320
57321- if (!pipe->readers) {
57322+ if (!atomic_read(&pipe->readers)) {
57323 send_sig(SIGPIPE, current, 0);
57324 if (!ret)
57325 ret = -EPIPE;
57326@@ -1364,7 +1364,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
57327 page_nr++;
57328 ret += buf->len;
57329
57330- if (pipe->files)
57331+ if (atomic_read(&pipe->files))
57332 do_wakeup = 1;
57333 }
57334
57335diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
57336index 72a5d5b..c991011 100644
57337--- a/fs/fuse/dir.c
57338+++ b/fs/fuse/dir.c
57339@@ -1433,7 +1433,7 @@ static char *read_link(struct dentry *dentry)
57340 return link;
57341 }
57342
57343-static void free_link(char *link)
57344+static void free_link(const char *link)
57345 {
57346 if (!IS_ERR(link))
57347 free_page((unsigned long) link);
57348diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
57349index 64915ee..6bed500 100644
57350--- a/fs/gfs2/inode.c
57351+++ b/fs/gfs2/inode.c
57352@@ -1506,7 +1506,7 @@ out:
57353
57354 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
57355 {
57356- char *s = nd_get_link(nd);
57357+ const char *s = nd_get_link(nd);
57358 if (!IS_ERR(s))
57359 kfree(s);
57360 }
57361diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
57362index d19b30a..ef89c36 100644
57363--- a/fs/hugetlbfs/inode.c
57364+++ b/fs/hugetlbfs/inode.c
57365@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
57366 struct mm_struct *mm = current->mm;
57367 struct vm_area_struct *vma;
57368 struct hstate *h = hstate_file(file);
57369+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
57370 struct vm_unmapped_area_info info;
57371
57372 if (len & ~huge_page_mask(h))
57373@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
57374 return addr;
57375 }
57376
57377+#ifdef CONFIG_PAX_RANDMMAP
57378+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
57379+#endif
57380+
57381 if (addr) {
57382 addr = ALIGN(addr, huge_page_size(h));
57383 vma = find_vma(mm, addr);
57384- if (TASK_SIZE - len >= addr &&
57385- (!vma || addr + len <= vma->vm_start))
57386+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
57387 return addr;
57388 }
57389
57390 info.flags = 0;
57391 info.length = len;
57392 info.low_limit = TASK_UNMAPPED_BASE;
57393+
57394+#ifdef CONFIG_PAX_RANDMMAP
57395+ if (mm->pax_flags & MF_PAX_RANDMMAP)
57396+ info.low_limit += mm->delta_mmap;
57397+#endif
57398+
57399 info.high_limit = TASK_SIZE;
57400 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
57401 info.align_offset = 0;
57402@@ -908,7 +918,7 @@ static struct file_system_type hugetlbfs_fs_type = {
57403 };
57404 MODULE_ALIAS_FS("hugetlbfs");
57405
57406-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
57407+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
57408
57409 static int can_do_hugetlb_shm(void)
57410 {
57411diff --git a/fs/inode.c b/fs/inode.c
57412index d6dfb09..602e77e 100644
57413--- a/fs/inode.c
57414+++ b/fs/inode.c
57415@@ -880,8 +880,8 @@ unsigned int get_next_ino(void)
57416
57417 #ifdef CONFIG_SMP
57418 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
57419- static atomic_t shared_last_ino;
57420- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
57421+ static atomic_unchecked_t shared_last_ino;
57422+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
57423
57424 res = next - LAST_INO_BATCH;
57425 }
57426diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
57427index 4a6cf28..d3a29d3 100644
57428--- a/fs/jffs2/erase.c
57429+++ b/fs/jffs2/erase.c
57430@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
57431 struct jffs2_unknown_node marker = {
57432 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
57433 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
57434- .totlen = cpu_to_je32(c->cleanmarker_size)
57435+ .totlen = cpu_to_je32(c->cleanmarker_size),
57436+ .hdr_crc = cpu_to_je32(0)
57437 };
57438
57439 jffs2_prealloc_raw_node_refs(c, jeb, 1);
57440diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
57441index a6597d6..41b30ec 100644
57442--- a/fs/jffs2/wbuf.c
57443+++ b/fs/jffs2/wbuf.c
57444@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
57445 {
57446 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
57447 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
57448- .totlen = constant_cpu_to_je32(8)
57449+ .totlen = constant_cpu_to_je32(8),
57450+ .hdr_crc = constant_cpu_to_je32(0)
57451 };
57452
57453 /*
57454diff --git a/fs/jfs/super.c b/fs/jfs/super.c
57455index 6669aa2..36b033d 100644
57456--- a/fs/jfs/super.c
57457+++ b/fs/jfs/super.c
57458@@ -882,7 +882,7 @@ static int __init init_jfs_fs(void)
57459
57460 jfs_inode_cachep =
57461 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
57462- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
57463+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
57464 init_once);
57465 if (jfs_inode_cachep == NULL)
57466 return -ENOMEM;
57467diff --git a/fs/libfs.c b/fs/libfs.c
57468index 3a3a9b5..3a9b074 100644
57469--- a/fs/libfs.c
57470+++ b/fs/libfs.c
57471@@ -150,6 +150,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
57472
57473 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
57474 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
57475+ char d_name[sizeof(next->d_iname)];
57476+ const unsigned char *name;
57477+
57478 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
57479 if (!simple_positive(next)) {
57480 spin_unlock(&next->d_lock);
57481@@ -158,7 +161,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
57482
57483 spin_unlock(&next->d_lock);
57484 spin_unlock(&dentry->d_lock);
57485- if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
57486+ name = next->d_name.name;
57487+ if (name == next->d_iname) {
57488+ memcpy(d_name, name, next->d_name.len);
57489+ name = d_name;
57490+ }
57491+ if (!dir_emit(ctx, name, next->d_name.len,
57492 next->d_inode->i_ino, dt_type(next->d_inode)))
57493 return 0;
57494 spin_lock(&dentry->d_lock);
57495diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
57496index acd3947..1f896e2 100644
57497--- a/fs/lockd/clntproc.c
57498+++ b/fs/lockd/clntproc.c
57499@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
57500 /*
57501 * Cookie counter for NLM requests
57502 */
57503-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
57504+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
57505
57506 void nlmclnt_next_cookie(struct nlm_cookie *c)
57507 {
57508- u32 cookie = atomic_inc_return(&nlm_cookie);
57509+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
57510
57511 memcpy(c->data, &cookie, 4);
57512 c->len=4;
57513diff --git a/fs/locks.c b/fs/locks.c
57514index b27a300..4156d0b 100644
57515--- a/fs/locks.c
57516+++ b/fs/locks.c
57517@@ -2183,16 +2183,16 @@ void locks_remove_flock(struct file *filp)
57518 return;
57519
57520 if (filp->f_op && filp->f_op->flock) {
57521- struct file_lock fl = {
57522+ struct file_lock flock = {
57523 .fl_pid = current->tgid,
57524 .fl_file = filp,
57525 .fl_flags = FL_FLOCK,
57526 .fl_type = F_UNLCK,
57527 .fl_end = OFFSET_MAX,
57528 };
57529- filp->f_op->flock(filp, F_SETLKW, &fl);
57530- if (fl.fl_ops && fl.fl_ops->fl_release_private)
57531- fl.fl_ops->fl_release_private(&fl);
57532+ filp->f_op->flock(filp, F_SETLKW, &flock);
57533+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
57534+ flock.fl_ops->fl_release_private(&flock);
57535 }
57536
57537 spin_lock(&inode->i_lock);
57538diff --git a/fs/namei.c b/fs/namei.c
57539index 7720fbd..7934bb2 100644
57540--- a/fs/namei.c
57541+++ b/fs/namei.c
57542@@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
57543 if (ret != -EACCES)
57544 return ret;
57545
57546+#ifdef CONFIG_GRKERNSEC
57547+ /* we'll block if we have to log due to a denied capability use */
57548+ if (mask & MAY_NOT_BLOCK)
57549+ return -ECHILD;
57550+#endif
57551+
57552 if (S_ISDIR(inode->i_mode)) {
57553 /* DACs are overridable for directories */
57554- if (inode_capable(inode, CAP_DAC_OVERRIDE))
57555- return 0;
57556 if (!(mask & MAY_WRITE))
57557- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
57558+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
57559+ inode_capable(inode, CAP_DAC_READ_SEARCH))
57560 return 0;
57561+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
57562+ return 0;
57563 return -EACCES;
57564 }
57565 /*
57566+ * Searching includes executable on directories, else just read.
57567+ */
57568+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
57569+ if (mask == MAY_READ)
57570+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
57571+ inode_capable(inode, CAP_DAC_READ_SEARCH))
57572+ return 0;
57573+
57574+ /*
57575 * Read/write DACs are always overridable.
57576 * Executable DACs are overridable when there is
57577 * at least one exec bit set.
57578@@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
57579 if (inode_capable(inode, CAP_DAC_OVERRIDE))
57580 return 0;
57581
57582- /*
57583- * Searching includes executable on directories, else just read.
57584- */
57585- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
57586- if (mask == MAY_READ)
57587- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
57588- return 0;
57589-
57590 return -EACCES;
57591 }
57592
57593@@ -820,7 +828,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
57594 {
57595 struct dentry *dentry = link->dentry;
57596 int error;
57597- char *s;
57598+ const char *s;
57599
57600 BUG_ON(nd->flags & LOOKUP_RCU);
57601
57602@@ -841,6 +849,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
57603 if (error)
57604 goto out_put_nd_path;
57605
57606+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
57607+ dentry->d_inode, dentry, nd->path.mnt)) {
57608+ error = -EACCES;
57609+ goto out_put_nd_path;
57610+ }
57611+
57612 nd->last_type = LAST_BIND;
57613 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
57614 error = PTR_ERR(*p);
57615@@ -1588,6 +1602,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
57616 if (res)
57617 break;
57618 res = walk_component(nd, path, LOOKUP_FOLLOW);
57619+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
57620+ res = -EACCES;
57621 put_link(nd, &link, cookie);
57622 } while (res > 0);
57623
57624@@ -1686,7 +1702,7 @@ EXPORT_SYMBOL(full_name_hash);
57625 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
57626 {
57627 unsigned long a, b, adata, bdata, mask, hash, len;
57628- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
57629+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
57630
57631 hash = a = 0;
57632 len = -sizeof(unsigned long);
57633@@ -1967,6 +1983,8 @@ static int path_lookupat(int dfd, const char *name,
57634 if (err)
57635 break;
57636 err = lookup_last(nd, &path);
57637+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
57638+ err = -EACCES;
57639 put_link(nd, &link, cookie);
57640 }
57641 }
57642@@ -1974,6 +1992,13 @@ static int path_lookupat(int dfd, const char *name,
57643 if (!err)
57644 err = complete_walk(nd);
57645
57646+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
57647+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
57648+ path_put(&nd->path);
57649+ err = -ENOENT;
57650+ }
57651+ }
57652+
57653 if (!err && nd->flags & LOOKUP_DIRECTORY) {
57654 if (!can_lookup(nd->inode)) {
57655 path_put(&nd->path);
57656@@ -2001,8 +2026,15 @@ static int filename_lookup(int dfd, struct filename *name,
57657 retval = path_lookupat(dfd, name->name,
57658 flags | LOOKUP_REVAL, nd);
57659
57660- if (likely(!retval))
57661+ if (likely(!retval)) {
57662 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
57663+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
57664+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
57665+ path_put(&nd->path);
57666+ return -ENOENT;
57667+ }
57668+ }
57669+ }
57670 return retval;
57671 }
57672
57673@@ -2380,6 +2412,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
57674 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
57675 return -EPERM;
57676
57677+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
57678+ return -EPERM;
57679+ if (gr_handle_rawio(inode))
57680+ return -EPERM;
57681+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
57682+ return -EACCES;
57683+
57684 return 0;
57685 }
57686
57687@@ -2601,7 +2640,7 @@ looked_up:
57688 * cleared otherwise prior to returning.
57689 */
57690 static int lookup_open(struct nameidata *nd, struct path *path,
57691- struct file *file,
57692+ struct path *link, struct file *file,
57693 const struct open_flags *op,
57694 bool got_write, int *opened)
57695 {
57696@@ -2636,6 +2675,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
57697 /* Negative dentry, just create the file */
57698 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
57699 umode_t mode = op->mode;
57700+
57701+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
57702+ error = -EACCES;
57703+ goto out_dput;
57704+ }
57705+
57706+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
57707+ error = -EACCES;
57708+ goto out_dput;
57709+ }
57710+
57711 if (!IS_POSIXACL(dir->d_inode))
57712 mode &= ~current_umask();
57713 /*
57714@@ -2657,6 +2707,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
57715 nd->flags & LOOKUP_EXCL);
57716 if (error)
57717 goto out_dput;
57718+ else
57719+ gr_handle_create(dentry, nd->path.mnt);
57720 }
57721 out_no_open:
57722 path->dentry = dentry;
57723@@ -2671,7 +2723,7 @@ out_dput:
57724 /*
57725 * Handle the last step of open()
57726 */
57727-static int do_last(struct nameidata *nd, struct path *path,
57728+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
57729 struct file *file, const struct open_flags *op,
57730 int *opened, struct filename *name)
57731 {
57732@@ -2721,6 +2773,15 @@ static int do_last(struct nameidata *nd, struct path *path,
57733 if (error)
57734 return error;
57735
57736+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
57737+ error = -ENOENT;
57738+ goto out;
57739+ }
57740+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
57741+ error = -EACCES;
57742+ goto out;
57743+ }
57744+
57745 audit_inode(name, dir, LOOKUP_PARENT);
57746 error = -EISDIR;
57747 /* trailing slashes? */
57748@@ -2740,7 +2801,7 @@ retry_lookup:
57749 */
57750 }
57751 mutex_lock(&dir->d_inode->i_mutex);
57752- error = lookup_open(nd, path, file, op, got_write, opened);
57753+ error = lookup_open(nd, path, link, file, op, got_write, opened);
57754 mutex_unlock(&dir->d_inode->i_mutex);
57755
57756 if (error <= 0) {
57757@@ -2764,11 +2825,28 @@ retry_lookup:
57758 goto finish_open_created;
57759 }
57760
57761+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
57762+ error = -ENOENT;
57763+ goto exit_dput;
57764+ }
57765+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
57766+ error = -EACCES;
57767+ goto exit_dput;
57768+ }
57769+
57770 /*
57771 * create/update audit record if it already exists.
57772 */
57773- if (path->dentry->d_inode)
57774+ if (path->dentry->d_inode) {
57775+ /* only check if O_CREAT is specified, all other checks need to go
57776+ into may_open */
57777+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
57778+ error = -EACCES;
57779+ goto exit_dput;
57780+ }
57781+
57782 audit_inode(name, path->dentry, 0);
57783+ }
57784
57785 /*
57786 * If atomic_open() acquired write access it is dropped now due to
57787@@ -2809,6 +2887,11 @@ finish_lookup:
57788 }
57789 }
57790 BUG_ON(inode != path->dentry->d_inode);
57791+ /* if we're resolving a symlink to another symlink */
57792+ if (link && gr_handle_symlink_owner(link, inode)) {
57793+ error = -EACCES;
57794+ goto out;
57795+ }
57796 return 1;
57797 }
57798
57799@@ -2818,7 +2901,6 @@ finish_lookup:
57800 save_parent.dentry = nd->path.dentry;
57801 save_parent.mnt = mntget(path->mnt);
57802 nd->path.dentry = path->dentry;
57803-
57804 }
57805 nd->inode = inode;
57806 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
57807@@ -2828,7 +2910,18 @@ finish_open:
57808 path_put(&save_parent);
57809 return error;
57810 }
57811+
57812+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
57813+ error = -ENOENT;
57814+ goto out;
57815+ }
57816+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
57817+ error = -EACCES;
57818+ goto out;
57819+ }
57820+
57821 audit_inode(name, nd->path.dentry, 0);
57822+
57823 error = -EISDIR;
57824 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
57825 goto out;
57826@@ -2991,7 +3084,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
57827 if (unlikely(error))
57828 goto out;
57829
57830- error = do_last(nd, &path, file, op, &opened, pathname);
57831+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
57832 while (unlikely(error > 0)) { /* trailing symlink */
57833 struct path link = path;
57834 void *cookie;
57835@@ -3009,7 +3102,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
57836 error = follow_link(&link, nd, &cookie);
57837 if (unlikely(error))
57838 break;
57839- error = do_last(nd, &path, file, op, &opened, pathname);
57840+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
57841 put_link(nd, &link, cookie);
57842 }
57843 out:
57844@@ -3109,8 +3202,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
57845 goto unlock;
57846
57847 error = -EEXIST;
57848- if (dentry->d_inode)
57849+ if (dentry->d_inode) {
57850+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
57851+ error = -ENOENT;
57852+ }
57853 goto fail;
57854+ }
57855 /*
57856 * Special case - lookup gave negative, but... we had foo/bar/
57857 * From the vfs_mknod() POV we just have a negative dentry -
57858@@ -3162,6 +3259,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
57859 }
57860 EXPORT_SYMBOL(user_path_create);
57861
57862+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
57863+{
57864+ struct filename *tmp = getname(pathname);
57865+ struct dentry *res;
57866+ if (IS_ERR(tmp))
57867+ return ERR_CAST(tmp);
57868+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
57869+ if (IS_ERR(res))
57870+ putname(tmp);
57871+ else
57872+ *to = tmp;
57873+ return res;
57874+}
57875+
57876 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
57877 {
57878 int error = may_create(dir, dentry);
57879@@ -3224,6 +3335,17 @@ retry:
57880
57881 if (!IS_POSIXACL(path.dentry->d_inode))
57882 mode &= ~current_umask();
57883+
57884+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
57885+ error = -EPERM;
57886+ goto out;
57887+ }
57888+
57889+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
57890+ error = -EACCES;
57891+ goto out;
57892+ }
57893+
57894 error = security_path_mknod(&path, dentry, mode, dev);
57895 if (error)
57896 goto out;
57897@@ -3240,6 +3362,8 @@ retry:
57898 break;
57899 }
57900 out:
57901+ if (!error)
57902+ gr_handle_create(dentry, path.mnt);
57903 done_path_create(&path, dentry);
57904 if (retry_estale(error, lookup_flags)) {
57905 lookup_flags |= LOOKUP_REVAL;
57906@@ -3292,9 +3416,16 @@ retry:
57907
57908 if (!IS_POSIXACL(path.dentry->d_inode))
57909 mode &= ~current_umask();
57910+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
57911+ error = -EACCES;
57912+ goto out;
57913+ }
57914 error = security_path_mkdir(&path, dentry, mode);
57915 if (!error)
57916 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
57917+ if (!error)
57918+ gr_handle_create(dentry, path.mnt);
57919+out:
57920 done_path_create(&path, dentry);
57921 if (retry_estale(error, lookup_flags)) {
57922 lookup_flags |= LOOKUP_REVAL;
57923@@ -3375,6 +3506,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
57924 struct filename *name;
57925 struct dentry *dentry;
57926 struct nameidata nd;
57927+ ino_t saved_ino = 0;
57928+ dev_t saved_dev = 0;
57929 unsigned int lookup_flags = 0;
57930 retry:
57931 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
57932@@ -3407,10 +3540,21 @@ retry:
57933 error = -ENOENT;
57934 goto exit3;
57935 }
57936+
57937+ saved_ino = dentry->d_inode->i_ino;
57938+ saved_dev = gr_get_dev_from_dentry(dentry);
57939+
57940+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
57941+ error = -EACCES;
57942+ goto exit3;
57943+ }
57944+
57945 error = security_path_rmdir(&nd.path, dentry);
57946 if (error)
57947 goto exit3;
57948 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
57949+ if (!error && (saved_dev || saved_ino))
57950+ gr_handle_delete(saved_ino, saved_dev);
57951 exit3:
57952 dput(dentry);
57953 exit2:
57954@@ -3476,6 +3620,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
57955 struct dentry *dentry;
57956 struct nameidata nd;
57957 struct inode *inode = NULL;
57958+ ino_t saved_ino = 0;
57959+ dev_t saved_dev = 0;
57960 unsigned int lookup_flags = 0;
57961 retry:
57962 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
57963@@ -3502,10 +3648,22 @@ retry:
57964 if (!inode)
57965 goto slashes;
57966 ihold(inode);
57967+
57968+ if (inode->i_nlink <= 1) {
57969+ saved_ino = inode->i_ino;
57970+ saved_dev = gr_get_dev_from_dentry(dentry);
57971+ }
57972+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
57973+ error = -EACCES;
57974+ goto exit2;
57975+ }
57976+
57977 error = security_path_unlink(&nd.path, dentry);
57978 if (error)
57979 goto exit2;
57980 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
57981+ if (!error && (saved_ino || saved_dev))
57982+ gr_handle_delete(saved_ino, saved_dev);
57983 exit2:
57984 dput(dentry);
57985 }
57986@@ -3583,9 +3741,17 @@ retry:
57987 if (IS_ERR(dentry))
57988 goto out_putname;
57989
57990+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
57991+ error = -EACCES;
57992+ goto out;
57993+ }
57994+
57995 error = security_path_symlink(&path, dentry, from->name);
57996 if (!error)
57997 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
57998+ if (!error)
57999+ gr_handle_create(dentry, path.mnt);
58000+out:
58001 done_path_create(&path, dentry);
58002 if (retry_estale(error, lookup_flags)) {
58003 lookup_flags |= LOOKUP_REVAL;
58004@@ -3665,6 +3831,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
58005 {
58006 struct dentry *new_dentry;
58007 struct path old_path, new_path;
58008+ struct filename *to = NULL;
58009 int how = 0;
58010 int error;
58011
58012@@ -3688,7 +3855,7 @@ retry:
58013 if (error)
58014 return error;
58015
58016- new_dentry = user_path_create(newdfd, newname, &new_path,
58017+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
58018 (how & LOOKUP_REVAL));
58019 error = PTR_ERR(new_dentry);
58020 if (IS_ERR(new_dentry))
58021@@ -3700,11 +3867,28 @@ retry:
58022 error = may_linkat(&old_path);
58023 if (unlikely(error))
58024 goto out_dput;
58025+
58026+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
58027+ old_path.dentry->d_inode,
58028+ old_path.dentry->d_inode->i_mode, to)) {
58029+ error = -EACCES;
58030+ goto out_dput;
58031+ }
58032+
58033+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
58034+ old_path.dentry, old_path.mnt, to)) {
58035+ error = -EACCES;
58036+ goto out_dput;
58037+ }
58038+
58039 error = security_path_link(old_path.dentry, &new_path, new_dentry);
58040 if (error)
58041 goto out_dput;
58042 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
58043+ if (!error)
58044+ gr_handle_create(new_dentry, new_path.mnt);
58045 out_dput:
58046+ putname(to);
58047 done_path_create(&new_path, new_dentry);
58048 if (retry_estale(error, how)) {
58049 how |= LOOKUP_REVAL;
58050@@ -3950,12 +4134,21 @@ retry:
58051 if (new_dentry == trap)
58052 goto exit5;
58053
58054+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
58055+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
58056+ to);
58057+ if (error)
58058+ goto exit5;
58059+
58060 error = security_path_rename(&oldnd.path, old_dentry,
58061 &newnd.path, new_dentry);
58062 if (error)
58063 goto exit5;
58064 error = vfs_rename(old_dir->d_inode, old_dentry,
58065 new_dir->d_inode, new_dentry);
58066+ if (!error)
58067+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
58068+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
58069 exit5:
58070 dput(new_dentry);
58071 exit4:
58072@@ -3987,6 +4180,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
58073
58074 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
58075 {
58076+ char tmpbuf[64];
58077+ const char *newlink;
58078 int len;
58079
58080 len = PTR_ERR(link);
58081@@ -3996,7 +4191,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
58082 len = strlen(link);
58083 if (len > (unsigned) buflen)
58084 len = buflen;
58085- if (copy_to_user(buffer, link, len))
58086+
58087+ if (len < sizeof(tmpbuf)) {
58088+ memcpy(tmpbuf, link, len);
58089+ newlink = tmpbuf;
58090+ } else
58091+ newlink = link;
58092+
58093+ if (copy_to_user(buffer, newlink, len))
58094 len = -EFAULT;
58095 out:
58096 return len;
58097diff --git a/fs/namespace.c b/fs/namespace.c
58098index a45ba4f..b4c7d07 100644
58099--- a/fs/namespace.c
58100+++ b/fs/namespace.c
58101@@ -1265,6 +1265,9 @@ static int do_umount(struct mount *mnt, int flags)
58102 if (!(sb->s_flags & MS_RDONLY))
58103 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
58104 up_write(&sb->s_umount);
58105+
58106+ gr_log_remount(mnt->mnt_devname, retval);
58107+
58108 return retval;
58109 }
58110
58111@@ -1283,6 +1286,9 @@ static int do_umount(struct mount *mnt, int flags)
58112 }
58113 br_write_unlock(&vfsmount_lock);
58114 namespace_unlock();
58115+
58116+ gr_log_unmount(mnt->mnt_devname, retval);
58117+
58118 return retval;
58119 }
58120
58121@@ -1302,7 +1308,7 @@ static inline bool may_mount(void)
58122 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
58123 */
58124
58125-SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
58126+SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
58127 {
58128 struct path path;
58129 struct mount *mnt;
58130@@ -1342,7 +1348,7 @@ out:
58131 /*
58132 * The 2.0 compatible umount. No flags.
58133 */
58134-SYSCALL_DEFINE1(oldumount, char __user *, name)
58135+SYSCALL_DEFINE1(oldumount, const char __user *, name)
58136 {
58137 return sys_umount(name, 0);
58138 }
58139@@ -2313,6 +2319,16 @@ long do_mount(const char *dev_name, const char *dir_name,
58140 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
58141 MS_STRICTATIME);
58142
58143+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
58144+ retval = -EPERM;
58145+ goto dput_out;
58146+ }
58147+
58148+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
58149+ retval = -EPERM;
58150+ goto dput_out;
58151+ }
58152+
58153 if (flags & MS_REMOUNT)
58154 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
58155 data_page);
58156@@ -2327,6 +2343,9 @@ long do_mount(const char *dev_name, const char *dir_name,
58157 dev_name, data_page);
58158 dput_out:
58159 path_put(&path);
58160+
58161+ gr_log_mount(dev_name, dir_name, retval);
58162+
58163 return retval;
58164 }
58165
58166@@ -2344,7 +2363,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
58167 * number incrementing at 10Ghz will take 12,427 years to wrap which
58168 * is effectively never, so we can ignore the possibility.
58169 */
58170-static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
58171+static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
58172
58173 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
58174 {
58175@@ -2359,7 +2378,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
58176 kfree(new_ns);
58177 return ERR_PTR(ret);
58178 }
58179- new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
58180+ new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
58181 atomic_set(&new_ns->count, 1);
58182 new_ns->root = NULL;
58183 INIT_LIST_HEAD(&new_ns->list);
58184@@ -2373,7 +2392,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
58185 * Allocate a new namespace structure and populate it with contents
58186 * copied from the namespace of the passed in task structure.
58187 */
58188-static struct mnt_namespace *dup_mnt_ns(struct mnt_namespace *mnt_ns,
58189+static __latent_entropy struct mnt_namespace *dup_mnt_ns(struct mnt_namespace *mnt_ns,
58190 struct user_namespace *user_ns, struct fs_struct *fs)
58191 {
58192 struct mnt_namespace *new_ns;
58193@@ -2500,8 +2519,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
58194 }
58195 EXPORT_SYMBOL(mount_subtree);
58196
58197-SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
58198- char __user *, type, unsigned long, flags, void __user *, data)
58199+SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
58200+ const char __user *, type, unsigned long, flags, void __user *, data)
58201 {
58202 int ret;
58203 char *kernel_type;
58204@@ -2614,6 +2633,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
58205 if (error)
58206 goto out2;
58207
58208+ if (gr_handle_chroot_pivot()) {
58209+ error = -EPERM;
58210+ goto out2;
58211+ }
58212+
58213 get_fs_root(current->fs, &root);
58214 old_mp = lock_mount(&old);
58215 error = PTR_ERR(old_mp);
58216@@ -2864,7 +2888,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
58217 !nsown_capable(CAP_SYS_ADMIN))
58218 return -EPERM;
58219
58220- if (fs->users != 1)
58221+ if (atomic_read(&fs->users) != 1)
58222 return -EINVAL;
58223
58224 get_mnt_ns(mnt_ns);
58225diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
58226index f4ccfe6..a5cf064 100644
58227--- a/fs/nfs/callback_xdr.c
58228+++ b/fs/nfs/callback_xdr.c
58229@@ -51,7 +51,7 @@ struct callback_op {
58230 callback_decode_arg_t decode_args;
58231 callback_encode_res_t encode_res;
58232 long res_maxsize;
58233-};
58234+} __do_const;
58235
58236 static struct callback_op callback_ops[];
58237
58238diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
58239index 941246f..17d8724 100644
58240--- a/fs/nfs/inode.c
58241+++ b/fs/nfs/inode.c
58242@@ -1138,16 +1138,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
58243 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
58244 }
58245
58246-static atomic_long_t nfs_attr_generation_counter;
58247+static atomic_long_unchecked_t nfs_attr_generation_counter;
58248
58249 static unsigned long nfs_read_attr_generation_counter(void)
58250 {
58251- return atomic_long_read(&nfs_attr_generation_counter);
58252+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
58253 }
58254
58255 unsigned long nfs_inc_attr_generation_counter(void)
58256 {
58257- return atomic_long_inc_return(&nfs_attr_generation_counter);
58258+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
58259 }
58260
58261 void nfs_fattr_init(struct nfs_fattr *fattr)
58262diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
58263index 419572f..5414a23 100644
58264--- a/fs/nfsd/nfs4proc.c
58265+++ b/fs/nfsd/nfs4proc.c
58266@@ -1168,7 +1168,7 @@ struct nfsd4_operation {
58267 nfsd4op_rsize op_rsize_bop;
58268 stateid_getter op_get_currentstateid;
58269 stateid_setter op_set_currentstateid;
58270-};
58271+} __do_const;
58272
58273 static struct nfsd4_operation nfsd4_ops[];
58274
58275diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
58276index c2a4701..fd80e29 100644
58277--- a/fs/nfsd/nfs4xdr.c
58278+++ b/fs/nfsd/nfs4xdr.c
58279@@ -1498,7 +1498,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
58280
58281 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
58282
58283-static nfsd4_dec nfsd4_dec_ops[] = {
58284+static const nfsd4_dec nfsd4_dec_ops[] = {
58285 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
58286 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
58287 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
58288@@ -1538,7 +1538,7 @@ static nfsd4_dec nfsd4_dec_ops[] = {
58289 [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner,
58290 };
58291
58292-static nfsd4_dec nfsd41_dec_ops[] = {
58293+static const nfsd4_dec nfsd41_dec_ops[] = {
58294 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
58295 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
58296 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
58297@@ -1600,7 +1600,7 @@ static nfsd4_dec nfsd41_dec_ops[] = {
58298 };
58299
58300 struct nfsd4_minorversion_ops {
58301- nfsd4_dec *decoders;
58302+ const nfsd4_dec *decoders;
58303 int nops;
58304 };
58305
58306diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
58307index e76244e..9fe8f2f1 100644
58308--- a/fs/nfsd/nfscache.c
58309+++ b/fs/nfsd/nfscache.c
58310@@ -526,14 +526,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
58311 {
58312 struct svc_cacherep *rp = rqstp->rq_cacherep;
58313 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
58314- int len;
58315+ long len;
58316 size_t bufsize = 0;
58317
58318 if (!rp)
58319 return;
58320
58321- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
58322- len >>= 2;
58323+ if (statp) {
58324+ len = (char*)statp - (char*)resv->iov_base;
58325+ len = resv->iov_len - len;
58326+ len >>= 2;
58327+ }
58328
58329 /* Don't cache excessive amounts of data and XDR failures */
58330 if (!statp || len > (256 >> 2)) {
58331diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
58332index c827acb..b253b77 100644
58333--- a/fs/nfsd/vfs.c
58334+++ b/fs/nfsd/vfs.c
58335@@ -968,7 +968,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
58336 } else {
58337 oldfs = get_fs();
58338 set_fs(KERNEL_DS);
58339- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
58340+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
58341 set_fs(oldfs);
58342 }
58343
58344@@ -1055,7 +1055,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
58345
58346 /* Write the data. */
58347 oldfs = get_fs(); set_fs(KERNEL_DS);
58348- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
58349+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
58350 set_fs(oldfs);
58351 if (host_err < 0)
58352 goto out_nfserr;
58353@@ -1601,7 +1601,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
58354 */
58355
58356 oldfs = get_fs(); set_fs(KERNEL_DS);
58357- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
58358+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
58359 set_fs(oldfs);
58360
58361 if (host_err < 0)
58362diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
58363index fea6bd5..8ee9d81 100644
58364--- a/fs/nls/nls_base.c
58365+++ b/fs/nls/nls_base.c
58366@@ -234,20 +234,22 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
58367
58368 int register_nls(struct nls_table * nls)
58369 {
58370- struct nls_table ** tmp = &tables;
58371+ struct nls_table *tmp = tables;
58372
58373 if (nls->next)
58374 return -EBUSY;
58375
58376 spin_lock(&nls_lock);
58377- while (*tmp) {
58378- if (nls == *tmp) {
58379+ while (tmp) {
58380+ if (nls == tmp) {
58381 spin_unlock(&nls_lock);
58382 return -EBUSY;
58383 }
58384- tmp = &(*tmp)->next;
58385+ tmp = tmp->next;
58386 }
58387- nls->next = tables;
58388+ pax_open_kernel();
58389+ *(struct nls_table **)&nls->next = tables;
58390+ pax_close_kernel();
58391 tables = nls;
58392 spin_unlock(&nls_lock);
58393 return 0;
58394@@ -255,12 +257,14 @@ int register_nls(struct nls_table * nls)
58395
58396 int unregister_nls(struct nls_table * nls)
58397 {
58398- struct nls_table ** tmp = &tables;
58399+ struct nls_table * const * tmp = &tables;
58400
58401 spin_lock(&nls_lock);
58402 while (*tmp) {
58403 if (nls == *tmp) {
58404- *tmp = nls->next;
58405+ pax_open_kernel();
58406+ *(struct nls_table **)tmp = nls->next;
58407+ pax_close_kernel();
58408 spin_unlock(&nls_lock);
58409 return 0;
58410 }
58411diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
58412index 7424929..35f6be5 100644
58413--- a/fs/nls/nls_euc-jp.c
58414+++ b/fs/nls/nls_euc-jp.c
58415@@ -561,8 +561,10 @@ static int __init init_nls_euc_jp(void)
58416 p_nls = load_nls("cp932");
58417
58418 if (p_nls) {
58419- table.charset2upper = p_nls->charset2upper;
58420- table.charset2lower = p_nls->charset2lower;
58421+ pax_open_kernel();
58422+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
58423+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
58424+ pax_close_kernel();
58425 return register_nls(&table);
58426 }
58427
58428diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
58429index e7bc1d7..06bd4bb 100644
58430--- a/fs/nls/nls_koi8-ru.c
58431+++ b/fs/nls/nls_koi8-ru.c
58432@@ -63,8 +63,10 @@ static int __init init_nls_koi8_ru(void)
58433 p_nls = load_nls("koi8-u");
58434
58435 if (p_nls) {
58436- table.charset2upper = p_nls->charset2upper;
58437- table.charset2lower = p_nls->charset2lower;
58438+ pax_open_kernel();
58439+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
58440+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
58441+ pax_close_kernel();
58442 return register_nls(&table);
58443 }
58444
58445diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
58446index e44cb64..4807084 100644
58447--- a/fs/notify/fanotify/fanotify_user.c
58448+++ b/fs/notify/fanotify/fanotify_user.c
58449@@ -253,8 +253,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
58450
58451 fd = fanotify_event_metadata.fd;
58452 ret = -EFAULT;
58453- if (copy_to_user(buf, &fanotify_event_metadata,
58454- fanotify_event_metadata.event_len))
58455+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
58456+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
58457 goto out_close_fd;
58458
58459 ret = prepare_for_access_response(group, event, fd);
58460diff --git a/fs/notify/notification.c b/fs/notify/notification.c
58461index 7b51b05..5ea5ef6 100644
58462--- a/fs/notify/notification.c
58463+++ b/fs/notify/notification.c
58464@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
58465 * get set to 0 so it will never get 'freed'
58466 */
58467 static struct fsnotify_event *q_overflow_event;
58468-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
58469+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
58470
58471 /**
58472 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
58473@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
58474 */
58475 u32 fsnotify_get_cookie(void)
58476 {
58477- return atomic_inc_return(&fsnotify_sync_cookie);
58478+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
58479 }
58480 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
58481
58482diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
58483index 9e38daf..5727cae 100644
58484--- a/fs/ntfs/dir.c
58485+++ b/fs/ntfs/dir.c
58486@@ -1310,7 +1310,7 @@ find_next_index_buffer:
58487 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
58488 ~(s64)(ndir->itype.index.block_size - 1)));
58489 /* Bounds checks. */
58490- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
58491+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
58492 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
58493 "inode 0x%lx or driver bug.", vdir->i_ino);
58494 goto err_out;
58495diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
58496index c5670b8..d590213 100644
58497--- a/fs/ntfs/file.c
58498+++ b/fs/ntfs/file.c
58499@@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
58500 char *addr;
58501 size_t total = 0;
58502 unsigned len;
58503- int left;
58504+ unsigned left;
58505
58506 do {
58507 len = PAGE_CACHE_SIZE - ofs;
58508diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
58509index 82650d5..db37dcf 100644
58510--- a/fs/ntfs/super.c
58511+++ b/fs/ntfs/super.c
58512@@ -685,7 +685,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
58513 if (!silent)
58514 ntfs_error(sb, "Primary boot sector is invalid.");
58515 } else if (!silent)
58516- ntfs_error(sb, read_err_str, "primary");
58517+ ntfs_error(sb, read_err_str, "%s", "primary");
58518 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
58519 if (bh_primary)
58520 brelse(bh_primary);
58521@@ -701,7 +701,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
58522 goto hotfix_primary_boot_sector;
58523 brelse(bh_backup);
58524 } else if (!silent)
58525- ntfs_error(sb, read_err_str, "backup");
58526+ ntfs_error(sb, read_err_str, "%s", "backup");
58527 /* Try to read NT3.51- backup boot sector. */
58528 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
58529 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
58530@@ -712,7 +712,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
58531 "sector.");
58532 brelse(bh_backup);
58533 } else if (!silent)
58534- ntfs_error(sb, read_err_str, "backup");
58535+ ntfs_error(sb, read_err_str, "%s", "backup");
58536 /* We failed. Cleanup and return. */
58537 if (bh_primary)
58538 brelse(bh_primary);
58539diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
58540index aebeacd..0dcdd26 100644
58541--- a/fs/ocfs2/localalloc.c
58542+++ b/fs/ocfs2/localalloc.c
58543@@ -1278,7 +1278,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
58544 goto bail;
58545 }
58546
58547- atomic_inc(&osb->alloc_stats.moves);
58548+ atomic_inc_unchecked(&osb->alloc_stats.moves);
58549
58550 bail:
58551 if (handle)
58552diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
58553index 3a90347..c40bef8 100644
58554--- a/fs/ocfs2/ocfs2.h
58555+++ b/fs/ocfs2/ocfs2.h
58556@@ -235,11 +235,11 @@ enum ocfs2_vol_state
58557
58558 struct ocfs2_alloc_stats
58559 {
58560- atomic_t moves;
58561- atomic_t local_data;
58562- atomic_t bitmap_data;
58563- atomic_t bg_allocs;
58564- atomic_t bg_extends;
58565+ atomic_unchecked_t moves;
58566+ atomic_unchecked_t local_data;
58567+ atomic_unchecked_t bitmap_data;
58568+ atomic_unchecked_t bg_allocs;
58569+ atomic_unchecked_t bg_extends;
58570 };
58571
58572 enum ocfs2_local_alloc_state
58573diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
58574index 5397c07..54afc55 100644
58575--- a/fs/ocfs2/suballoc.c
58576+++ b/fs/ocfs2/suballoc.c
58577@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
58578 mlog_errno(status);
58579 goto bail;
58580 }
58581- atomic_inc(&osb->alloc_stats.bg_extends);
58582+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
58583
58584 /* You should never ask for this much metadata */
58585 BUG_ON(bits_wanted >
58586@@ -2000,7 +2000,7 @@ int ocfs2_claim_metadata(handle_t *handle,
58587 mlog_errno(status);
58588 goto bail;
58589 }
58590- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58591+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58592
58593 *suballoc_loc = res.sr_bg_blkno;
58594 *suballoc_bit_start = res.sr_bit_offset;
58595@@ -2164,7 +2164,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
58596 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
58597 res->sr_bits);
58598
58599- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58600+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58601
58602 BUG_ON(res->sr_bits != 1);
58603
58604@@ -2206,7 +2206,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
58605 mlog_errno(status);
58606 goto bail;
58607 }
58608- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58609+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
58610
58611 BUG_ON(res.sr_bits != 1);
58612
58613@@ -2310,7 +2310,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
58614 cluster_start,
58615 num_clusters);
58616 if (!status)
58617- atomic_inc(&osb->alloc_stats.local_data);
58618+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
58619 } else {
58620 if (min_clusters > (osb->bitmap_cpg - 1)) {
58621 /* The only paths asking for contiguousness
58622@@ -2336,7 +2336,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
58623 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
58624 res.sr_bg_blkno,
58625 res.sr_bit_offset);
58626- atomic_inc(&osb->alloc_stats.bitmap_data);
58627+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
58628 *num_clusters = res.sr_bits;
58629 }
58630 }
58631diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
58632index 121da2d..a0232bc 100644
58633--- a/fs/ocfs2/super.c
58634+++ b/fs/ocfs2/super.c
58635@@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
58636 "%10s => GlobalAllocs: %d LocalAllocs: %d "
58637 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
58638 "Stats",
58639- atomic_read(&osb->alloc_stats.bitmap_data),
58640- atomic_read(&osb->alloc_stats.local_data),
58641- atomic_read(&osb->alloc_stats.bg_allocs),
58642- atomic_read(&osb->alloc_stats.moves),
58643- atomic_read(&osb->alloc_stats.bg_extends));
58644+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
58645+ atomic_read_unchecked(&osb->alloc_stats.local_data),
58646+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
58647+ atomic_read_unchecked(&osb->alloc_stats.moves),
58648+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
58649
58650 out += snprintf(buf + out, len - out,
58651 "%10s => State: %u Descriptor: %llu Size: %u bits "
58652@@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
58653 spin_lock_init(&osb->osb_xattr_lock);
58654 ocfs2_init_steal_slots(osb);
58655
58656- atomic_set(&osb->alloc_stats.moves, 0);
58657- atomic_set(&osb->alloc_stats.local_data, 0);
58658- atomic_set(&osb->alloc_stats.bitmap_data, 0);
58659- atomic_set(&osb->alloc_stats.bg_allocs, 0);
58660- atomic_set(&osb->alloc_stats.bg_extends, 0);
58661+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
58662+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
58663+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
58664+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
58665+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
58666
58667 /* Copy the blockcheck stats from the superblock probe */
58668 osb->osb_ecc_stats = *stats;
58669diff --git a/fs/open.c b/fs/open.c
58670index 7931f76..7b03f3b 100644
58671--- a/fs/open.c
58672+++ b/fs/open.c
58673@@ -32,6 +32,8 @@
58674 #include <linux/dnotify.h>
58675 #include <linux/compat.h>
58676
58677+#define CREATE_TRACE_POINTS
58678+#include <trace/events/fs.h>
58679 #include "internal.h"
58680
58681 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
58682@@ -102,6 +104,8 @@ long vfs_truncate(struct path *path, loff_t length)
58683 error = locks_verify_truncate(inode, NULL, length);
58684 if (!error)
58685 error = security_path_truncate(path);
58686+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
58687+ error = -EACCES;
58688 if (!error)
58689 error = do_truncate(path->dentry, length, 0, NULL);
58690
58691@@ -186,6 +190,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
58692 error = locks_verify_truncate(inode, f.file, length);
58693 if (!error)
58694 error = security_path_truncate(&f.file->f_path);
58695+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
58696+ error = -EACCES;
58697 if (!error)
58698 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
58699 sb_end_write(inode->i_sb);
58700@@ -360,6 +366,9 @@ retry:
58701 if (__mnt_is_readonly(path.mnt))
58702 res = -EROFS;
58703
58704+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
58705+ res = -EACCES;
58706+
58707 out_path_release:
58708 path_put(&path);
58709 if (retry_estale(res, lookup_flags)) {
58710@@ -391,6 +400,8 @@ retry:
58711 if (error)
58712 goto dput_and_out;
58713
58714+ gr_log_chdir(path.dentry, path.mnt);
58715+
58716 set_fs_pwd(current->fs, &path);
58717
58718 dput_and_out:
58719@@ -420,6 +431,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
58720 goto out_putf;
58721
58722 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
58723+
58724+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
58725+ error = -EPERM;
58726+
58727+ if (!error)
58728+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
58729+
58730 if (!error)
58731 set_fs_pwd(current->fs, &f.file->f_path);
58732 out_putf:
58733@@ -449,7 +467,13 @@ retry:
58734 if (error)
58735 goto dput_and_out;
58736
58737+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
58738+ goto dput_and_out;
58739+
58740 set_fs_root(current->fs, &path);
58741+
58742+ gr_handle_chroot_chdir(&path);
58743+
58744 error = 0;
58745 dput_and_out:
58746 path_put(&path);
58747@@ -471,6 +495,16 @@ static int chmod_common(struct path *path, umode_t mode)
58748 if (error)
58749 return error;
58750 mutex_lock(&inode->i_mutex);
58751+
58752+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
58753+ error = -EACCES;
58754+ goto out_unlock;
58755+ }
58756+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
58757+ error = -EACCES;
58758+ goto out_unlock;
58759+ }
58760+
58761 error = security_path_chmod(path, mode);
58762 if (error)
58763 goto out_unlock;
58764@@ -531,6 +565,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
58765 uid = make_kuid(current_user_ns(), user);
58766 gid = make_kgid(current_user_ns(), group);
58767
58768+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
58769+ return -EACCES;
58770+
58771 newattrs.ia_valid = ATTR_CTIME;
58772 if (user != (uid_t) -1) {
58773 if (!uid_valid(uid))
58774@@ -960,6 +997,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
58775 } else {
58776 fsnotify_open(f);
58777 fd_install(fd, f);
58778+ trace_do_sys_open(tmp->name, flags, mode);
58779 }
58780 }
58781 putname(tmp);
58782diff --git a/fs/pipe.c b/fs/pipe.c
58783index d2c45e1..009fe1c 100644
58784--- a/fs/pipe.c
58785+++ b/fs/pipe.c
58786@@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
58787
58788 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
58789 {
58790- if (pipe->files)
58791+ if (atomic_read(&pipe->files))
58792 mutex_lock_nested(&pipe->mutex, subclass);
58793 }
58794
58795@@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
58796
58797 void pipe_unlock(struct pipe_inode_info *pipe)
58798 {
58799- if (pipe->files)
58800+ if (atomic_read(&pipe->files))
58801 mutex_unlock(&pipe->mutex);
58802 }
58803 EXPORT_SYMBOL(pipe_unlock);
58804@@ -449,9 +449,9 @@ redo:
58805 }
58806 if (bufs) /* More to do? */
58807 continue;
58808- if (!pipe->writers)
58809+ if (!atomic_read(&pipe->writers))
58810 break;
58811- if (!pipe->waiting_writers) {
58812+ if (!atomic_read(&pipe->waiting_writers)) {
58813 /* syscall merging: Usually we must not sleep
58814 * if O_NONBLOCK is set, or if we got some data.
58815 * But if a writer sleeps in kernel space, then
58816@@ -513,7 +513,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
58817 ret = 0;
58818 __pipe_lock(pipe);
58819
58820- if (!pipe->readers) {
58821+ if (!atomic_read(&pipe->readers)) {
58822 send_sig(SIGPIPE, current, 0);
58823 ret = -EPIPE;
58824 goto out;
58825@@ -562,7 +562,7 @@ redo1:
58826 for (;;) {
58827 int bufs;
58828
58829- if (!pipe->readers) {
58830+ if (!atomic_read(&pipe->readers)) {
58831 send_sig(SIGPIPE, current, 0);
58832 if (!ret)
58833 ret = -EPIPE;
58834@@ -653,9 +653,9 @@ redo2:
58835 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
58836 do_wakeup = 0;
58837 }
58838- pipe->waiting_writers++;
58839+ atomic_inc(&pipe->waiting_writers);
58840 pipe_wait(pipe);
58841- pipe->waiting_writers--;
58842+ atomic_dec(&pipe->waiting_writers);
58843 }
58844 out:
58845 __pipe_unlock(pipe);
58846@@ -709,7 +709,7 @@ pipe_poll(struct file *filp, poll_table *wait)
58847 mask = 0;
58848 if (filp->f_mode & FMODE_READ) {
58849 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
58850- if (!pipe->writers && filp->f_version != pipe->w_counter)
58851+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
58852 mask |= POLLHUP;
58853 }
58854
58855@@ -719,7 +719,7 @@ pipe_poll(struct file *filp, poll_table *wait)
58856 * Most Unices do not set POLLERR for FIFOs but on Linux they
58857 * behave exactly like pipes for poll().
58858 */
58859- if (!pipe->readers)
58860+ if (!atomic_read(&pipe->readers))
58861 mask |= POLLERR;
58862 }
58863
58864@@ -734,17 +734,17 @@ pipe_release(struct inode *inode, struct file *file)
58865
58866 __pipe_lock(pipe);
58867 if (file->f_mode & FMODE_READ)
58868- pipe->readers--;
58869+ atomic_dec(&pipe->readers);
58870 if (file->f_mode & FMODE_WRITE)
58871- pipe->writers--;
58872+ atomic_dec(&pipe->writers);
58873
58874- if (pipe->readers || pipe->writers) {
58875+ if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
58876 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
58877 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
58878 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
58879 }
58880 spin_lock(&inode->i_lock);
58881- if (!--pipe->files) {
58882+ if (atomic_dec_and_test(&pipe->files)) {
58883 inode->i_pipe = NULL;
58884 kill = 1;
58885 }
58886@@ -811,7 +811,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
58887 kfree(pipe);
58888 }
58889
58890-static struct vfsmount *pipe_mnt __read_mostly;
58891+struct vfsmount *pipe_mnt __read_mostly;
58892
58893 /*
58894 * pipefs_dname() is called from d_path().
58895@@ -841,8 +841,9 @@ static struct inode * get_pipe_inode(void)
58896 goto fail_iput;
58897
58898 inode->i_pipe = pipe;
58899- pipe->files = 2;
58900- pipe->readers = pipe->writers = 1;
58901+ atomic_set(&pipe->files, 2);
58902+ atomic_set(&pipe->readers, 1);
58903+ atomic_set(&pipe->writers, 1);
58904 inode->i_fop = &pipefifo_fops;
58905
58906 /*
58907@@ -1022,17 +1023,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
58908 spin_lock(&inode->i_lock);
58909 if (inode->i_pipe) {
58910 pipe = inode->i_pipe;
58911- pipe->files++;
58912+ atomic_inc(&pipe->files);
58913 spin_unlock(&inode->i_lock);
58914 } else {
58915 spin_unlock(&inode->i_lock);
58916 pipe = alloc_pipe_info();
58917 if (!pipe)
58918 return -ENOMEM;
58919- pipe->files = 1;
58920+ atomic_set(&pipe->files, 1);
58921 spin_lock(&inode->i_lock);
58922 if (unlikely(inode->i_pipe)) {
58923- inode->i_pipe->files++;
58924+ atomic_inc(&inode->i_pipe->files);
58925 spin_unlock(&inode->i_lock);
58926 free_pipe_info(pipe);
58927 pipe = inode->i_pipe;
58928@@ -1057,10 +1058,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
58929 * opened, even when there is no process writing the FIFO.
58930 */
58931 pipe->r_counter++;
58932- if (pipe->readers++ == 0)
58933+ if (atomic_inc_return(&pipe->readers) == 1)
58934 wake_up_partner(pipe);
58935
58936- if (!is_pipe && !pipe->writers) {
58937+ if (!is_pipe && !atomic_read(&pipe->writers)) {
58938 if ((filp->f_flags & O_NONBLOCK)) {
58939 /* suppress POLLHUP until we have
58940 * seen a writer */
58941@@ -1079,14 +1080,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
58942 * errno=ENXIO when there is no process reading the FIFO.
58943 */
58944 ret = -ENXIO;
58945- if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
58946+ if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
58947 goto err;
58948
58949 pipe->w_counter++;
58950- if (!pipe->writers++)
58951+ if (atomic_inc_return(&pipe->writers) == 1)
58952 wake_up_partner(pipe);
58953
58954- if (!is_pipe && !pipe->readers) {
58955+ if (!is_pipe && !atomic_read(&pipe->readers)) {
58956 if (wait_for_partner(pipe, &pipe->r_counter))
58957 goto err_wr;
58958 }
58959@@ -1100,11 +1101,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
58960 * the process can at least talk to itself.
58961 */
58962
58963- pipe->readers++;
58964- pipe->writers++;
58965+ atomic_inc(&pipe->readers);
58966+ atomic_inc(&pipe->writers);
58967 pipe->r_counter++;
58968 pipe->w_counter++;
58969- if (pipe->readers == 1 || pipe->writers == 1)
58970+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
58971 wake_up_partner(pipe);
58972 break;
58973
58974@@ -1118,20 +1119,20 @@ static int fifo_open(struct inode *inode, struct file *filp)
58975 return 0;
58976
58977 err_rd:
58978- if (!--pipe->readers)
58979+ if (atomic_dec_and_test(&pipe->readers))
58980 wake_up_interruptible(&pipe->wait);
58981 ret = -ERESTARTSYS;
58982 goto err;
58983
58984 err_wr:
58985- if (!--pipe->writers)
58986+ if (atomic_dec_and_test(&pipe->writers))
58987 wake_up_interruptible(&pipe->wait);
58988 ret = -ERESTARTSYS;
58989 goto err;
58990
58991 err:
58992 spin_lock(&inode->i_lock);
58993- if (!--pipe->files) {
58994+ if (atomic_dec_and_test(&pipe->files)) {
58995 inode->i_pipe = NULL;
58996 kill = 1;
58997 }
58998diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
58999index 15af622..0e9f4467 100644
59000--- a/fs/proc/Kconfig
59001+++ b/fs/proc/Kconfig
59002@@ -30,12 +30,12 @@ config PROC_FS
59003
59004 config PROC_KCORE
59005 bool "/proc/kcore support" if !ARM
59006- depends on PROC_FS && MMU
59007+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
59008
59009 config PROC_VMCORE
59010 bool "/proc/vmcore support"
59011- depends on PROC_FS && CRASH_DUMP
59012- default y
59013+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
59014+ default n
59015 help
59016 Exports the dump image of crashed kernel in ELF format.
59017
59018@@ -59,8 +59,8 @@ config PROC_SYSCTL
59019 limited in memory.
59020
59021 config PROC_PAGE_MONITOR
59022- default y
59023- depends on PROC_FS && MMU
59024+ default n
59025+ depends on PROC_FS && MMU && !GRKERNSEC
59026 bool "Enable /proc page monitoring" if EXPERT
59027 help
59028 Various /proc files exist to monitor process memory utilization:
59029diff --git a/fs/proc/array.c b/fs/proc/array.c
59030index cbd0f1b..adec3f0 100644
59031--- a/fs/proc/array.c
59032+++ b/fs/proc/array.c
59033@@ -60,6 +60,7 @@
59034 #include <linux/tty.h>
59035 #include <linux/string.h>
59036 #include <linux/mman.h>
59037+#include <linux/grsecurity.h>
59038 #include <linux/proc_fs.h>
59039 #include <linux/ioport.h>
59040 #include <linux/uaccess.h>
59041@@ -363,6 +364,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
59042 seq_putc(m, '\n');
59043 }
59044
59045+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
59046+static inline void task_pax(struct seq_file *m, struct task_struct *p)
59047+{
59048+ if (p->mm)
59049+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
59050+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
59051+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
59052+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
59053+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
59054+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
59055+ else
59056+ seq_printf(m, "PaX:\t-----\n");
59057+}
59058+#endif
59059+
59060 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
59061 struct pid *pid, struct task_struct *task)
59062 {
59063@@ -381,9 +397,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
59064 task_cpus_allowed(m, task);
59065 cpuset_task_status_allowed(m, task);
59066 task_context_switch_counts(m, task);
59067+
59068+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
59069+ task_pax(m, task);
59070+#endif
59071+
59072+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
59073+ task_grsec_rbac(m, task);
59074+#endif
59075+
59076 return 0;
59077 }
59078
59079+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59080+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
59081+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
59082+ _mm->pax_flags & MF_PAX_SEGMEXEC))
59083+#endif
59084+
59085 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
59086 struct pid *pid, struct task_struct *task, int whole)
59087 {
59088@@ -405,6 +436,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
59089 char tcomm[sizeof(task->comm)];
59090 unsigned long flags;
59091
59092+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59093+ if (current->exec_id != m->exec_id) {
59094+ gr_log_badprocpid("stat");
59095+ return 0;
59096+ }
59097+#endif
59098+
59099 state = *get_task_state(task);
59100 vsize = eip = esp = 0;
59101 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
59102@@ -476,6 +514,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
59103 gtime = task_gtime(task);
59104 }
59105
59106+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59107+ if (PAX_RAND_FLAGS(mm)) {
59108+ eip = 0;
59109+ esp = 0;
59110+ wchan = 0;
59111+ }
59112+#endif
59113+#ifdef CONFIG_GRKERNSEC_HIDESYM
59114+ wchan = 0;
59115+ eip =0;
59116+ esp =0;
59117+#endif
59118+
59119 /* scale priority and nice values from timeslices to -20..20 */
59120 /* to make it look like a "normal" Unix priority/nice value */
59121 priority = task_prio(task);
59122@@ -512,9 +563,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
59123 seq_put_decimal_ull(m, ' ', vsize);
59124 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
59125 seq_put_decimal_ull(m, ' ', rsslim);
59126+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59127+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
59128+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
59129+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
59130+#else
59131 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
59132 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
59133 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
59134+#endif
59135 seq_put_decimal_ull(m, ' ', esp);
59136 seq_put_decimal_ull(m, ' ', eip);
59137 /* The signal information here is obsolete.
59138@@ -536,7 +593,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
59139 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
59140 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
59141
59142- if (mm && permitted) {
59143+ if (mm && permitted
59144+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59145+ && !PAX_RAND_FLAGS(mm)
59146+#endif
59147+ ) {
59148 seq_put_decimal_ull(m, ' ', mm->start_data);
59149 seq_put_decimal_ull(m, ' ', mm->end_data);
59150 seq_put_decimal_ull(m, ' ', mm->start_brk);
59151@@ -574,8 +635,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
59152 struct pid *pid, struct task_struct *task)
59153 {
59154 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
59155- struct mm_struct *mm = get_task_mm(task);
59156+ struct mm_struct *mm;
59157
59158+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59159+ if (current->exec_id != m->exec_id) {
59160+ gr_log_badprocpid("statm");
59161+ return 0;
59162+ }
59163+#endif
59164+ mm = get_task_mm(task);
59165 if (mm) {
59166 size = task_statm(mm, &shared, &text, &data, &resident);
59167 mmput(mm);
59168@@ -598,6 +666,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
59169 return 0;
59170 }
59171
59172+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
59173+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
59174+{
59175+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
59176+}
59177+#endif
59178+
59179 #ifdef CONFIG_CHECKPOINT_RESTORE
59180 static struct pid *
59181 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
59182diff --git a/fs/proc/base.c b/fs/proc/base.c
59183index 1485e38..8ad4236 100644
59184--- a/fs/proc/base.c
59185+++ b/fs/proc/base.c
59186@@ -113,6 +113,14 @@ struct pid_entry {
59187 union proc_op op;
59188 };
59189
59190+struct getdents_callback {
59191+ struct linux_dirent __user * current_dir;
59192+ struct linux_dirent __user * previous;
59193+ struct file * file;
59194+ int count;
59195+ int error;
59196+};
59197+
59198 #define NOD(NAME, MODE, IOP, FOP, OP) { \
59199 .name = (NAME), \
59200 .len = sizeof(NAME) - 1, \
59201@@ -210,6 +218,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
59202 if (!mm->arg_end)
59203 goto out_mm; /* Shh! No looking before we're done */
59204
59205+ if (gr_acl_handle_procpidmem(task))
59206+ goto out_mm;
59207+
59208 len = mm->arg_end - mm->arg_start;
59209
59210 if (len > PAGE_SIZE)
59211@@ -237,12 +248,28 @@ out:
59212 return res;
59213 }
59214
59215+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59216+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
59217+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
59218+ _mm->pax_flags & MF_PAX_SEGMEXEC))
59219+#endif
59220+
59221 static int proc_pid_auxv(struct task_struct *task, char *buffer)
59222 {
59223 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
59224 int res = PTR_ERR(mm);
59225 if (mm && !IS_ERR(mm)) {
59226 unsigned int nwords = 0;
59227+
59228+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59229+ /* allow if we're currently ptracing this task */
59230+ if (PAX_RAND_FLAGS(mm) &&
59231+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
59232+ mmput(mm);
59233+ return 0;
59234+ }
59235+#endif
59236+
59237 do {
59238 nwords += 2;
59239 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
59240@@ -256,7 +283,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
59241 }
59242
59243
59244-#ifdef CONFIG_KALLSYMS
59245+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59246 /*
59247 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
59248 * Returns the resolved symbol. If that fails, simply return the address.
59249@@ -295,7 +322,7 @@ static void unlock_trace(struct task_struct *task)
59250 mutex_unlock(&task->signal->cred_guard_mutex);
59251 }
59252
59253-#ifdef CONFIG_STACKTRACE
59254+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59255
59256 #define MAX_STACK_TRACE_DEPTH 64
59257
59258@@ -518,7 +545,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
59259 return count;
59260 }
59261
59262-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
59263+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
59264 static int proc_pid_syscall(struct task_struct *task, char *buffer)
59265 {
59266 long nr;
59267@@ -547,7 +574,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
59268 /************************************************************************/
59269
59270 /* permission checks */
59271-static int proc_fd_access_allowed(struct inode *inode)
59272+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
59273 {
59274 struct task_struct *task;
59275 int allowed = 0;
59276@@ -557,7 +584,10 @@ static int proc_fd_access_allowed(struct inode *inode)
59277 */
59278 task = get_proc_task(inode);
59279 if (task) {
59280- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
59281+ if (log)
59282+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
59283+ else
59284+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
59285 put_task_struct(task);
59286 }
59287 return allowed;
59288@@ -588,10 +618,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
59289 struct task_struct *task,
59290 int hide_pid_min)
59291 {
59292+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
59293+ return false;
59294+
59295+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59296+ rcu_read_lock();
59297+ {
59298+ const struct cred *tmpcred = current_cred();
59299+ const struct cred *cred = __task_cred(task);
59300+
59301+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
59302+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59303+ || in_group_p(grsec_proc_gid)
59304+#endif
59305+ ) {
59306+ rcu_read_unlock();
59307+ return true;
59308+ }
59309+ }
59310+ rcu_read_unlock();
59311+
59312+ if (!pid->hide_pid)
59313+ return false;
59314+#endif
59315+
59316 if (pid->hide_pid < hide_pid_min)
59317 return true;
59318 if (in_group_p(pid->pid_gid))
59319 return true;
59320+
59321 return ptrace_may_access(task, PTRACE_MODE_READ);
59322 }
59323
59324@@ -609,7 +664,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
59325 put_task_struct(task);
59326
59327 if (!has_perms) {
59328+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59329+ {
59330+#else
59331 if (pid->hide_pid == 2) {
59332+#endif
59333 /*
59334 * Let's make getdents(), stat(), and open()
59335 * consistent with each other. If a process
59336@@ -707,6 +766,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
59337 if (!task)
59338 return -ESRCH;
59339
59340+ if (gr_acl_handle_procpidmem(task)) {
59341+ put_task_struct(task);
59342+ return -EPERM;
59343+ }
59344+
59345 mm = mm_access(task, mode);
59346 put_task_struct(task);
59347
59348@@ -722,6 +786,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
59349
59350 file->private_data = mm;
59351
59352+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59353+ file->f_version = current->exec_id;
59354+#endif
59355+
59356 return 0;
59357 }
59358
59359@@ -743,6 +811,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
59360 ssize_t copied;
59361 char *page;
59362
59363+#ifdef CONFIG_GRKERNSEC
59364+ if (write)
59365+ return -EPERM;
59366+#endif
59367+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59368+ if (file->f_version != current->exec_id) {
59369+ gr_log_badprocpid("mem");
59370+ return 0;
59371+ }
59372+#endif
59373+
59374 if (!mm)
59375 return 0;
59376
59377@@ -755,7 +834,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
59378 goto free;
59379
59380 while (count > 0) {
59381- int this_len = min_t(int, count, PAGE_SIZE);
59382+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
59383
59384 if (write && copy_from_user(page, buf, this_len)) {
59385 copied = -EFAULT;
59386@@ -847,6 +926,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
59387 if (!mm)
59388 return 0;
59389
59390+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
59391+ if (file->f_version != current->exec_id) {
59392+ gr_log_badprocpid("environ");
59393+ return 0;
59394+ }
59395+#endif
59396+
59397 page = (char *)__get_free_page(GFP_TEMPORARY);
59398 if (!page)
59399 return -ENOMEM;
59400@@ -856,7 +942,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
59401 goto free;
59402 while (count > 0) {
59403 size_t this_len, max_len;
59404- int retval;
59405+ ssize_t retval;
59406
59407 if (src >= (mm->env_end - mm->env_start))
59408 break;
59409@@ -1461,7 +1547,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
59410 int error = -EACCES;
59411
59412 /* Are we allowed to snoop on the tasks file descriptors? */
59413- if (!proc_fd_access_allowed(inode))
59414+ if (!proc_fd_access_allowed(inode, 0))
59415 goto out;
59416
59417 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
59418@@ -1505,8 +1591,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
59419 struct path path;
59420
59421 /* Are we allowed to snoop on the tasks file descriptors? */
59422- if (!proc_fd_access_allowed(inode))
59423- goto out;
59424+ /* logging this is needed for learning on chromium to work properly,
59425+ but we don't want to flood the logs from 'ps' which does a readlink
59426+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
59427+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
59428+ */
59429+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
59430+ if (!proc_fd_access_allowed(inode,0))
59431+ goto out;
59432+ } else {
59433+ if (!proc_fd_access_allowed(inode,1))
59434+ goto out;
59435+ }
59436
59437 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
59438 if (error)
59439@@ -1556,7 +1652,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
59440 rcu_read_lock();
59441 cred = __task_cred(task);
59442 inode->i_uid = cred->euid;
59443+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59444+ inode->i_gid = grsec_proc_gid;
59445+#else
59446 inode->i_gid = cred->egid;
59447+#endif
59448 rcu_read_unlock();
59449 }
59450 security_task_to_inode(task, inode);
59451@@ -1592,10 +1692,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
59452 return -ENOENT;
59453 }
59454 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
59455+#ifdef CONFIG_GRKERNSEC_PROC_USER
59456+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
59457+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59458+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
59459+#endif
59460 task_dumpable(task)) {
59461 cred = __task_cred(task);
59462 stat->uid = cred->euid;
59463+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59464+ stat->gid = grsec_proc_gid;
59465+#else
59466 stat->gid = cred->egid;
59467+#endif
59468 }
59469 }
59470 rcu_read_unlock();
59471@@ -1633,11 +1742,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
59472
59473 if (task) {
59474 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
59475+#ifdef CONFIG_GRKERNSEC_PROC_USER
59476+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
59477+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59478+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
59479+#endif
59480 task_dumpable(task)) {
59481 rcu_read_lock();
59482 cred = __task_cred(task);
59483 inode->i_uid = cred->euid;
59484+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59485+ inode->i_gid = grsec_proc_gid;
59486+#else
59487 inode->i_gid = cred->egid;
59488+#endif
59489 rcu_read_unlock();
59490 } else {
59491 inode->i_uid = GLOBAL_ROOT_UID;
59492@@ -2166,6 +2284,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
59493 if (!task)
59494 goto out_no_task;
59495
59496+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
59497+ goto out;
59498+
59499 /*
59500 * Yes, it does not scale. And it should not. Don't add
59501 * new entries into /proc/<tgid>/ without very good reasons.
59502@@ -2196,6 +2317,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
59503 if (!task)
59504 return -ENOENT;
59505
59506+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
59507+ goto out;
59508+
59509 if (!dir_emit_dots(file, ctx))
59510 goto out;
59511
59512@@ -2585,7 +2709,7 @@ static const struct pid_entry tgid_base_stuff[] = {
59513 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
59514 #endif
59515 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
59516-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
59517+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
59518 INF("syscall", S_IRUGO, proc_pid_syscall),
59519 #endif
59520 INF("cmdline", S_IRUGO, proc_pid_cmdline),
59521@@ -2610,10 +2734,10 @@ static const struct pid_entry tgid_base_stuff[] = {
59522 #ifdef CONFIG_SECURITY
59523 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
59524 #endif
59525-#ifdef CONFIG_KALLSYMS
59526+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59527 INF("wchan", S_IRUGO, proc_pid_wchan),
59528 #endif
59529-#ifdef CONFIG_STACKTRACE
59530+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59531 ONE("stack", S_IRUGO, proc_pid_stack),
59532 #endif
59533 #ifdef CONFIG_SCHEDSTATS
59534@@ -2647,6 +2771,9 @@ static const struct pid_entry tgid_base_stuff[] = {
59535 #ifdef CONFIG_HARDWALL
59536 INF("hardwall", S_IRUGO, proc_pid_hardwall),
59537 #endif
59538+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
59539+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
59540+#endif
59541 #ifdef CONFIG_USER_NS
59542 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
59543 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
59544@@ -2777,7 +2904,14 @@ static int proc_pid_instantiate(struct inode *dir,
59545 if (!inode)
59546 goto out;
59547
59548+#ifdef CONFIG_GRKERNSEC_PROC_USER
59549+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
59550+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59551+ inode->i_gid = grsec_proc_gid;
59552+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
59553+#else
59554 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
59555+#endif
59556 inode->i_op = &proc_tgid_base_inode_operations;
59557 inode->i_fop = &proc_tgid_base_operations;
59558 inode->i_flags|=S_IMMUTABLE;
59559@@ -2815,7 +2949,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
59560 if (!task)
59561 goto out;
59562
59563+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
59564+ goto out_put_task;
59565+
59566 result = proc_pid_instantiate(dir, dentry, task, NULL);
59567+out_put_task:
59568 put_task_struct(task);
59569 out:
59570 return ERR_PTR(result);
59571@@ -2921,7 +3059,7 @@ static const struct pid_entry tid_base_stuff[] = {
59572 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
59573 #endif
59574 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
59575-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
59576+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
59577 INF("syscall", S_IRUGO, proc_pid_syscall),
59578 #endif
59579 INF("cmdline", S_IRUGO, proc_pid_cmdline),
59580@@ -2948,10 +3086,10 @@ static const struct pid_entry tid_base_stuff[] = {
59581 #ifdef CONFIG_SECURITY
59582 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
59583 #endif
59584-#ifdef CONFIG_KALLSYMS
59585+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59586 INF("wchan", S_IRUGO, proc_pid_wchan),
59587 #endif
59588-#ifdef CONFIG_STACKTRACE
59589+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
59590 ONE("stack", S_IRUGO, proc_pid_stack),
59591 #endif
59592 #ifdef CONFIG_SCHEDSTATS
59593diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
59594index 82676e3..5f8518a 100644
59595--- a/fs/proc/cmdline.c
59596+++ b/fs/proc/cmdline.c
59597@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
59598
59599 static int __init proc_cmdline_init(void)
59600 {
59601+#ifdef CONFIG_GRKERNSEC_PROC_ADD
59602+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
59603+#else
59604 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
59605+#endif
59606 return 0;
59607 }
59608 module_init(proc_cmdline_init);
59609diff --git a/fs/proc/devices.c b/fs/proc/devices.c
59610index b143471..bb105e5 100644
59611--- a/fs/proc/devices.c
59612+++ b/fs/proc/devices.c
59613@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
59614
59615 static int __init proc_devices_init(void)
59616 {
59617+#ifdef CONFIG_GRKERNSEC_PROC_ADD
59618+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
59619+#else
59620 proc_create("devices", 0, NULL, &proc_devinfo_operations);
59621+#endif
59622 return 0;
59623 }
59624 module_init(proc_devices_init);
59625diff --git a/fs/proc/fd.c b/fs/proc/fd.c
59626index 0ff80f9..a1d7500 100644
59627--- a/fs/proc/fd.c
59628+++ b/fs/proc/fd.c
59629@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
59630 if (!task)
59631 return -ENOENT;
59632
59633- files = get_files_struct(task);
59634+ if (!gr_acl_handle_procpidmem(task))
59635+ files = get_files_struct(task);
59636 put_task_struct(task);
59637
59638 if (files) {
59639@@ -283,11 +284,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
59640 */
59641 int proc_fd_permission(struct inode *inode, int mask)
59642 {
59643+ struct task_struct *task;
59644 int rv = generic_permission(inode, mask);
59645- if (rv == 0)
59646- return 0;
59647+
59648 if (task_pid(current) == proc_pid(inode))
59649 rv = 0;
59650+
59651+ task = get_proc_task(inode);
59652+ if (task == NULL)
59653+ return rv;
59654+
59655+ if (gr_acl_handle_procpidmem(task))
59656+ rv = -EACCES;
59657+
59658+ put_task_struct(task);
59659+
59660 return rv;
59661 }
59662
59663diff --git a/fs/proc/inode.c b/fs/proc/inode.c
59664index 073aea6..0630370 100644
59665--- a/fs/proc/inode.c
59666+++ b/fs/proc/inode.c
59667@@ -23,11 +23,17 @@
59668 #include <linux/slab.h>
59669 #include <linux/mount.h>
59670 #include <linux/magic.h>
59671+#include <linux/grsecurity.h>
59672
59673 #include <asm/uaccess.h>
59674
59675 #include "internal.h"
59676
59677+#ifdef CONFIG_PROC_SYSCTL
59678+extern const struct inode_operations proc_sys_inode_operations;
59679+extern const struct inode_operations proc_sys_dir_operations;
59680+#endif
59681+
59682 static void proc_evict_inode(struct inode *inode)
59683 {
59684 struct proc_dir_entry *de;
59685@@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
59686 ns = PROC_I(inode)->ns.ns;
59687 if (ns_ops && ns)
59688 ns_ops->put(ns);
59689+
59690+#ifdef CONFIG_PROC_SYSCTL
59691+ if (inode->i_op == &proc_sys_inode_operations ||
59692+ inode->i_op == &proc_sys_dir_operations)
59693+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
59694+#endif
59695+
59696 }
59697
59698 static struct kmem_cache * proc_inode_cachep;
59699@@ -385,7 +398,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
59700 if (de->mode) {
59701 inode->i_mode = de->mode;
59702 inode->i_uid = de->uid;
59703+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
59704+ inode->i_gid = grsec_proc_gid;
59705+#else
59706 inode->i_gid = de->gid;
59707+#endif
59708 }
59709 if (de->size)
59710 inode->i_size = de->size;
59711diff --git a/fs/proc/internal.h b/fs/proc/internal.h
59712index 651d09a..60c73ae 100644
59713--- a/fs/proc/internal.h
59714+++ b/fs/proc/internal.h
59715@@ -155,6 +155,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
59716 struct pid *, struct task_struct *);
59717 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
59718 struct pid *, struct task_struct *);
59719+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
59720+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
59721+#endif
59722
59723 /*
59724 * base.c
59725diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
59726index 06ea155..9a798c7 100644
59727--- a/fs/proc/kcore.c
59728+++ b/fs/proc/kcore.c
59729@@ -484,9 +484,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
59730 * the addresses in the elf_phdr on our list.
59731 */
59732 start = kc_offset_to_vaddr(*fpos - elf_buflen);
59733- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
59734+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
59735+ if (tsz > buflen)
59736 tsz = buflen;
59737-
59738+
59739 while (buflen) {
59740 struct kcore_list *m;
59741
59742@@ -515,20 +516,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
59743 kfree(elf_buf);
59744 } else {
59745 if (kern_addr_valid(start)) {
59746- unsigned long n;
59747+ char *elf_buf;
59748+ mm_segment_t oldfs;
59749
59750- n = copy_to_user(buffer, (char *)start, tsz);
59751- /*
59752- * We cannot distinguish between fault on source
59753- * and fault on destination. When this happens
59754- * we clear too and hope it will trigger the
59755- * EFAULT again.
59756- */
59757- if (n) {
59758- if (clear_user(buffer + tsz - n,
59759- n))
59760+ elf_buf = kmalloc(tsz, GFP_KERNEL);
59761+ if (!elf_buf)
59762+ return -ENOMEM;
59763+ oldfs = get_fs();
59764+ set_fs(KERNEL_DS);
59765+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
59766+ set_fs(oldfs);
59767+ if (copy_to_user(buffer, elf_buf, tsz)) {
59768+ kfree(elf_buf);
59769 return -EFAULT;
59770+ }
59771 }
59772+ set_fs(oldfs);
59773+ kfree(elf_buf);
59774 } else {
59775 if (clear_user(buffer, tsz))
59776 return -EFAULT;
59777@@ -548,6 +552,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
59778
59779 static int open_kcore(struct inode *inode, struct file *filp)
59780 {
59781+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
59782+ return -EPERM;
59783+#endif
59784 if (!capable(CAP_SYS_RAWIO))
59785 return -EPERM;
59786 if (kcore_need_update)
59787diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
59788index 5aa847a..f77c8d4 100644
59789--- a/fs/proc/meminfo.c
59790+++ b/fs/proc/meminfo.c
59791@@ -159,7 +159,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
59792 vmi.used >> 10,
59793 vmi.largest_chunk >> 10
59794 #ifdef CONFIG_MEMORY_FAILURE
59795- ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
59796+ ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
59797 #endif
59798 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
59799 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
59800diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
59801index ccfd99b..1b7e255 100644
59802--- a/fs/proc/nommu.c
59803+++ b/fs/proc/nommu.c
59804@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
59805 if (len < 1)
59806 len = 1;
59807 seq_printf(m, "%*c", len, ' ');
59808- seq_path(m, &file->f_path, "");
59809+ seq_path(m, &file->f_path, "\n\\");
59810 }
59811
59812 seq_putc(m, '\n');
59813diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
59814index 4677bb7..408e936 100644
59815--- a/fs/proc/proc_net.c
59816+++ b/fs/proc/proc_net.c
59817@@ -23,6 +23,7 @@
59818 #include <linux/nsproxy.h>
59819 #include <net/net_namespace.h>
59820 #include <linux/seq_file.h>
59821+#include <linux/grsecurity.h>
59822
59823 #include "internal.h"
59824
59825@@ -109,6 +110,17 @@ static struct net *get_proc_task_net(struct inode *dir)
59826 struct task_struct *task;
59827 struct nsproxy *ns;
59828 struct net *net = NULL;
59829+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59830+ const struct cred *cred = current_cred();
59831+#endif
59832+
59833+#ifdef CONFIG_GRKERNSEC_PROC_USER
59834+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
59835+ return net;
59836+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
59837+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
59838+ return net;
59839+#endif
59840
59841 rcu_read_lock();
59842 task = pid_task(proc_pid(dir), PIDTYPE_PID);
59843diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
59844index 7129046..f2779c6 100644
59845--- a/fs/proc/proc_sysctl.c
59846+++ b/fs/proc/proc_sysctl.c
59847@@ -13,11 +13,15 @@
59848 #include <linux/module.h>
59849 #include "internal.h"
59850
59851+extern int gr_handle_chroot_sysctl(const int op);
59852+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
59853+ const int op);
59854+
59855 static const struct dentry_operations proc_sys_dentry_operations;
59856 static const struct file_operations proc_sys_file_operations;
59857-static const struct inode_operations proc_sys_inode_operations;
59858+const struct inode_operations proc_sys_inode_operations;
59859 static const struct file_operations proc_sys_dir_file_operations;
59860-static const struct inode_operations proc_sys_dir_operations;
59861+const struct inode_operations proc_sys_dir_operations;
59862
59863 void proc_sys_poll_notify(struct ctl_table_poll *poll)
59864 {
59865@@ -467,6 +471,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
59866
59867 err = NULL;
59868 d_set_d_op(dentry, &proc_sys_dentry_operations);
59869+
59870+ gr_handle_proc_create(dentry, inode);
59871+
59872 d_add(dentry, inode);
59873
59874 out:
59875@@ -482,6 +489,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
59876 struct inode *inode = file_inode(filp);
59877 struct ctl_table_header *head = grab_header(inode);
59878 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
59879+ int op = write ? MAY_WRITE : MAY_READ;
59880 ssize_t error;
59881 size_t res;
59882
59883@@ -493,7 +501,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
59884 * and won't be until we finish.
59885 */
59886 error = -EPERM;
59887- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
59888+ if (sysctl_perm(head, table, op))
59889 goto out;
59890
59891 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
59892@@ -501,6 +509,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
59893 if (!table->proc_handler)
59894 goto out;
59895
59896+#ifdef CONFIG_GRKERNSEC
59897+ error = -EPERM;
59898+ if (gr_handle_chroot_sysctl(op))
59899+ goto out;
59900+ dget(filp->f_path.dentry);
59901+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
59902+ dput(filp->f_path.dentry);
59903+ goto out;
59904+ }
59905+ dput(filp->f_path.dentry);
59906+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
59907+ goto out;
59908+ if (write && !capable(CAP_SYS_ADMIN))
59909+ goto out;
59910+#endif
59911+
59912 /* careful: calling conventions are nasty here */
59913 res = count;
59914 error = table->proc_handler(table, write, buf, &res, ppos);
59915@@ -598,6 +622,9 @@ static bool proc_sys_fill_cache(struct file *file,
59916 return false;
59917 } else {
59918 d_set_d_op(child, &proc_sys_dentry_operations);
59919+
59920+ gr_handle_proc_create(child, inode);
59921+
59922 d_add(child, inode);
59923 }
59924 } else {
59925@@ -641,6 +668,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
59926 if ((*pos)++ < ctx->pos)
59927 return true;
59928
59929+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
59930+ return 0;
59931+
59932 if (unlikely(S_ISLNK(table->mode)))
59933 res = proc_sys_link_fill_cache(file, ctx, head, table);
59934 else
59935@@ -734,6 +764,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
59936 if (IS_ERR(head))
59937 return PTR_ERR(head);
59938
59939+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
59940+ return -ENOENT;
59941+
59942 generic_fillattr(inode, stat);
59943 if (table)
59944 stat->mode = (stat->mode & S_IFMT) | table->mode;
59945@@ -756,13 +789,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
59946 .llseek = generic_file_llseek,
59947 };
59948
59949-static const struct inode_operations proc_sys_inode_operations = {
59950+const struct inode_operations proc_sys_inode_operations = {
59951 .permission = proc_sys_permission,
59952 .setattr = proc_sys_setattr,
59953 .getattr = proc_sys_getattr,
59954 };
59955
59956-static const struct inode_operations proc_sys_dir_operations = {
59957+const struct inode_operations proc_sys_dir_operations = {
59958 .lookup = proc_sys_lookup,
59959 .permission = proc_sys_permission,
59960 .setattr = proc_sys_setattr,
59961@@ -839,7 +872,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
59962 static struct ctl_dir *new_dir(struct ctl_table_set *set,
59963 const char *name, int namelen)
59964 {
59965- struct ctl_table *table;
59966+ ctl_table_no_const *table;
59967 struct ctl_dir *new;
59968 struct ctl_node *node;
59969 char *new_name;
59970@@ -851,7 +884,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
59971 return NULL;
59972
59973 node = (struct ctl_node *)(new + 1);
59974- table = (struct ctl_table *)(node + 1);
59975+ table = (ctl_table_no_const *)(node + 1);
59976 new_name = (char *)(table + 2);
59977 memcpy(new_name, name, namelen);
59978 new_name[namelen] = '\0';
59979@@ -1020,7 +1053,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
59980 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
59981 struct ctl_table_root *link_root)
59982 {
59983- struct ctl_table *link_table, *entry, *link;
59984+ ctl_table_no_const *link_table, *link;
59985+ struct ctl_table *entry;
59986 struct ctl_table_header *links;
59987 struct ctl_node *node;
59988 char *link_name;
59989@@ -1043,7 +1077,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
59990 return NULL;
59991
59992 node = (struct ctl_node *)(links + 1);
59993- link_table = (struct ctl_table *)(node + nr_entries);
59994+ link_table = (ctl_table_no_const *)(node + nr_entries);
59995 link_name = (char *)&link_table[nr_entries + 1];
59996
59997 for (link = link_table, entry = table; entry->procname; link++, entry++) {
59998@@ -1291,8 +1325,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
59999 struct ctl_table_header ***subheader, struct ctl_table_set *set,
60000 struct ctl_table *table)
60001 {
60002- struct ctl_table *ctl_table_arg = NULL;
60003- struct ctl_table *entry, *files;
60004+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
60005+ struct ctl_table *entry;
60006 int nr_files = 0;
60007 int nr_dirs = 0;
60008 int err = -ENOMEM;
60009@@ -1304,10 +1338,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
60010 nr_files++;
60011 }
60012
60013- files = table;
60014 /* If there are mixed files and directories we need a new table */
60015 if (nr_dirs && nr_files) {
60016- struct ctl_table *new;
60017+ ctl_table_no_const *new;
60018 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
60019 GFP_KERNEL);
60020 if (!files)
60021@@ -1325,7 +1358,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
60022 /* Register everything except a directory full of subdirectories */
60023 if (nr_files || !nr_dirs) {
60024 struct ctl_table_header *header;
60025- header = __register_sysctl_table(set, path, files);
60026+ header = __register_sysctl_table(set, path, files ? files : table);
60027 if (!header) {
60028 kfree(ctl_table_arg);
60029 goto out;
60030diff --git a/fs/proc/root.c b/fs/proc/root.c
60031index e0a790d..21e095e 100644
60032--- a/fs/proc/root.c
60033+++ b/fs/proc/root.c
60034@@ -182,7 +182,15 @@ void __init proc_root_init(void)
60035 #ifdef CONFIG_PROC_DEVICETREE
60036 proc_device_tree_init();
60037 #endif
60038+#ifdef CONFIG_GRKERNSEC_PROC_ADD
60039+#ifdef CONFIG_GRKERNSEC_PROC_USER
60040+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
60041+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60042+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
60043+#endif
60044+#else
60045 proc_mkdir("bus", NULL);
60046+#endif
60047 proc_sys_init();
60048 }
60049
60050diff --git a/fs/proc/self.c b/fs/proc/self.c
60051index 6b6a993..807cccc 100644
60052--- a/fs/proc/self.c
60053+++ b/fs/proc/self.c
60054@@ -39,7 +39,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
60055 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
60056 void *cookie)
60057 {
60058- char *s = nd_get_link(nd);
60059+ const char *s = nd_get_link(nd);
60060 if (!IS_ERR(s))
60061 kfree(s);
60062 }
60063diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
60064index 107d026..c715aeb 100644
60065--- a/fs/proc/task_mmu.c
60066+++ b/fs/proc/task_mmu.c
60067@@ -12,12 +12,19 @@
60068 #include <linux/swap.h>
60069 #include <linux/swapops.h>
60070 #include <linux/mmu_notifier.h>
60071+#include <linux/grsecurity.h>
60072
60073 #include <asm/elf.h>
60074 #include <asm/uaccess.h>
60075 #include <asm/tlbflush.h>
60076 #include "internal.h"
60077
60078+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60079+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
60080+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
60081+ _mm->pax_flags & MF_PAX_SEGMEXEC))
60082+#endif
60083+
60084 void task_mem(struct seq_file *m, struct mm_struct *mm)
60085 {
60086 unsigned long data, text, lib, swap;
60087@@ -53,8 +60,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
60088 "VmExe:\t%8lu kB\n"
60089 "VmLib:\t%8lu kB\n"
60090 "VmPTE:\t%8lu kB\n"
60091- "VmSwap:\t%8lu kB\n",
60092- hiwater_vm << (PAGE_SHIFT-10),
60093+ "VmSwap:\t%8lu kB\n"
60094+
60095+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
60096+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
60097+#endif
60098+
60099+ ,hiwater_vm << (PAGE_SHIFT-10),
60100 total_vm << (PAGE_SHIFT-10),
60101 mm->locked_vm << (PAGE_SHIFT-10),
60102 mm->pinned_vm << (PAGE_SHIFT-10),
60103@@ -63,7 +75,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
60104 data << (PAGE_SHIFT-10),
60105 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
60106 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
60107- swap << (PAGE_SHIFT-10));
60108+ swap << (PAGE_SHIFT-10)
60109+
60110+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
60111+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60112+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
60113+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
60114+#else
60115+ , mm->context.user_cs_base
60116+ , mm->context.user_cs_limit
60117+#endif
60118+#endif
60119+
60120+ );
60121 }
60122
60123 unsigned long task_vsize(struct mm_struct *mm)
60124@@ -278,13 +302,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
60125 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
60126 }
60127
60128- /* We don't show the stack guard page in /proc/maps */
60129+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60130+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
60131+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
60132+#else
60133 start = vma->vm_start;
60134- if (stack_guard_page_start(vma, start))
60135- start += PAGE_SIZE;
60136 end = vma->vm_end;
60137- if (stack_guard_page_end(vma, end))
60138- end -= PAGE_SIZE;
60139+#endif
60140
60141 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
60142 start,
60143@@ -293,7 +317,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
60144 flags & VM_WRITE ? 'w' : '-',
60145 flags & VM_EXEC ? 'x' : '-',
60146 flags & VM_MAYSHARE ? 's' : 'p',
60147+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60148+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
60149+#else
60150 pgoff,
60151+#endif
60152 MAJOR(dev), MINOR(dev), ino, &len);
60153
60154 /*
60155@@ -302,7 +330,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
60156 */
60157 if (file) {
60158 pad_len_spaces(m, len);
60159- seq_path(m, &file->f_path, "\n");
60160+ seq_path(m, &file->f_path, "\n\\");
60161 goto done;
60162 }
60163
60164@@ -328,8 +356,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
60165 * Thread stack in /proc/PID/task/TID/maps or
60166 * the main process stack.
60167 */
60168- if (!is_pid || (vma->vm_start <= mm->start_stack &&
60169- vma->vm_end >= mm->start_stack)) {
60170+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
60171+ (vma->vm_start <= mm->start_stack &&
60172+ vma->vm_end >= mm->start_stack)) {
60173 name = "[stack]";
60174 } else {
60175 /* Thread stack in /proc/PID/maps */
60176@@ -353,6 +382,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
60177 struct proc_maps_private *priv = m->private;
60178 struct task_struct *task = priv->task;
60179
60180+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60181+ if (current->exec_id != m->exec_id) {
60182+ gr_log_badprocpid("maps");
60183+ return 0;
60184+ }
60185+#endif
60186+
60187 show_map_vma(m, vma, is_pid);
60188
60189 if (m->count < m->size) /* vma is copied successfully */
60190@@ -590,12 +626,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
60191 .private = &mss,
60192 };
60193
60194+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60195+ if (current->exec_id != m->exec_id) {
60196+ gr_log_badprocpid("smaps");
60197+ return 0;
60198+ }
60199+#endif
60200 memset(&mss, 0, sizeof mss);
60201- mss.vma = vma;
60202- /* mmap_sem is held in m_start */
60203- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
60204- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
60205-
60206+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60207+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
60208+#endif
60209+ mss.vma = vma;
60210+ /* mmap_sem is held in m_start */
60211+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
60212+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
60213+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60214+ }
60215+#endif
60216 show_map_vma(m, vma, is_pid);
60217
60218 seq_printf(m,
60219@@ -613,7 +660,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
60220 "KernelPageSize: %8lu kB\n"
60221 "MMUPageSize: %8lu kB\n"
60222 "Locked: %8lu kB\n",
60223+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60224+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
60225+#else
60226 (vma->vm_end - vma->vm_start) >> 10,
60227+#endif
60228 mss.resident >> 10,
60229 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
60230 mss.shared_clean >> 10,
60231@@ -1362,6 +1413,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
60232 int n;
60233 char buffer[50];
60234
60235+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60236+ if (current->exec_id != m->exec_id) {
60237+ gr_log_badprocpid("numa_maps");
60238+ return 0;
60239+ }
60240+#endif
60241+
60242 if (!mm)
60243 return 0;
60244
60245@@ -1379,11 +1437,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
60246 mpol_to_str(buffer, sizeof(buffer), pol);
60247 mpol_cond_put(pol);
60248
60249+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60250+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
60251+#else
60252 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
60253+#endif
60254
60255 if (file) {
60256 seq_printf(m, " file=");
60257- seq_path(m, &file->f_path, "\n\t= ");
60258+ seq_path(m, &file->f_path, "\n\t\\= ");
60259 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
60260 seq_printf(m, " heap");
60261 } else {
60262diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
60263index 56123a6..5a2f6ec 100644
60264--- a/fs/proc/task_nommu.c
60265+++ b/fs/proc/task_nommu.c
60266@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
60267 else
60268 bytes += kobjsize(mm);
60269
60270- if (current->fs && current->fs->users > 1)
60271+ if (current->fs && atomic_read(&current->fs->users) > 1)
60272 sbytes += kobjsize(current->fs);
60273 else
60274 bytes += kobjsize(current->fs);
60275@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
60276
60277 if (file) {
60278 pad_len_spaces(m, len);
60279- seq_path(m, &file->f_path, "");
60280+ seq_path(m, &file->f_path, "\n\\");
60281 } else if (mm) {
60282 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
60283
60284diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
60285index a1a16eb..6be46ed 100644
60286--- a/fs/proc/vmcore.c
60287+++ b/fs/proc/vmcore.c
60288@@ -104,9 +104,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
60289 nr_bytes = count;
60290
60291 /* If pfn is not ram, return zeros for sparse dump files */
60292- if (pfn_is_ram(pfn) == 0)
60293- memset(buf, 0, nr_bytes);
60294- else {
60295+ if (pfn_is_ram(pfn) == 0) {
60296+ if (userbuf) {
60297+ if (clear_user((char __force_user *)buf, nr_bytes))
60298+ return -EFAULT;
60299+ } else
60300+ memset(buf, 0, nr_bytes);
60301+ } else {
60302 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
60303 offset, userbuf);
60304 if (tmp < 0)
60305@@ -178,7 +182,7 @@ static ssize_t read_vmcore(struct file *file, char __user *buffer,
60306 if (*fpos < m->offset + m->size) {
60307 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
60308 start = m->paddr + *fpos - m->offset;
60309- tmp = read_from_oldmem(buffer, tsz, &start, 1);
60310+ tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, 1);
60311 if (tmp < 0)
60312 return tmp;
60313 buflen -= tsz;
60314diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
60315index b00fcc9..e0c6381 100644
60316--- a/fs/qnx6/qnx6.h
60317+++ b/fs/qnx6/qnx6.h
60318@@ -74,7 +74,7 @@ enum {
60319 BYTESEX_BE,
60320 };
60321
60322-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
60323+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
60324 {
60325 if (sbi->s_bytesex == BYTESEX_LE)
60326 return le64_to_cpu((__force __le64)n);
60327@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
60328 return (__force __fs64)cpu_to_be64(n);
60329 }
60330
60331-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
60332+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
60333 {
60334 if (sbi->s_bytesex == BYTESEX_LE)
60335 return le32_to_cpu((__force __le32)n);
60336diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
60337index 16e8abb..2dcf914 100644
60338--- a/fs/quota/netlink.c
60339+++ b/fs/quota/netlink.c
60340@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
60341 void quota_send_warning(struct kqid qid, dev_t dev,
60342 const char warntype)
60343 {
60344- static atomic_t seq;
60345+ static atomic_unchecked_t seq;
60346 struct sk_buff *skb;
60347 void *msg_head;
60348 int ret;
60349@@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
60350 "VFS: Not enough memory to send quota warning.\n");
60351 return;
60352 }
60353- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
60354+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
60355 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
60356 if (!msg_head) {
60357 printk(KERN_ERR
60358diff --git a/fs/read_write.c b/fs/read_write.c
60359index 122a384..0b7ecf2 100644
60360--- a/fs/read_write.c
60361+++ b/fs/read_write.c
60362@@ -440,7 +440,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
60363
60364 old_fs = get_fs();
60365 set_fs(get_ds());
60366- p = (__force const char __user *)buf;
60367+ p = (const char __force_user *)buf;
60368 if (count > MAX_RW_COUNT)
60369 count = MAX_RW_COUNT;
60370 if (file->f_op->write)
60371diff --git a/fs/readdir.c b/fs/readdir.c
60372index 93d71e5..6a14be8 100644
60373--- a/fs/readdir.c
60374+++ b/fs/readdir.c
60375@@ -17,6 +17,7 @@
60376 #include <linux/security.h>
60377 #include <linux/syscalls.h>
60378 #include <linux/unistd.h>
60379+#include <linux/namei.h>
60380
60381 #include <asm/uaccess.h>
60382
60383@@ -69,6 +70,7 @@ struct old_linux_dirent {
60384 struct readdir_callback {
60385 struct dir_context ctx;
60386 struct old_linux_dirent __user * dirent;
60387+ struct file * file;
60388 int result;
60389 };
60390
60391@@ -86,6 +88,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
60392 buf->result = -EOVERFLOW;
60393 return -EOVERFLOW;
60394 }
60395+
60396+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60397+ return 0;
60398+
60399 buf->result++;
60400 dirent = buf->dirent;
60401 if (!access_ok(VERIFY_WRITE, dirent,
60402@@ -117,6 +123,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
60403 if (!f.file)
60404 return -EBADF;
60405
60406+ buf.file = f.file;
60407 error = iterate_dir(f.file, &buf.ctx);
60408 if (buf.result)
60409 error = buf.result;
60410@@ -142,6 +149,7 @@ struct getdents_callback {
60411 struct dir_context ctx;
60412 struct linux_dirent __user * current_dir;
60413 struct linux_dirent __user * previous;
60414+ struct file * file;
60415 int count;
60416 int error;
60417 };
60418@@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
60419 buf->error = -EOVERFLOW;
60420 return -EOVERFLOW;
60421 }
60422+
60423+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60424+ return 0;
60425+
60426 dirent = buf->previous;
60427 if (dirent) {
60428 if (__put_user(offset, &dirent->d_off))
60429@@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
60430 if (!f.file)
60431 return -EBADF;
60432
60433+ buf.file = f.file;
60434 error = iterate_dir(f.file, &buf.ctx);
60435 if (error >= 0)
60436 error = buf.error;
60437@@ -226,6 +239,7 @@ struct getdents_callback64 {
60438 struct dir_context ctx;
60439 struct linux_dirent64 __user * current_dir;
60440 struct linux_dirent64 __user * previous;
60441+ struct file *file;
60442 int count;
60443 int error;
60444 };
60445@@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
60446 buf->error = -EINVAL; /* only used if we fail.. */
60447 if (reclen > buf->count)
60448 return -EINVAL;
60449+
60450+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60451+ return 0;
60452+
60453 dirent = buf->previous;
60454 if (dirent) {
60455 if (__put_user(offset, &dirent->d_off))
60456@@ -288,6 +306,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
60457 if (!f.file)
60458 return -EBADF;
60459
60460+ buf.file = f.file;
60461 error = iterate_dir(f.file, &buf.ctx);
60462 if (error >= 0)
60463 error = buf.error;
60464diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
60465index 2b7882b..1c5ef48 100644
60466--- a/fs/reiserfs/do_balan.c
60467+++ b/fs/reiserfs/do_balan.c
60468@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
60469 return;
60470 }
60471
60472- atomic_inc(&(fs_generation(tb->tb_sb)));
60473+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
60474 do_balance_starts(tb);
60475
60476 /* balance leaf returns 0 except if combining L R and S into
60477diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
60478index a958444..42b2323 100644
60479--- a/fs/reiserfs/procfs.c
60480+++ b/fs/reiserfs/procfs.c
60481@@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
60482 "SMALL_TAILS " : "NO_TAILS ",
60483 replay_only(sb) ? "REPLAY_ONLY " : "",
60484 convert_reiserfs(sb) ? "CONV " : "",
60485- atomic_read(&r->s_generation_counter),
60486+ atomic_read_unchecked(&r->s_generation_counter),
60487 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
60488 SF(s_do_balance), SF(s_unneeded_left_neighbor),
60489 SF(s_good_search_by_key_reada), SF(s_bmaps),
60490diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
60491index 3df5ce6..8c0f4b0 100644
60492--- a/fs/reiserfs/reiserfs.h
60493+++ b/fs/reiserfs/reiserfs.h
60494@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
60495 /* Comment? -Hans */
60496 wait_queue_head_t s_wait;
60497 /* To be obsoleted soon by per buffer seals.. -Hans */
60498- atomic_t s_generation_counter; // increased by one every time the
60499+ atomic_unchecked_t s_generation_counter; // increased by one every time the
60500 // tree gets re-balanced
60501 unsigned long s_properties; /* File system properties. Currently holds
60502 on-disk FS format */
60503@@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
60504 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
60505
60506 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
60507-#define get_generation(s) atomic_read (&fs_generation(s))
60508+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
60509 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
60510 #define __fs_changed(gen,s) (gen != get_generation (s))
60511 #define fs_changed(gen,s) \
60512diff --git a/fs/select.c b/fs/select.c
60513index 35d4adc7..d6c60db 100644
60514--- a/fs/select.c
60515+++ b/fs/select.c
60516@@ -20,6 +20,7 @@
60517 #include <linux/export.h>
60518 #include <linux/slab.h>
60519 #include <linux/poll.h>
60520+#include <linux/security.h>
60521 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
60522 #include <linux/file.h>
60523 #include <linux/fdtable.h>
60524@@ -881,6 +882,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
60525 struct poll_list *walk = head;
60526 unsigned long todo = nfds;
60527
60528+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
60529 if (nfds > rlimit(RLIMIT_NOFILE))
60530 return -EINVAL;
60531
60532diff --git a/fs/seq_file.c b/fs/seq_file.c
60533index 3135c25..d0395dd 100644
60534--- a/fs/seq_file.c
60535+++ b/fs/seq_file.c
60536@@ -10,6 +10,7 @@
60537 #include <linux/seq_file.h>
60538 #include <linux/slab.h>
60539 #include <linux/cred.h>
60540+#include <linux/sched.h>
60541
60542 #include <asm/uaccess.h>
60543 #include <asm/page.h>
60544@@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
60545 #ifdef CONFIG_USER_NS
60546 p->user_ns = file->f_cred->user_ns;
60547 #endif
60548+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
60549+ p->exec_id = current->exec_id;
60550+#endif
60551
60552 /*
60553 * Wrappers around seq_open(e.g. swaps_open) need to be
60554@@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
60555 return 0;
60556 }
60557 if (!m->buf) {
60558- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
60559+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
60560 if (!m->buf)
60561 return -ENOMEM;
60562 }
60563@@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
60564 Eoverflow:
60565 m->op->stop(m, p);
60566 kfree(m->buf);
60567- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
60568+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
60569 return !m->buf ? -ENOMEM : -EAGAIN;
60570 }
60571
60572@@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
60573
60574 /* grab buffer if we didn't have one */
60575 if (!m->buf) {
60576- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
60577+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
60578 if (!m->buf)
60579 goto Enomem;
60580 }
60581@@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
60582 goto Fill;
60583 m->op->stop(m, p);
60584 kfree(m->buf);
60585- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
60586+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
60587 if (!m->buf)
60588 goto Enomem;
60589 m->count = 0;
60590@@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
60591 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
60592 void *data)
60593 {
60594- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
60595+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
60596 int res = -ENOMEM;
60597
60598 if (op) {
60599diff --git a/fs/splice.c b/fs/splice.c
60600index 3b7ee65..87fc2e4 100644
60601--- a/fs/splice.c
60602+++ b/fs/splice.c
60603@@ -196,7 +196,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
60604 pipe_lock(pipe);
60605
60606 for (;;) {
60607- if (!pipe->readers) {
60608+ if (!atomic_read(&pipe->readers)) {
60609 send_sig(SIGPIPE, current, 0);
60610 if (!ret)
60611 ret = -EPIPE;
60612@@ -219,7 +219,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
60613 page_nr++;
60614 ret += buf->len;
60615
60616- if (pipe->files)
60617+ if (atomic_read(&pipe->files))
60618 do_wakeup = 1;
60619
60620 if (!--spd->nr_pages)
60621@@ -250,9 +250,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
60622 do_wakeup = 0;
60623 }
60624
60625- pipe->waiting_writers++;
60626+ atomic_inc(&pipe->waiting_writers);
60627 pipe_wait(pipe);
60628- pipe->waiting_writers--;
60629+ atomic_dec(&pipe->waiting_writers);
60630 }
60631
60632 pipe_unlock(pipe);
60633@@ -565,7 +565,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
60634 old_fs = get_fs();
60635 set_fs(get_ds());
60636 /* The cast to a user pointer is valid due to the set_fs() */
60637- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
60638+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
60639 set_fs(old_fs);
60640
60641 return res;
60642@@ -580,7 +580,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
60643 old_fs = get_fs();
60644 set_fs(get_ds());
60645 /* The cast to a user pointer is valid due to the set_fs() */
60646- res = vfs_write(file, (__force const char __user *)buf, count, &pos);
60647+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
60648 set_fs(old_fs);
60649
60650 return res;
60651@@ -633,7 +633,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
60652 goto err;
60653
60654 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
60655- vec[i].iov_base = (void __user *) page_address(page);
60656+ vec[i].iov_base = (void __force_user *) page_address(page);
60657 vec[i].iov_len = this_len;
60658 spd.pages[i] = page;
60659 spd.nr_pages++;
60660@@ -829,7 +829,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
60661 ops->release(pipe, buf);
60662 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
60663 pipe->nrbufs--;
60664- if (pipe->files)
60665+ if (atomic_read(&pipe->files))
60666 sd->need_wakeup = true;
60667 }
60668
60669@@ -854,10 +854,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
60670 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
60671 {
60672 while (!pipe->nrbufs) {
60673- if (!pipe->writers)
60674+ if (!atomic_read(&pipe->writers))
60675 return 0;
60676
60677- if (!pipe->waiting_writers && sd->num_spliced)
60678+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
60679 return 0;
60680
60681 if (sd->flags & SPLICE_F_NONBLOCK)
60682@@ -1179,7 +1179,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
60683 * out of the pipe right after the splice_to_pipe(). So set
60684 * PIPE_READERS appropriately.
60685 */
60686- pipe->readers = 1;
60687+ atomic_set(&pipe->readers, 1);
60688
60689 current->splice_pipe = pipe;
60690 }
60691@@ -1475,6 +1475,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
60692
60693 partial[buffers].offset = off;
60694 partial[buffers].len = plen;
60695+ partial[buffers].private = 0;
60696
60697 off = 0;
60698 len -= plen;
60699@@ -1777,9 +1778,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
60700 ret = -ERESTARTSYS;
60701 break;
60702 }
60703- if (!pipe->writers)
60704+ if (!atomic_read(&pipe->writers))
60705 break;
60706- if (!pipe->waiting_writers) {
60707+ if (!atomic_read(&pipe->waiting_writers)) {
60708 if (flags & SPLICE_F_NONBLOCK) {
60709 ret = -EAGAIN;
60710 break;
60711@@ -1811,7 +1812,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
60712 pipe_lock(pipe);
60713
60714 while (pipe->nrbufs >= pipe->buffers) {
60715- if (!pipe->readers) {
60716+ if (!atomic_read(&pipe->readers)) {
60717 send_sig(SIGPIPE, current, 0);
60718 ret = -EPIPE;
60719 break;
60720@@ -1824,9 +1825,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
60721 ret = -ERESTARTSYS;
60722 break;
60723 }
60724- pipe->waiting_writers++;
60725+ atomic_inc(&pipe->waiting_writers);
60726 pipe_wait(pipe);
60727- pipe->waiting_writers--;
60728+ atomic_dec(&pipe->waiting_writers);
60729 }
60730
60731 pipe_unlock(pipe);
60732@@ -1862,14 +1863,14 @@ retry:
60733 pipe_double_lock(ipipe, opipe);
60734
60735 do {
60736- if (!opipe->readers) {
60737+ if (!atomic_read(&opipe->readers)) {
60738 send_sig(SIGPIPE, current, 0);
60739 if (!ret)
60740 ret = -EPIPE;
60741 break;
60742 }
60743
60744- if (!ipipe->nrbufs && !ipipe->writers)
60745+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
60746 break;
60747
60748 /*
60749@@ -1966,7 +1967,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
60750 pipe_double_lock(ipipe, opipe);
60751
60752 do {
60753- if (!opipe->readers) {
60754+ if (!atomic_read(&opipe->readers)) {
60755 send_sig(SIGPIPE, current, 0);
60756 if (!ret)
60757 ret = -EPIPE;
60758@@ -2011,7 +2012,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
60759 * return EAGAIN if we have the potential of some data in the
60760 * future, otherwise just return 0
60761 */
60762- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
60763+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
60764 ret = -EAGAIN;
60765
60766 pipe_unlock(ipipe);
60767diff --git a/fs/stat.c b/fs/stat.c
60768index 04ce1ac..a13dd1e 100644
60769--- a/fs/stat.c
60770+++ b/fs/stat.c
60771@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
60772 stat->gid = inode->i_gid;
60773 stat->rdev = inode->i_rdev;
60774 stat->size = i_size_read(inode);
60775- stat->atime = inode->i_atime;
60776- stat->mtime = inode->i_mtime;
60777+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
60778+ stat->atime = inode->i_ctime;
60779+ stat->mtime = inode->i_ctime;
60780+ } else {
60781+ stat->atime = inode->i_atime;
60782+ stat->mtime = inode->i_mtime;
60783+ }
60784 stat->ctime = inode->i_ctime;
60785 stat->blksize = (1 << inode->i_blkbits);
60786 stat->blocks = inode->i_blocks;
60787@@ -46,8 +51,14 @@ int vfs_getattr(struct path *path, struct kstat *stat)
60788 if (retval)
60789 return retval;
60790
60791- if (inode->i_op->getattr)
60792- return inode->i_op->getattr(path->mnt, path->dentry, stat);
60793+ if (inode->i_op->getattr) {
60794+ retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
60795+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
60796+ stat->atime = stat->ctime;
60797+ stat->mtime = stat->ctime;
60798+ }
60799+ return retval;
60800+ }
60801
60802 generic_fillattr(inode, stat);
60803 return 0;
60804diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c
60805index 15c68f9..36a8b3e 100644
60806--- a/fs/sysfs/bin.c
60807+++ b/fs/sysfs/bin.c
60808@@ -235,13 +235,13 @@ static int bin_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
60809 return ret;
60810 }
60811
60812-static int bin_access(struct vm_area_struct *vma, unsigned long addr,
60813- void *buf, int len, int write)
60814+static ssize_t bin_access(struct vm_area_struct *vma, unsigned long addr,
60815+ void *buf, size_t len, int write)
60816 {
60817 struct file *file = vma->vm_file;
60818 struct bin_buffer *bb = file->private_data;
60819 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
60820- int ret;
60821+ ssize_t ret;
60822
60823 if (!bb->vm_ops)
60824 return -EINVAL;
60825diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
60826index e068e74..92edeb8 100644
60827--- a/fs/sysfs/dir.c
60828+++ b/fs/sysfs/dir.c
60829@@ -40,7 +40,7 @@ static DEFINE_IDA(sysfs_ino_ida);
60830 *
60831 * Returns 31 bit hash of ns + name (so it fits in an off_t )
60832 */
60833-static unsigned int sysfs_name_hash(const void *ns, const char *name)
60834+static unsigned int sysfs_name_hash(const void *ns, const unsigned char *name)
60835 {
60836 unsigned long hash = init_name_hash();
60837 unsigned int len = strlen(name);
60838@@ -679,6 +679,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
60839 struct sysfs_dirent *sd;
60840 int rc;
60841
60842+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
60843+ const char *parent_name = parent_sd->s_name;
60844+
60845+ mode = S_IFDIR | S_IRWXU;
60846+
60847+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
60848+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
60849+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
60850+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
60851+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
60852+#endif
60853+
60854 /* allocate */
60855 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
60856 if (!sd)
60857diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
60858index d2bb7ed..fe8c331 100644
60859--- a/fs/sysfs/file.c
60860+++ b/fs/sysfs/file.c
60861@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
60862
60863 struct sysfs_open_dirent {
60864 atomic_t refcnt;
60865- atomic_t event;
60866+ atomic_unchecked_t event;
60867 wait_queue_head_t poll;
60868 struct list_head buffers; /* goes through sysfs_buffer.list */
60869 };
60870@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
60871 if (!sysfs_get_active(attr_sd))
60872 return -ENODEV;
60873
60874- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
60875+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
60876 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
60877
60878 sysfs_put_active(attr_sd);
60879@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
60880 return -ENOMEM;
60881
60882 atomic_set(&new_od->refcnt, 0);
60883- atomic_set(&new_od->event, 1);
60884+ atomic_set_unchecked(&new_od->event, 1);
60885 init_waitqueue_head(&new_od->poll);
60886 INIT_LIST_HEAD(&new_od->buffers);
60887 goto retry;
60888@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
60889
60890 sysfs_put_active(attr_sd);
60891
60892- if (buffer->event != atomic_read(&od->event))
60893+ if (buffer->event != atomic_read_unchecked(&od->event))
60894 goto trigger;
60895
60896 return DEFAULT_POLLMASK;
60897@@ -452,7 +452,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
60898 if (!WARN_ON(sysfs_type(sd) != SYSFS_KOBJ_ATTR)) {
60899 od = sd->s_attr.open;
60900 if (od) {
60901- atomic_inc(&od->event);
60902+ atomic_inc_unchecked(&od->event);
60903 wake_up_interruptible(&od->poll);
60904 }
60905 }
60906diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
60907index 8c940df..25b733e 100644
60908--- a/fs/sysfs/symlink.c
60909+++ b/fs/sysfs/symlink.c
60910@@ -305,7 +305,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
60911
60912 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
60913 {
60914- char *page = nd_get_link(nd);
60915+ const char *page = nd_get_link(nd);
60916 if (!IS_ERR(page))
60917 free_page((unsigned long)page);
60918 }
60919diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
60920index 69d4889..a810bd4 100644
60921--- a/fs/sysv/sysv.h
60922+++ b/fs/sysv/sysv.h
60923@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
60924 #endif
60925 }
60926
60927-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
60928+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
60929 {
60930 if (sbi->s_bytesex == BYTESEX_PDP)
60931 return PDP_swab((__force __u32)n);
60932diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
60933index e18b988..f1d4ad0f 100644
60934--- a/fs/ubifs/io.c
60935+++ b/fs/ubifs/io.c
60936@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
60937 return err;
60938 }
60939
60940-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
60941+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
60942 {
60943 int err;
60944
60945diff --git a/fs/udf/misc.c b/fs/udf/misc.c
60946index c175b4d..8f36a16 100644
60947--- a/fs/udf/misc.c
60948+++ b/fs/udf/misc.c
60949@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
60950
60951 u8 udf_tag_checksum(const struct tag *t)
60952 {
60953- u8 *data = (u8 *)t;
60954+ const u8 *data = (const u8 *)t;
60955 u8 checksum = 0;
60956 int i;
60957 for (i = 0; i < sizeof(struct tag); ++i)
60958diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
60959index 8d974c4..b82f6ec 100644
60960--- a/fs/ufs/swab.h
60961+++ b/fs/ufs/swab.h
60962@@ -22,7 +22,7 @@ enum {
60963 BYTESEX_BE
60964 };
60965
60966-static inline u64
60967+static inline u64 __intentional_overflow(-1)
60968 fs64_to_cpu(struct super_block *sbp, __fs64 n)
60969 {
60970 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
60971@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
60972 return (__force __fs64)cpu_to_be64(n);
60973 }
60974
60975-static inline u32
60976+static inline u32 __intentional_overflow(-1)
60977 fs32_to_cpu(struct super_block *sbp, __fs32 n)
60978 {
60979 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
60980diff --git a/fs/utimes.c b/fs/utimes.c
60981index f4fb7ec..3fe03c0 100644
60982--- a/fs/utimes.c
60983+++ b/fs/utimes.c
60984@@ -1,6 +1,7 @@
60985 #include <linux/compiler.h>
60986 #include <linux/file.h>
60987 #include <linux/fs.h>
60988+#include <linux/security.h>
60989 #include <linux/linkage.h>
60990 #include <linux/mount.h>
60991 #include <linux/namei.h>
60992@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
60993 goto mnt_drop_write_and_out;
60994 }
60995 }
60996+
60997+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
60998+ error = -EACCES;
60999+ goto mnt_drop_write_and_out;
61000+ }
61001+
61002 mutex_lock(&inode->i_mutex);
61003 error = notify_change(path->dentry, &newattrs);
61004 mutex_unlock(&inode->i_mutex);
61005diff --git a/fs/xattr.c b/fs/xattr.c
61006index 3377dff..4d074d9 100644
61007--- a/fs/xattr.c
61008+++ b/fs/xattr.c
61009@@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
61010 return rc;
61011 }
61012
61013+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
61014+ssize_t
61015+pax_getxattr(struct dentry *dentry, void *value, size_t size)
61016+{
61017+ struct inode *inode = dentry->d_inode;
61018+ ssize_t error;
61019+
61020+ error = inode_permission(inode, MAY_EXEC);
61021+ if (error)
61022+ return error;
61023+
61024+ if (inode->i_op->getxattr)
61025+ error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
61026+ else
61027+ error = -EOPNOTSUPP;
61028+
61029+ return error;
61030+}
61031+EXPORT_SYMBOL(pax_getxattr);
61032+#endif
61033+
61034 ssize_t
61035 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
61036 {
61037@@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
61038 * Extended attribute SET operations
61039 */
61040 static long
61041-setxattr(struct dentry *d, const char __user *name, const void __user *value,
61042+setxattr(struct path *path, const char __user *name, const void __user *value,
61043 size_t size, int flags)
61044 {
61045 int error;
61046@@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
61047 posix_acl_fix_xattr_from_user(kvalue, size);
61048 }
61049
61050- error = vfs_setxattr(d, kname, kvalue, size, flags);
61051+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
61052+ error = -EACCES;
61053+ goto out;
61054+ }
61055+
61056+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
61057 out:
61058 if (vvalue)
61059 vfree(vvalue);
61060@@ -377,7 +403,7 @@ retry:
61061 return error;
61062 error = mnt_want_write(path.mnt);
61063 if (!error) {
61064- error = setxattr(path.dentry, name, value, size, flags);
61065+ error = setxattr(&path, name, value, size, flags);
61066 mnt_drop_write(path.mnt);
61067 }
61068 path_put(&path);
61069@@ -401,7 +427,7 @@ retry:
61070 return error;
61071 error = mnt_want_write(path.mnt);
61072 if (!error) {
61073- error = setxattr(path.dentry, name, value, size, flags);
61074+ error = setxattr(&path, name, value, size, flags);
61075 mnt_drop_write(path.mnt);
61076 }
61077 path_put(&path);
61078@@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
61079 const void __user *,value, size_t, size, int, flags)
61080 {
61081 struct fd f = fdget(fd);
61082- struct dentry *dentry;
61083 int error = -EBADF;
61084
61085 if (!f.file)
61086 return error;
61087- dentry = f.file->f_path.dentry;
61088- audit_inode(NULL, dentry, 0);
61089+ audit_inode(NULL, f.file->f_path.dentry, 0);
61090 error = mnt_want_write_file(f.file);
61091 if (!error) {
61092- error = setxattr(dentry, name, value, size, flags);
61093+ error = setxattr(&f.file->f_path, name, value, size, flags);
61094 mnt_drop_write_file(f.file);
61095 }
61096 fdput(f);
61097diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
61098index 9fbea87..6b19972 100644
61099--- a/fs/xattr_acl.c
61100+++ b/fs/xattr_acl.c
61101@@ -76,8 +76,8 @@ struct posix_acl *
61102 posix_acl_from_xattr(struct user_namespace *user_ns,
61103 const void *value, size_t size)
61104 {
61105- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
61106- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
61107+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
61108+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
61109 int count;
61110 struct posix_acl *acl;
61111 struct posix_acl_entry *acl_e;
61112diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
61113index 05c698c..6b918af 100644
61114--- a/fs/xfs/xfs_bmap.c
61115+++ b/fs/xfs/xfs_bmap.c
61116@@ -765,7 +765,7 @@ xfs_bmap_validate_ret(
61117
61118 #else
61119 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
61120-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
61121+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
61122 #endif /* DEBUG */
61123
61124 /*
61125diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
61126index 97676a3..399a75d 100644
61127--- a/fs/xfs/xfs_dir2_sf.c
61128+++ b/fs/xfs/xfs_dir2_sf.c
61129@@ -848,7 +848,12 @@ xfs_dir2_sf_getdents(
61130
61131 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
61132 ctx->pos = off & 0x7fffffff;
61133- if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen,
61134+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
61135+ char name[sfep->namelen];
61136+ memcpy(name, sfep->name, sfep->namelen);
61137+ if (!dir_emit(ctx, name, sfep->namelen, ino, DT_UNKNOWN))
61138+ return 0;
61139+ } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen,
61140 ino, DT_UNKNOWN))
61141 return 0;
61142 sfep = xfs_dir2_sf_nextentry(sfp, sfep);
61143diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
61144index 6e2bca5..6ce80d3 100644
61145--- a/fs/xfs/xfs_ioctl.c
61146+++ b/fs/xfs/xfs_ioctl.c
61147@@ -127,7 +127,7 @@ xfs_find_handle(
61148 }
61149
61150 error = -EFAULT;
61151- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
61152+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
61153 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
61154 goto out_put;
61155
61156diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
61157index 96dda62..d6c6a52 100644
61158--- a/fs/xfs/xfs_iops.c
61159+++ b/fs/xfs/xfs_iops.c
61160@@ -395,7 +395,7 @@ xfs_vn_put_link(
61161 struct nameidata *nd,
61162 void *p)
61163 {
61164- char *s = nd_get_link(nd);
61165+ const char *s = nd_get_link(nd);
61166
61167 if (!IS_ERR(s))
61168 kfree(s);
61169diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
61170new file mode 100644
61171index 0000000..0fd7c82
61172--- /dev/null
61173+++ b/grsecurity/Kconfig
61174@@ -0,0 +1,1080 @@
61175+#
61176+# grecurity configuration
61177+#
61178+menu "Memory Protections"
61179+depends on GRKERNSEC
61180+
61181+config GRKERNSEC_KMEM
61182+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
61183+ default y if GRKERNSEC_CONFIG_AUTO
61184+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
61185+ help
61186+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
61187+ be written to or read from to modify or leak the contents of the running
61188+ kernel. /dev/port will also not be allowed to be opened and support
61189+ for /dev/cpu/*/msr will be removed. If you have module
61190+ support disabled, enabling this will close up five ways that are
61191+ currently used to insert malicious code into the running kernel.
61192+
61193+ Even with all these features enabled, we still highly recommend that
61194+ you use the RBAC system, as it is still possible for an attacker to
61195+ modify the running kernel through privileged I/O granted by ioperm/iopl.
61196+
61197+ If you are not using XFree86, you may be able to stop this additional
61198+ case by enabling the 'Disable privileged I/O' option. Though nothing
61199+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
61200+ but only to video memory, which is the only writing we allow in this
61201+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
61202+ not be allowed to mprotect it with PROT_WRITE later.
61203+ Enabling this feature will prevent the "cpupower" and "powertop" tools
61204+ from working.
61205+
61206+ It is highly recommended that you say Y here if you meet all the
61207+ conditions above.
61208+
61209+config GRKERNSEC_VM86
61210+ bool "Restrict VM86 mode"
61211+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
61212+ depends on X86_32
61213+
61214+ help
61215+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
61216+ make use of a special execution mode on 32bit x86 processors called
61217+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
61218+ video cards and will still work with this option enabled. The purpose
61219+ of the option is to prevent exploitation of emulation errors in
61220+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
61221+ Nearly all users should be able to enable this option.
61222+
61223+config GRKERNSEC_IO
61224+ bool "Disable privileged I/O"
61225+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
61226+ depends on X86
61227+ select RTC_CLASS
61228+ select RTC_INTF_DEV
61229+ select RTC_DRV_CMOS
61230+
61231+ help
61232+ If you say Y here, all ioperm and iopl calls will return an error.
61233+ Ioperm and iopl can be used to modify the running kernel.
61234+ Unfortunately, some programs need this access to operate properly,
61235+ the most notable of which are XFree86 and hwclock. hwclock can be
61236+ remedied by having RTC support in the kernel, so real-time
61237+ clock support is enabled if this option is enabled, to ensure
61238+ that hwclock operates correctly. XFree86 still will not
61239+ operate correctly with this option enabled, so DO NOT CHOOSE Y
61240+ IF YOU USE XFree86. If you use XFree86 and you still want to
61241+ protect your kernel against modification, use the RBAC system.
61242+
61243+config GRKERNSEC_JIT_HARDEN
61244+ bool "Harden BPF JIT against spray attacks"
61245+ default y if GRKERNSEC_CONFIG_AUTO
61246+ depends on BPF_JIT
61247+ help
61248+ If you say Y here, the native code generated by the kernel's Berkeley
61249+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
61250+ attacks that attempt to fit attacker-beneficial instructions in
61251+ 32bit immediate fields of JIT-generated native instructions. The
61252+ attacker will generally aim to cause an unintended instruction sequence
61253+ of JIT-generated native code to execute by jumping into the middle of
61254+ a generated instruction. This feature effectively randomizes the 32bit
61255+ immediate constants present in the generated code to thwart such attacks.
61256+
61257+ If you're using KERNEXEC, it's recommended that you enable this option
61258+ to supplement the hardening of the kernel.
61259+
61260+config GRKERNSEC_PERF_HARDEN
61261+ bool "Disable unprivileged PERF_EVENTS usage by default"
61262+ default y if GRKERNSEC_CONFIG_AUTO
61263+ depends on PERF_EVENTS
61264+ help
61265+ If you say Y here, the range of acceptable values for the
61266+ /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
61267+ default to a new value: 3. When the sysctl is set to this value, no
61268+ unprivileged use of the PERF_EVENTS syscall interface will be permitted.
61269+
61270+ Though PERF_EVENTS can be used legitimately for performance monitoring
61271+ and low-level application profiling, it is forced on regardless of
61272+ configuration, has been at fault for several vulnerabilities, and
61273+ creates new opportunities for side channels and other information leaks.
61274+
61275+ This feature puts PERF_EVENTS into a secure default state and permits
61276+ the administrator to change out of it temporarily if unprivileged
61277+ application profiling is needed.
61278+
61279+config GRKERNSEC_RAND_THREADSTACK
61280+ bool "Insert random gaps between thread stacks"
61281+ default y if GRKERNSEC_CONFIG_AUTO
61282+ depends on PAX_RANDMMAP && !PPC
61283+ help
61284+ If you say Y here, a random-sized gap will be enforced between allocated
61285+ thread stacks. Glibc's NPTL and other threading libraries that
61286+ pass MAP_STACK to the kernel for thread stack allocation are supported.
61287+ The implementation currently provides 8 bits of entropy for the gap.
61288+
61289+ Many distributions do not compile threaded remote services with the
61290+ -fstack-check argument to GCC, causing the variable-sized stack-based
61291+ allocator, alloca(), to not probe the stack on allocation. This
61292+ permits an unbounded alloca() to skip over any guard page and potentially
61293+ modify another thread's stack reliably. An enforced random gap
61294+ reduces the reliability of such an attack and increases the chance
61295+ that such a read/write to another thread's stack instead lands in
61296+ an unmapped area, causing a crash and triggering grsecurity's
61297+ anti-bruteforcing logic.
61298+
61299+config GRKERNSEC_PROC_MEMMAP
61300+ bool "Harden ASLR against information leaks and entropy reduction"
61301+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
61302+ depends on PAX_NOEXEC || PAX_ASLR
61303+ help
61304+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
61305+ give no information about the addresses of its mappings if
61306+ PaX features that rely on random addresses are enabled on the task.
61307+ In addition to sanitizing this information and disabling other
61308+ dangerous sources of information, this option causes reads of sensitive
61309+ /proc/<pid> entries where the file descriptor was opened in a different
61310+ task than the one performing the read. Such attempts are logged.
61311+ This option also limits argv/env strings for suid/sgid binaries
61312+ to 512KB to prevent a complete exhaustion of the stack entropy provided
61313+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
61314+ binaries to prevent alternative mmap layouts from being abused.
61315+
61316+ If you use PaX it is essential that you say Y here as it closes up
61317+ several holes that make full ASLR useless locally.
61318+
61319+config GRKERNSEC_BRUTE
61320+ bool "Deter exploit bruteforcing"
61321+ default y if GRKERNSEC_CONFIG_AUTO
61322+ help
61323+ If you say Y here, attempts to bruteforce exploits against forking
61324+ daemons such as apache or sshd, as well as against suid/sgid binaries
61325+ will be deterred. When a child of a forking daemon is killed by PaX
61326+ or crashes due to an illegal instruction or other suspicious signal,
61327+ the parent process will be delayed 30 seconds upon every subsequent
61328+ fork until the administrator is able to assess the situation and
61329+ restart the daemon.
61330+ In the suid/sgid case, the attempt is logged, the user has all their
61331+ existing instances of the suid/sgid binary terminated and will
61332+ be unable to execute any suid/sgid binaries for 15 minutes.
61333+
61334+ It is recommended that you also enable signal logging in the auditing
61335+ section so that logs are generated when a process triggers a suspicious
61336+ signal.
61337+ If the sysctl option is enabled, a sysctl option with name
61338+ "deter_bruteforce" is created.
61339+
61340+
61341+config GRKERNSEC_MODHARDEN
61342+ bool "Harden module auto-loading"
61343+ default y if GRKERNSEC_CONFIG_AUTO
61344+ depends on MODULES
61345+ help
61346+ If you say Y here, module auto-loading in response to use of some
61347+ feature implemented by an unloaded module will be restricted to
61348+ root users. Enabling this option helps defend against attacks
61349+ by unprivileged users who abuse the auto-loading behavior to
61350+ cause a vulnerable module to load that is then exploited.
61351+
61352+ If this option prevents a legitimate use of auto-loading for a
61353+ non-root user, the administrator can execute modprobe manually
61354+ with the exact name of the module mentioned in the alert log.
61355+ Alternatively, the administrator can add the module to the list
61356+ of modules loaded at boot by modifying init scripts.
61357+
61358+ Modification of init scripts will most likely be needed on
61359+ Ubuntu servers with encrypted home directory support enabled,
61360+ as the first non-root user logging in will cause the ecb(aes),
61361+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
61362+
61363+config GRKERNSEC_HIDESYM
61364+ bool "Hide kernel symbols"
61365+ default y if GRKERNSEC_CONFIG_AUTO
61366+ select PAX_USERCOPY_SLABS
61367+ help
61368+ If you say Y here, getting information on loaded modules, and
61369+ displaying all kernel symbols through a syscall will be restricted
61370+ to users with CAP_SYS_MODULE. For software compatibility reasons,
61371+ /proc/kallsyms will be restricted to the root user. The RBAC
61372+ system can hide that entry even from root.
61373+
61374+ This option also prevents leaking of kernel addresses through
61375+ several /proc entries.
61376+
61377+ Note that this option is only effective provided the following
61378+ conditions are met:
61379+ 1) The kernel using grsecurity is not precompiled by some distribution
61380+ 2) You have also enabled GRKERNSEC_DMESG
61381+ 3) You are using the RBAC system and hiding other files such as your
61382+ kernel image and System.map. Alternatively, enabling this option
61383+ causes the permissions on /boot, /lib/modules, and the kernel
61384+ source directory to change at compile time to prevent
61385+ reading by non-root users.
61386+ If the above conditions are met, this option will aid in providing a
61387+ useful protection against local kernel exploitation of overflows
61388+ and arbitrary read/write vulnerabilities.
61389+
61390+ It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
61391+ in addition to this feature.
61392+
61393+config GRKERNSEC_KERN_LOCKOUT
61394+ bool "Active kernel exploit response"
61395+ default y if GRKERNSEC_CONFIG_AUTO
61396+ depends on X86 || ARM || PPC || SPARC
61397+ help
61398+ If you say Y here, when a PaX alert is triggered due to suspicious
61399+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
61400+ or an OOPS occurs due to bad memory accesses, instead of just
61401+ terminating the offending process (and potentially allowing
61402+ a subsequent exploit from the same user), we will take one of two
61403+ actions:
61404+ If the user was root, we will panic the system
61405+ If the user was non-root, we will log the attempt, terminate
61406+ all processes owned by the user, then prevent them from creating
61407+ any new processes until the system is restarted
61408+ This deters repeated kernel exploitation/bruteforcing attempts
61409+ and is useful for later forensics.
61410+
61411+endmenu
61412+menu "Role Based Access Control Options"
61413+depends on GRKERNSEC
61414+
61415+config GRKERNSEC_RBAC_DEBUG
61416+ bool
61417+
61418+config GRKERNSEC_NO_RBAC
61419+ bool "Disable RBAC system"
61420+ help
61421+ If you say Y here, the /dev/grsec device will be removed from the kernel,
61422+ preventing the RBAC system from being enabled. You should only say Y
61423+ here if you have no intention of using the RBAC system, so as to prevent
61424+ an attacker with root access from misusing the RBAC system to hide files
61425+ and processes when loadable module support and /dev/[k]mem have been
61426+ locked down.
61427+
61428+config GRKERNSEC_ACL_HIDEKERN
61429+ bool "Hide kernel processes"
61430+ help
61431+ If you say Y here, all kernel threads will be hidden to all
61432+ processes but those whose subject has the "view hidden processes"
61433+ flag.
61434+
61435+config GRKERNSEC_ACL_MAXTRIES
61436+ int "Maximum tries before password lockout"
61437+ default 3
61438+ help
61439+ This option enforces the maximum number of times a user can attempt
61440+ to authorize themselves with the grsecurity RBAC system before being
61441+ denied the ability to attempt authorization again for a specified time.
61442+ The lower the number, the harder it will be to brute-force a password.
61443+
61444+config GRKERNSEC_ACL_TIMEOUT
61445+ int "Time to wait after max password tries, in seconds"
61446+ default 30
61447+ help
61448+ This option specifies the time the user must wait after attempting to
61449+ authorize to the RBAC system with the maximum number of invalid
61450+ passwords. The higher the number, the harder it will be to brute-force
61451+ a password.
61452+
61453+endmenu
61454+menu "Filesystem Protections"
61455+depends on GRKERNSEC
61456+
61457+config GRKERNSEC_PROC
61458+ bool "Proc restrictions"
61459+ default y if GRKERNSEC_CONFIG_AUTO
61460+ help
61461+ If you say Y here, the permissions of the /proc filesystem
61462+ will be altered to enhance system security and privacy. You MUST
61463+ choose either a user only restriction or a user and group restriction.
61464+ Depending upon the option you choose, you can either restrict users to
61465+ see only the processes they themselves run, or choose a group that can
61466+ view all processes and files normally restricted to root if you choose
61467+ the "restrict to user only" option. NOTE: If you're running identd or
61468+ ntpd as a non-root user, you will have to run it as the group you
61469+ specify here.
61470+
61471+config GRKERNSEC_PROC_USER
61472+ bool "Restrict /proc to user only"
61473+ depends on GRKERNSEC_PROC
61474+ help
61475+ If you say Y here, non-root users will only be able to view their own
61476+ processes, and restricts them from viewing network-related information,
61477+ and viewing kernel symbol and module information.
61478+
61479+config GRKERNSEC_PROC_USERGROUP
61480+ bool "Allow special group"
61481+ default y if GRKERNSEC_CONFIG_AUTO
61482+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
61483+ help
61484+ If you say Y here, you will be able to select a group that will be
61485+ able to view all processes and network-related information. If you've
61486+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
61487+ remain hidden. This option is useful if you want to run identd as
61488+ a non-root user. The group you select may also be chosen at boot time
61489+ via "grsec_proc_gid=" on the kernel commandline.
61490+
61491+config GRKERNSEC_PROC_GID
61492+ int "GID for special group"
61493+ depends on GRKERNSEC_PROC_USERGROUP
61494+ default 1001
61495+
61496+config GRKERNSEC_PROC_ADD
61497+ bool "Additional restrictions"
61498+ default y if GRKERNSEC_CONFIG_AUTO
61499+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
61500+ help
61501+ If you say Y here, additional restrictions will be placed on
61502+ /proc that keep normal users from viewing device information and
61503+ slabinfo information that could be useful for exploits.
61504+
61505+config GRKERNSEC_LINK
61506+ bool "Linking restrictions"
61507+ default y if GRKERNSEC_CONFIG_AUTO
61508+ help
61509+ If you say Y here, /tmp race exploits will be prevented, since users
61510+ will no longer be able to follow symlinks owned by other users in
61511+ world-writable +t directories (e.g. /tmp), unless the owner of the
61512+ symlink is the owner of the directory. users will also not be
61513+ able to hardlink to files they do not own. If the sysctl option is
61514+ enabled, a sysctl option with name "linking_restrictions" is created.
61515+
61516+config GRKERNSEC_SYMLINKOWN
61517+ bool "Kernel-enforced SymlinksIfOwnerMatch"
61518+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
61519+ help
61520+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
61521+ that prevents it from being used as a security feature. As Apache
61522+ verifies the symlink by performing a stat() against the target of
61523+ the symlink before it is followed, an attacker can setup a symlink
61524+ to point to a same-owned file, then replace the symlink with one
61525+ that targets another user's file just after Apache "validates" the
61526+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
61527+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
61528+ will be in place for the group you specify. If the sysctl option
61529+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
61530+ created.
61531+
61532+config GRKERNSEC_SYMLINKOWN_GID
61533+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
61534+ depends on GRKERNSEC_SYMLINKOWN
61535+ default 1006
61536+ help
61537+ Setting this GID determines what group kernel-enforced
61538+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
61539+ is enabled, a sysctl option with name "symlinkown_gid" is created.
61540+
61541+config GRKERNSEC_FIFO
61542+ bool "FIFO restrictions"
61543+ default y if GRKERNSEC_CONFIG_AUTO
61544+ help
61545+ If you say Y here, users will not be able to write to FIFOs they don't
61546+ own in world-writable +t directories (e.g. /tmp), unless the owner of
61547+ the FIFO is the same owner of the directory it's held in. If the sysctl
61548+ option is enabled, a sysctl option with name "fifo_restrictions" is
61549+ created.
61550+
61551+config GRKERNSEC_SYSFS_RESTRICT
61552+ bool "Sysfs/debugfs restriction"
61553+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
61554+ depends on SYSFS
61555+ help
61556+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
61557+ any filesystem normally mounted under it (e.g. debugfs) will be
61558+ mostly accessible only by root. These filesystems generally provide access
61559+ to hardware and debug information that isn't appropriate for unprivileged
61560+ users of the system. Sysfs and debugfs have also become a large source
61561+ of new vulnerabilities, ranging from infoleaks to local compromise.
61562+ There has been very little oversight with an eye toward security involved
61563+ in adding new exporters of information to these filesystems, so their
61564+ use is discouraged.
61565+ For reasons of compatibility, a few directories have been whitelisted
61566+ for access by non-root users:
61567+ /sys/fs/selinux
61568+ /sys/fs/fuse
61569+ /sys/devices/system/cpu
61570+
61571+config GRKERNSEC_ROFS
61572+ bool "Runtime read-only mount protection"
61573+ depends on SYSCTL
61574+ help
61575+ If you say Y here, a sysctl option with name "romount_protect" will
61576+ be created. By setting this option to 1 at runtime, filesystems
61577+ will be protected in the following ways:
61578+ * No new writable mounts will be allowed
61579+ * Existing read-only mounts won't be able to be remounted read/write
61580+ * Write operations will be denied on all block devices
61581+ This option acts independently of grsec_lock: once it is set to 1,
61582+ it cannot be turned off. Therefore, please be mindful of the resulting
61583+ behavior if this option is enabled in an init script on a read-only
61584+ filesystem. This feature is mainly intended for secure embedded systems.
61585+
61586+config GRKERNSEC_DEVICE_SIDECHANNEL
61587+ bool "Eliminate stat/notify-based device sidechannels"
61588+ default y if GRKERNSEC_CONFIG_AUTO
61589+ help
61590+ If you say Y here, timing analyses on block or character
61591+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
61592+ will be thwarted for unprivileged users. If a process without
61593+ CAP_MKNOD stats such a device, the last access and last modify times
61594+ will match the device's create time. No access or modify events
61595+ will be triggered through inotify/dnotify/fanotify for such devices.
61596+ This feature will prevent attacks that may at a minimum
61597+ allow an attacker to determine the administrator's password length.
61598+
61599+config GRKERNSEC_CHROOT
61600+ bool "Chroot jail restrictions"
61601+ default y if GRKERNSEC_CONFIG_AUTO
61602+ help
61603+ If you say Y here, you will be able to choose several options that will
61604+ make breaking out of a chrooted jail much more difficult. If you
61605+ encounter no software incompatibilities with the following options, it
61606+ is recommended that you enable each one.
61607+
61608+config GRKERNSEC_CHROOT_MOUNT
61609+ bool "Deny mounts"
61610+ default y if GRKERNSEC_CONFIG_AUTO
61611+ depends on GRKERNSEC_CHROOT
61612+ help
61613+ If you say Y here, processes inside a chroot will not be able to
61614+ mount or remount filesystems. If the sysctl option is enabled, a
61615+ sysctl option with name "chroot_deny_mount" is created.
61616+
61617+config GRKERNSEC_CHROOT_DOUBLE
61618+ bool "Deny double-chroots"
61619+ default y if GRKERNSEC_CONFIG_AUTO
61620+ depends on GRKERNSEC_CHROOT
61621+ help
61622+ If you say Y here, processes inside a chroot will not be able to chroot
61623+ again outside the chroot. This is a widely used method of breaking
61624+ out of a chroot jail and should not be allowed. If the sysctl
61625+ option is enabled, a sysctl option with name
61626+ "chroot_deny_chroot" is created.
61627+
61628+config GRKERNSEC_CHROOT_PIVOT
61629+ bool "Deny pivot_root in chroot"
61630+ default y if GRKERNSEC_CONFIG_AUTO
61631+ depends on GRKERNSEC_CHROOT
61632+ help
61633+ If you say Y here, processes inside a chroot will not be able to use
61634+ a function called pivot_root() that was introduced in Linux 2.3.41. It
61635+ works similar to chroot in that it changes the root filesystem. This
61636+ function could be misused in a chrooted process to attempt to break out
61637+ of the chroot, and therefore should not be allowed. If the sysctl
61638+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
61639+ created.
61640+
61641+config GRKERNSEC_CHROOT_CHDIR
61642+ bool "Enforce chdir(\"/\") on all chroots"
61643+ default y if GRKERNSEC_CONFIG_AUTO
61644+ depends on GRKERNSEC_CHROOT
61645+ help
61646+ If you say Y here, the current working directory of all newly-chrooted
61647+ applications will be set to the the root directory of the chroot.
61648+ The man page on chroot(2) states:
61649+ Note that this call does not change the current working
61650+ directory, so that `.' can be outside the tree rooted at
61651+ `/'. In particular, the super-user can escape from a
61652+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
61653+
61654+ It is recommended that you say Y here, since it's not known to break
61655+ any software. If the sysctl option is enabled, a sysctl option with
61656+ name "chroot_enforce_chdir" is created.
61657+
61658+config GRKERNSEC_CHROOT_CHMOD
61659+ bool "Deny (f)chmod +s"
61660+ default y if GRKERNSEC_CONFIG_AUTO
61661+ depends on GRKERNSEC_CHROOT
61662+ help
61663+ If you say Y here, processes inside a chroot will not be able to chmod
61664+ or fchmod files to make them have suid or sgid bits. This protects
61665+ against another published method of breaking a chroot. If the sysctl
61666+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
61667+ created.
61668+
61669+config GRKERNSEC_CHROOT_FCHDIR
61670+ bool "Deny fchdir out of chroot"
61671+ default y if GRKERNSEC_CONFIG_AUTO
61672+ depends on GRKERNSEC_CHROOT
61673+ help
61674+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
61675+ to a file descriptor of the chrooting process that points to a directory
61676+ outside the filesystem will be stopped. If the sysctl option
61677+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
61678+
61679+config GRKERNSEC_CHROOT_MKNOD
61680+ bool "Deny mknod"
61681+ default y if GRKERNSEC_CONFIG_AUTO
61682+ depends on GRKERNSEC_CHROOT
61683+ help
61684+ If you say Y here, processes inside a chroot will not be allowed to
61685+ mknod. The problem with using mknod inside a chroot is that it
61686+ would allow an attacker to create a device entry that is the same
61687+ as one on the physical root of your system, which could range from
61688+ anything from the console device to a device for your harddrive (which
61689+ they could then use to wipe the drive or steal data). It is recommended
61690+ that you say Y here, unless you run into software incompatibilities.
61691+ If the sysctl option is enabled, a sysctl option with name
61692+ "chroot_deny_mknod" is created.
61693+
61694+config GRKERNSEC_CHROOT_SHMAT
61695+ bool "Deny shmat() out of chroot"
61696+ default y if GRKERNSEC_CONFIG_AUTO
61697+ depends on GRKERNSEC_CHROOT
61698+ help
61699+ If you say Y here, processes inside a chroot will not be able to attach
61700+ to shared memory segments that were created outside of the chroot jail.
61701+ It is recommended that you say Y here. If the sysctl option is enabled,
61702+ a sysctl option with name "chroot_deny_shmat" is created.
61703+
61704+config GRKERNSEC_CHROOT_UNIX
61705+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
61706+ default y if GRKERNSEC_CONFIG_AUTO
61707+ depends on GRKERNSEC_CHROOT
61708+ help
61709+ If you say Y here, processes inside a chroot will not be able to
61710+ connect to abstract (meaning not belonging to a filesystem) Unix
61711+ domain sockets that were bound outside of a chroot. It is recommended
61712+ that you say Y here. If the sysctl option is enabled, a sysctl option
61713+ with name "chroot_deny_unix" is created.
61714+
61715+config GRKERNSEC_CHROOT_FINDTASK
61716+ bool "Protect outside processes"
61717+ default y if GRKERNSEC_CONFIG_AUTO
61718+ depends on GRKERNSEC_CHROOT
61719+ help
61720+ If you say Y here, processes inside a chroot will not be able to
61721+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
61722+ getsid, or view any process outside of the chroot. If the sysctl
61723+ option is enabled, a sysctl option with name "chroot_findtask" is
61724+ created.
61725+
61726+config GRKERNSEC_CHROOT_NICE
61727+ bool "Restrict priority changes"
61728+ default y if GRKERNSEC_CONFIG_AUTO
61729+ depends on GRKERNSEC_CHROOT
61730+ help
61731+ If you say Y here, processes inside a chroot will not be able to raise
61732+ the priority of processes in the chroot, or alter the priority of
61733+ processes outside the chroot. This provides more security than simply
61734+ removing CAP_SYS_NICE from the process' capability set. If the
61735+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
61736+ is created.
61737+
61738+config GRKERNSEC_CHROOT_SYSCTL
61739+ bool "Deny sysctl writes"
61740+ default y if GRKERNSEC_CONFIG_AUTO
61741+ depends on GRKERNSEC_CHROOT
61742+ help
61743+ If you say Y here, an attacker in a chroot will not be able to
61744+ write to sysctl entries, either by sysctl(2) or through a /proc
61745+ interface. It is strongly recommended that you say Y here. If the
61746+ sysctl option is enabled, a sysctl option with name
61747+ "chroot_deny_sysctl" is created.
61748+
61749+config GRKERNSEC_CHROOT_CAPS
61750+ bool "Capability restrictions"
61751+ default y if GRKERNSEC_CONFIG_AUTO
61752+ depends on GRKERNSEC_CHROOT
61753+ help
61754+ If you say Y here, the capabilities on all processes within a
61755+ chroot jail will be lowered to stop module insertion, raw i/o,
61756+ system and net admin tasks, rebooting the system, modifying immutable
61757+ files, modifying IPC owned by another, and changing the system time.
61758+ This is left an option because it can break some apps. Disable this
61759+ if your chrooted apps are having problems performing those kinds of
61760+ tasks. If the sysctl option is enabled, a sysctl option with
61761+ name "chroot_caps" is created.
61762+
61763+config GRKERNSEC_CHROOT_INITRD
61764+ bool "Exempt initrd tasks from restrictions"
61765+ default y if GRKERNSEC_CONFIG_AUTO
61766+ depends on GRKERNSEC_CHROOT && BLK_DEV_RAM
61767+ help
61768+ If you say Y here, tasks started prior to init will be exempted from
61769+ grsecurity's chroot restrictions. This option is mainly meant to
61770+ resolve Plymouth's performing privileged operations unnecessarily
61771+ in a chroot.
61772+
61773+endmenu
61774+menu "Kernel Auditing"
61775+depends on GRKERNSEC
61776+
61777+config GRKERNSEC_AUDIT_GROUP
61778+ bool "Single group for auditing"
61779+ help
61780+ If you say Y here, the exec and chdir logging features will only operate
61781+ on a group you specify. This option is recommended if you only want to
61782+ watch certain users instead of having a large amount of logs from the
61783+ entire system. If the sysctl option is enabled, a sysctl option with
61784+ name "audit_group" is created.
61785+
61786+config GRKERNSEC_AUDIT_GID
61787+ int "GID for auditing"
61788+ depends on GRKERNSEC_AUDIT_GROUP
61789+ default 1007
61790+
61791+config GRKERNSEC_EXECLOG
61792+ bool "Exec logging"
61793+ help
61794+ If you say Y here, all execve() calls will be logged (since the
61795+ other exec*() calls are frontends to execve(), all execution
61796+ will be logged). Useful for shell-servers that like to keep track
61797+ of their users. If the sysctl option is enabled, a sysctl option with
61798+ name "exec_logging" is created.
61799+ WARNING: This option when enabled will produce a LOT of logs, especially
61800+ on an active system.
61801+
61802+config GRKERNSEC_RESLOG
61803+ bool "Resource logging"
61804+ default y if GRKERNSEC_CONFIG_AUTO
61805+ help
61806+ If you say Y here, all attempts to overstep resource limits will
61807+ be logged with the resource name, the requested size, and the current
61808+ limit. It is highly recommended that you say Y here. If the sysctl
61809+ option is enabled, a sysctl option with name "resource_logging" is
61810+ created. If the RBAC system is enabled, the sysctl value is ignored.
61811+
61812+config GRKERNSEC_CHROOT_EXECLOG
61813+ bool "Log execs within chroot"
61814+ help
61815+ If you say Y here, all executions inside a chroot jail will be logged
61816+ to syslog. This can cause a large amount of logs if certain
61817+ applications (eg. djb's daemontools) are installed on the system, and
61818+ is therefore left as an option. If the sysctl option is enabled, a
61819+ sysctl option with name "chroot_execlog" is created.
61820+
61821+config GRKERNSEC_AUDIT_PTRACE
61822+ bool "Ptrace logging"
61823+ help
61824+ If you say Y here, all attempts to attach to a process via ptrace
61825+ will be logged. If the sysctl option is enabled, a sysctl option
61826+ with name "audit_ptrace" is created.
61827+
61828+config GRKERNSEC_AUDIT_CHDIR
61829+ bool "Chdir logging"
61830+ help
61831+ If you say Y here, all chdir() calls will be logged. If the sysctl
61832+ option is enabled, a sysctl option with name "audit_chdir" is created.
61833+
61834+config GRKERNSEC_AUDIT_MOUNT
61835+ bool "(Un)Mount logging"
61836+ help
61837+ If you say Y here, all mounts and unmounts will be logged. If the
61838+ sysctl option is enabled, a sysctl option with name "audit_mount" is
61839+ created.
61840+
61841+config GRKERNSEC_SIGNAL
61842+ bool "Signal logging"
61843+ default y if GRKERNSEC_CONFIG_AUTO
61844+ help
61845+ If you say Y here, certain important signals will be logged, such as
61846+ SIGSEGV, which will as a result inform you of when a error in a program
61847+ occurred, which in some cases could mean a possible exploit attempt.
61848+ If the sysctl option is enabled, a sysctl option with name
61849+ "signal_logging" is created.
61850+
61851+config GRKERNSEC_FORKFAIL
61852+ bool "Fork failure logging"
61853+ help
61854+ If you say Y here, all failed fork() attempts will be logged.
61855+ This could suggest a fork bomb, or someone attempting to overstep
61856+ their process limit. If the sysctl option is enabled, a sysctl option
61857+ with name "forkfail_logging" is created.
61858+
61859+config GRKERNSEC_TIME
61860+ bool "Time change logging"
61861+ default y if GRKERNSEC_CONFIG_AUTO
61862+ help
61863+ If you say Y here, any changes of the system clock will be logged.
61864+ If the sysctl option is enabled, a sysctl option with name
61865+ "timechange_logging" is created.
61866+
61867+config GRKERNSEC_PROC_IPADDR
61868+ bool "/proc/<pid>/ipaddr support"
61869+ default y if GRKERNSEC_CONFIG_AUTO
61870+ help
61871+ If you say Y here, a new entry will be added to each /proc/<pid>
61872+ directory that contains the IP address of the person using the task.
61873+ The IP is carried across local TCP and AF_UNIX stream sockets.
61874+ This information can be useful for IDS/IPSes to perform remote response
61875+ to a local attack. The entry is readable by only the owner of the
61876+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
61877+ the RBAC system), and thus does not create privacy concerns.
61878+
61879+config GRKERNSEC_RWXMAP_LOG
61880+ bool 'Denied RWX mmap/mprotect logging'
61881+ default y if GRKERNSEC_CONFIG_AUTO
61882+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
61883+ help
61884+ If you say Y here, calls to mmap() and mprotect() with explicit
61885+ usage of PROT_WRITE and PROT_EXEC together will be logged when
61886+ denied by the PAX_MPROTECT feature. This feature will also
61887+ log other problematic scenarios that can occur when PAX_MPROTECT
61888+ is enabled on a binary, like textrels and PT_GNU_STACK. If the
61889+ sysctl option is enabled, a sysctl option with name "rwxmap_logging"
61890+ is created.
61891+
61892+endmenu
61893+
61894+menu "Executable Protections"
61895+depends on GRKERNSEC
61896+
61897+config GRKERNSEC_DMESG
61898+ bool "Dmesg(8) restriction"
61899+ default y if GRKERNSEC_CONFIG_AUTO
61900+ help
61901+ If you say Y here, non-root users will not be able to use dmesg(8)
61902+ to view the contents of the kernel's circular log buffer.
61903+ The kernel's log buffer often contains kernel addresses and other
61904+ identifying information useful to an attacker in fingerprinting a
61905+ system for a targeted exploit.
61906+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
61907+ created.
61908+
61909+config GRKERNSEC_HARDEN_PTRACE
61910+ bool "Deter ptrace-based process snooping"
61911+ default y if GRKERNSEC_CONFIG_AUTO
61912+ help
61913+ If you say Y here, TTY sniffers and other malicious monitoring
61914+ programs implemented through ptrace will be defeated. If you
61915+ have been using the RBAC system, this option has already been
61916+ enabled for several years for all users, with the ability to make
61917+ fine-grained exceptions.
61918+
61919+ This option only affects the ability of non-root users to ptrace
61920+ processes that are not a descendent of the ptracing process.
61921+ This means that strace ./binary and gdb ./binary will still work,
61922+ but attaching to arbitrary processes will not. If the sysctl
61923+ option is enabled, a sysctl option with name "harden_ptrace" is
61924+ created.
61925+
61926+config GRKERNSEC_PTRACE_READEXEC
61927+ bool "Require read access to ptrace sensitive binaries"
61928+ default y if GRKERNSEC_CONFIG_AUTO
61929+ help
61930+ If you say Y here, unprivileged users will not be able to ptrace unreadable
61931+ binaries. This option is useful in environments that
61932+ remove the read bits (e.g. file mode 4711) from suid binaries to
61933+ prevent infoleaking of their contents. This option adds
61934+ consistency to the use of that file mode, as the binary could normally
61935+ be read out when run without privileges while ptracing.
61936+
61937+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
61938+ is created.
61939+
61940+config GRKERNSEC_SETXID
61941+ bool "Enforce consistent multithreaded privileges"
61942+ default y if GRKERNSEC_CONFIG_AUTO
61943+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
61944+ help
61945+ If you say Y here, a change from a root uid to a non-root uid
61946+ in a multithreaded application will cause the resulting uids,
61947+ gids, supplementary groups, and capabilities in that thread
61948+ to be propagated to the other threads of the process. In most
61949+ cases this is unnecessary, as glibc will emulate this behavior
61950+ on behalf of the application. Other libcs do not act in the
61951+ same way, allowing the other threads of the process to continue
61952+ running with root privileges. If the sysctl option is enabled,
61953+ a sysctl option with name "consistent_setxid" is created.
61954+
61955+config GRKERNSEC_TPE
61956+ bool "Trusted Path Execution (TPE)"
61957+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
61958+ help
61959+ If you say Y here, you will be able to choose a gid to add to the
61960+ supplementary groups of users you want to mark as "untrusted."
61961+ These users will not be able to execute any files that are not in
61962+ root-owned directories writable only by root. If the sysctl option
61963+ is enabled, a sysctl option with name "tpe" is created.
61964+
61965+config GRKERNSEC_TPE_ALL
61966+ bool "Partially restrict all non-root users"
61967+ depends on GRKERNSEC_TPE
61968+ help
61969+ If you say Y here, all non-root users will be covered under
61970+ a weaker TPE restriction. This is separate from, and in addition to,
61971+ the main TPE options that you have selected elsewhere. Thus, if a
61972+ "trusted" GID is chosen, this restriction applies to even that GID.
61973+ Under this restriction, all non-root users will only be allowed to
61974+ execute files in directories they own that are not group or
61975+ world-writable, or in directories owned by root and writable only by
61976+ root. If the sysctl option is enabled, a sysctl option with name
61977+ "tpe_restrict_all" is created.
61978+
61979+config GRKERNSEC_TPE_INVERT
61980+ bool "Invert GID option"
61981+ depends on GRKERNSEC_TPE
61982+ help
61983+ If you say Y here, the group you specify in the TPE configuration will
61984+ decide what group TPE restrictions will be *disabled* for. This
61985+ option is useful if you want TPE restrictions to be applied to most
61986+ users on the system. If the sysctl option is enabled, a sysctl option
61987+ with name "tpe_invert" is created. Unlike other sysctl options, this
61988+ entry will default to on for backward-compatibility.
61989+
61990+config GRKERNSEC_TPE_GID
61991+ int
61992+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
61993+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
61994+
61995+config GRKERNSEC_TPE_UNTRUSTED_GID
61996+ int "GID for TPE-untrusted users"
61997+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
61998+ default 1005
61999+ help
62000+ Setting this GID determines what group TPE restrictions will be
62001+ *enabled* for. If the sysctl option is enabled, a sysctl option
62002+ with name "tpe_gid" is created.
62003+
62004+config GRKERNSEC_TPE_TRUSTED_GID
62005+ int "GID for TPE-trusted users"
62006+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
62007+ default 1005
62008+ help
62009+ Setting this GID determines what group TPE restrictions will be
62010+ *disabled* for. If the sysctl option is enabled, a sysctl option
62011+ with name "tpe_gid" is created.
62012+
62013+endmenu
62014+menu "Network Protections"
62015+depends on GRKERNSEC
62016+
62017+config GRKERNSEC_RANDNET
62018+ bool "Larger entropy pools"
62019+ default y if GRKERNSEC_CONFIG_AUTO
62020+ help
62021+ If you say Y here, the entropy pools used for many features of Linux
62022+ and grsecurity will be doubled in size. Since several grsecurity
62023+ features use additional randomness, it is recommended that you say Y
62024+ here. Saying Y here has a similar effect as modifying
62025+ /proc/sys/kernel/random/poolsize.
62026+
62027+config GRKERNSEC_BLACKHOLE
62028+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
62029+ default y if GRKERNSEC_CONFIG_AUTO
62030+ depends on NET
62031+ help
62032+ If you say Y here, neither TCP resets nor ICMP
62033+ destination-unreachable packets will be sent in response to packets
62034+ sent to ports for which no associated listening process exists.
62035+ This feature supports both IPV4 and IPV6 and exempts the
62036+ loopback interface from blackholing. Enabling this feature
62037+ makes a host more resilient to DoS attacks and reduces network
62038+ visibility against scanners.
62039+
62040+ The blackhole feature as-implemented is equivalent to the FreeBSD
62041+ blackhole feature, as it prevents RST responses to all packets, not
62042+ just SYNs. Under most application behavior this causes no
62043+ problems, but applications (like haproxy) may not close certain
62044+ connections in a way that cleanly terminates them on the remote
62045+ end, leaving the remote host in LAST_ACK state. Because of this
62046+ side-effect and to prevent intentional LAST_ACK DoSes, this
62047+ feature also adds automatic mitigation against such attacks.
62048+ The mitigation drastically reduces the amount of time a socket
62049+ can spend in LAST_ACK state. If you're using haproxy and not
62050+ all servers it connects to have this option enabled, consider
62051+ disabling this feature on the haproxy host.
62052+
62053+ If the sysctl option is enabled, two sysctl options with names
62054+ "ip_blackhole" and "lastack_retries" will be created.
62055+ While "ip_blackhole" takes the standard zero/non-zero on/off
62056+ toggle, "lastack_retries" uses the same kinds of values as
62057+ "tcp_retries1" and "tcp_retries2". The default value of 4
62058+ prevents a socket from lasting more than 45 seconds in LAST_ACK
62059+ state.
62060+
62061+config GRKERNSEC_NO_SIMULT_CONNECT
62062+ bool "Disable TCP Simultaneous Connect"
62063+ default y if GRKERNSEC_CONFIG_AUTO
62064+ depends on NET
62065+ help
62066+ If you say Y here, a feature by Willy Tarreau will be enabled that
62067+ removes a weakness in Linux's strict implementation of TCP that
62068+ allows two clients to connect to each other without either entering
62069+ a listening state. The weakness allows an attacker to easily prevent
62070+ a client from connecting to a known server provided the source port
62071+ for the connection is guessed correctly.
62072+
62073+ As the weakness could be used to prevent an antivirus or IPS from
62074+ fetching updates, or prevent an SSL gateway from fetching a CRL,
62075+ it should be eliminated by enabling this option. Though Linux is
62076+ one of few operating systems supporting simultaneous connect, it
62077+ has no legitimate use in practice and is rarely supported by firewalls.
62078+
62079+config GRKERNSEC_SOCKET
62080+ bool "Socket restrictions"
62081+ depends on NET
62082+ help
62083+ If you say Y here, you will be able to choose from several options.
62084+ If you assign a GID on your system and add it to the supplementary
62085+ groups of users you want to restrict socket access to, this patch
62086+ will perform up to three things, based on the option(s) you choose.
62087+
62088+config GRKERNSEC_SOCKET_ALL
62089+ bool "Deny any sockets to group"
62090+ depends on GRKERNSEC_SOCKET
62091+ help
62092+ If you say Y here, you will be able to choose a GID of whose users will
62093+ be unable to connect to other hosts from your machine or run server
62094+ applications from your machine. If the sysctl option is enabled, a
62095+ sysctl option with name "socket_all" is created.
62096+
62097+config GRKERNSEC_SOCKET_ALL_GID
62098+ int "GID to deny all sockets for"
62099+ depends on GRKERNSEC_SOCKET_ALL
62100+ default 1004
62101+ help
62102+ Here you can choose the GID to disable socket access for. Remember to
62103+ add the users you want socket access disabled for to the GID
62104+ specified here. If the sysctl option is enabled, a sysctl option
62105+ with name "socket_all_gid" is created.
62106+
62107+config GRKERNSEC_SOCKET_CLIENT
62108+ bool "Deny client sockets to group"
62109+ depends on GRKERNSEC_SOCKET
62110+ help
62111+ If you say Y here, you will be able to choose a GID of whose users will
62112+ be unable to connect to other hosts from your machine, but will be
62113+ able to run servers. If this option is enabled, all users in the group
62114+ you specify will have to use passive mode when initiating ftp transfers
62115+ from the shell on your machine. If the sysctl option is enabled, a
62116+ sysctl option with name "socket_client" is created.
62117+
62118+config GRKERNSEC_SOCKET_CLIENT_GID
62119+ int "GID to deny client sockets for"
62120+ depends on GRKERNSEC_SOCKET_CLIENT
62121+ default 1003
62122+ help
62123+ Here you can choose the GID to disable client socket access for.
62124+ Remember to add the users you want client socket access disabled for to
62125+ the GID specified here. If the sysctl option is enabled, a sysctl
62126+ option with name "socket_client_gid" is created.
62127+
62128+config GRKERNSEC_SOCKET_SERVER
62129+ bool "Deny server sockets to group"
62130+ depends on GRKERNSEC_SOCKET
62131+ help
62132+ If you say Y here, you will be able to choose a GID of whose users will
62133+ be unable to run server applications from your machine. If the sysctl
62134+ option is enabled, a sysctl option with name "socket_server" is created.
62135+
62136+config GRKERNSEC_SOCKET_SERVER_GID
62137+ int "GID to deny server sockets for"
62138+ depends on GRKERNSEC_SOCKET_SERVER
62139+ default 1002
62140+ help
62141+ Here you can choose the GID to disable server socket access for.
62142+ Remember to add the users you want server socket access disabled for to
62143+ the GID specified here. If the sysctl option is enabled, a sysctl
62144+ option with name "socket_server_gid" is created.
62145+
62146+endmenu
62147+
62148+menu "Physical Protections"
62149+depends on GRKERNSEC
62150+
62151+config GRKERNSEC_DENYUSB
62152+ bool "Deny new USB connections after toggle"
62153+ default y if GRKERNSEC_CONFIG_AUTO
62154+ depends on SYSCTL && USB_SUPPORT
62155+ help
62156+ If you say Y here, a new sysctl option with name "deny_new_usb"
62157+ will be created. Setting its value to 1 will prevent any new
62158+ USB devices from being recognized by the OS. Any attempted USB
62159+ device insertion will be logged. This option is intended to be
62160+ used against custom USB devices designed to exploit vulnerabilities
62161+ in various USB device drivers.
62162+
62163+ For greatest effectiveness, this sysctl should be set after any
62164+ relevant init scripts. This option is safe to enable in distros
62165+ as each user can choose whether or not to toggle the sysctl.
62166+
62167+config GRKERNSEC_DENYUSB_FORCE
62168+ bool "Reject all USB devices not connected at boot"
62169+ select USB
62170+ depends on GRKERNSEC_DENYUSB
62171+ help
62172+ If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
62173+ that doesn't involve a sysctl entry. This option should only be
62174+ enabled if you're sure you want to deny all new USB connections
62175+ at runtime and don't want to modify init scripts. This should not
62176+ be enabled by distros. It forces the core USB code to be built
62177+ into the kernel image so that all devices connected at boot time
62178+ can be recognized and new USB device connections can be prevented
62179+ prior to init running.
62180+
62181+endmenu
62182+
62183+menu "Sysctl Support"
62184+depends on GRKERNSEC && SYSCTL
62185+
62186+config GRKERNSEC_SYSCTL
62187+ bool "Sysctl support"
62188+ default y if GRKERNSEC_CONFIG_AUTO
62189+ help
62190+ If you say Y here, you will be able to change the options that
62191+ grsecurity runs with at bootup, without having to recompile your
62192+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
62193+ to enable (1) or disable (0) various features. All the sysctl entries
62194+ are mutable until the "grsec_lock" entry is set to a non-zero value.
62195+ All features enabled in the kernel configuration are disabled at boot
62196+ if you do not say Y to the "Turn on features by default" option.
62197+ All options should be set at startup, and the grsec_lock entry should
62198+ be set to a non-zero value after all the options are set.
62199+ *THIS IS EXTREMELY IMPORTANT*
62200+
62201+config GRKERNSEC_SYSCTL_DISTRO
62202+ bool "Extra sysctl support for distro makers (READ HELP)"
62203+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
62204+ help
62205+ If you say Y here, additional sysctl options will be created
62206+ for features that affect processes running as root. Therefore,
62207+ it is critical when using this option that the grsec_lock entry be
62208+ enabled after boot. Only distros with prebuilt kernel packages
62209+ with this option enabled that can ensure grsec_lock is enabled
62210+ after boot should use this option.
62211+ *Failure to set grsec_lock after boot makes all grsec features
62212+ this option covers useless*
62213+
62214+ Currently this option creates the following sysctl entries:
62215+ "Disable Privileged I/O": "disable_priv_io"
62216+
62217+config GRKERNSEC_SYSCTL_ON
62218+ bool "Turn on features by default"
62219+ default y if GRKERNSEC_CONFIG_AUTO
62220+ depends on GRKERNSEC_SYSCTL
62221+ help
62222+ If you say Y here, instead of having all features enabled in the
62223+ kernel configuration disabled at boot time, the features will be
62224+ enabled at boot time. It is recommended you say Y here unless
62225+ there is some reason you would want all sysctl-tunable features to
62226+ be disabled by default. As mentioned elsewhere, it is important
62227+ to enable the grsec_lock entry once you have finished modifying
62228+ the sysctl entries.
62229+
62230+endmenu
62231+menu "Logging Options"
62232+depends on GRKERNSEC
62233+
62234+config GRKERNSEC_FLOODTIME
62235+ int "Seconds in between log messages (minimum)"
62236+ default 10
62237+ help
62238+ This option allows you to enforce the number of seconds between
62239+ grsecurity log messages. The default should be suitable for most
62240+ people, however, if you choose to change it, choose a value small enough
62241+ to allow informative logs to be produced, but large enough to
62242+ prevent flooding.
62243+
62244+config GRKERNSEC_FLOODBURST
62245+ int "Number of messages in a burst (maximum)"
62246+ default 6
62247+ help
62248+ This option allows you to choose the maximum number of messages allowed
62249+ within the flood time interval you chose in a separate option. The
62250+ default should be suitable for most people, however if you find that
62251+ many of your logs are being interpreted as flooding, you may want to
62252+ raise this value.
62253+
62254+endmenu
62255diff --git a/grsecurity/Makefile b/grsecurity/Makefile
62256new file mode 100644
62257index 0000000..b0b77d5
62258--- /dev/null
62259+++ b/grsecurity/Makefile
62260@@ -0,0 +1,43 @@
62261+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
62262+# during 2001-2009 it has been completely redesigned by Brad Spengler
62263+# into an RBAC system
62264+#
62265+# All code in this directory and various hooks inserted throughout the kernel
62266+# are copyright Brad Spengler - Open Source Security, Inc., and released
62267+# under the GPL v2 or higher
62268+
62269+KBUILD_CFLAGS += -Werror
62270+
62271+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
62272+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
62273+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
62274+ grsec_usb.o
62275+
62276+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
62277+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
62278+ gracl_learn.o grsec_log.o
62279+ifdef CONFIG_COMPAT
62280+obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
62281+endif
62282+
62283+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
62284+
62285+ifdef CONFIG_NET
62286+obj-y += grsec_sock.o
62287+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
62288+endif
62289+
62290+ifndef CONFIG_GRKERNSEC
62291+obj-y += grsec_disabled.o
62292+endif
62293+
62294+ifdef CONFIG_GRKERNSEC_HIDESYM
62295+extra-y := grsec_hidesym.o
62296+$(obj)/grsec_hidesym.o:
62297+ @-chmod -f 500 /boot
62298+ @-chmod -f 500 /lib/modules
62299+ @-chmod -f 500 /lib64/modules
62300+ @-chmod -f 500 /lib32/modules
62301+ @-chmod -f 700 .
62302+ @echo ' grsec: protected kernel image paths'
62303+endif
62304diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
62305new file mode 100644
62306index 0000000..c0793fd
62307--- /dev/null
62308+++ b/grsecurity/gracl.c
62309@@ -0,0 +1,4178 @@
62310+#include <linux/kernel.h>
62311+#include <linux/module.h>
62312+#include <linux/sched.h>
62313+#include <linux/mm.h>
62314+#include <linux/file.h>
62315+#include <linux/fs.h>
62316+#include <linux/namei.h>
62317+#include <linux/mount.h>
62318+#include <linux/tty.h>
62319+#include <linux/proc_fs.h>
62320+#include <linux/lglock.h>
62321+#include <linux/slab.h>
62322+#include <linux/vmalloc.h>
62323+#include <linux/types.h>
62324+#include <linux/sysctl.h>
62325+#include <linux/netdevice.h>
62326+#include <linux/ptrace.h>
62327+#include <linux/gracl.h>
62328+#include <linux/gralloc.h>
62329+#include <linux/security.h>
62330+#include <linux/grinternal.h>
62331+#include <linux/pid_namespace.h>
62332+#include <linux/stop_machine.h>
62333+#include <linux/fdtable.h>
62334+#include <linux/percpu.h>
62335+#include <linux/lglock.h>
62336+#include <linux/hugetlb.h>
62337+#include <linux/posix-timers.h>
62338+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
62339+#include <linux/magic.h>
62340+#include <linux/pagemap.h>
62341+#include "../fs/btrfs/async-thread.h"
62342+#include "../fs/btrfs/ctree.h"
62343+#include "../fs/btrfs/btrfs_inode.h"
62344+#endif
62345+#include "../fs/mount.h"
62346+
62347+#include <asm/uaccess.h>
62348+#include <asm/errno.h>
62349+#include <asm/mman.h>
62350+
62351+extern struct lglock vfsmount_lock;
62352+
62353+static struct acl_role_db acl_role_set;
62354+static struct name_db name_set;
62355+static struct inodev_db inodev_set;
62356+
62357+/* for keeping track of userspace pointers used for subjects, so we
62358+ can share references in the kernel as well
62359+*/
62360+
62361+static struct path real_root;
62362+
62363+static struct acl_subj_map_db subj_map_set;
62364+
62365+static struct acl_role_label *default_role;
62366+
62367+static struct acl_role_label *role_list;
62368+
62369+static u16 acl_sp_role_value;
62370+
62371+extern char *gr_shared_page[4];
62372+static DEFINE_MUTEX(gr_dev_mutex);
62373+DEFINE_RWLOCK(gr_inode_lock);
62374+
62375+struct gr_arg *gr_usermode;
62376+
62377+static unsigned int gr_status __read_only = GR_STATUS_INIT;
62378+
62379+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
62380+extern void gr_clear_learn_entries(void);
62381+
62382+unsigned char *gr_system_salt;
62383+unsigned char *gr_system_sum;
62384+
62385+static struct sprole_pw **acl_special_roles = NULL;
62386+static __u16 num_sprole_pws = 0;
62387+
62388+static struct acl_role_label *kernel_role = NULL;
62389+
62390+static unsigned int gr_auth_attempts = 0;
62391+static unsigned long gr_auth_expires = 0UL;
62392+
62393+#ifdef CONFIG_NET
62394+extern struct vfsmount *sock_mnt;
62395+#endif
62396+
62397+extern struct vfsmount *pipe_mnt;
62398+extern struct vfsmount *shm_mnt;
62399+
62400+#ifdef CONFIG_HUGETLBFS
62401+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
62402+#endif
62403+
62404+static struct acl_object_label *fakefs_obj_rw;
62405+static struct acl_object_label *fakefs_obj_rwx;
62406+
62407+extern int gr_init_uidset(void);
62408+extern void gr_free_uidset(void);
62409+extern void gr_remove_uid(uid_t uid);
62410+extern int gr_find_uid(uid_t uid);
62411+
62412+static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
62413+{
62414+ if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
62415+ return -EFAULT;
62416+
62417+ return 0;
62418+}
62419+
62420+static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
62421+{
62422+ if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
62423+ return -EFAULT;
62424+
62425+ return 0;
62426+}
62427+
62428+static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
62429+{
62430+ if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
62431+ return -EFAULT;
62432+
62433+ return 0;
62434+}
62435+
62436+static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
62437+{
62438+ if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
62439+ return -EFAULT;
62440+
62441+ return 0;
62442+}
62443+
62444+static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
62445+{
62446+ if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
62447+ return -EFAULT;
62448+
62449+ return 0;
62450+}
62451+
62452+static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
62453+{
62454+ if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
62455+ return -EFAULT;
62456+
62457+ return 0;
62458+}
62459+
62460+static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
62461+{
62462+ if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
62463+ return -EFAULT;
62464+
62465+ return 0;
62466+}
62467+
62468+static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
62469+{
62470+ if (copy_from_user(trans, userp, sizeof(struct role_transition)))
62471+ return -EFAULT;
62472+
62473+ return 0;
62474+}
62475+
62476+int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
62477+{
62478+ if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
62479+ return -EFAULT;
62480+
62481+ return 0;
62482+}
62483+
62484+static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
62485+{
62486+ if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
62487+ return -EFAULT;
62488+
62489+ if ((uwrap->version != GRSECURITY_VERSION) || (uwrap->size != sizeof(struct gr_arg)))
62490+ return -EINVAL;
62491+
62492+ return 0;
62493+}
62494+
62495+static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
62496+{
62497+ if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
62498+ return -EFAULT;
62499+
62500+ return 0;
62501+}
62502+
62503+static size_t get_gr_arg_wrapper_size_normal(void)
62504+{
62505+ return sizeof(struct gr_arg_wrapper);
62506+}
62507+
62508+#ifdef CONFIG_COMPAT
62509+extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
62510+extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
62511+extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
62512+extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
62513+extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
62514+extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
62515+extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
62516+extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
62517+extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
62518+extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
62519+extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
62520+extern size_t get_gr_arg_wrapper_size_compat(void);
62521+
62522+int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
62523+int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
62524+int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
62525+int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
62526+int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
62527+int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
62528+int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
62529+int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
62530+int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
62531+int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
62532+int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
62533+size_t (* get_gr_arg_wrapper_size)(void) __read_only;
62534+
62535+#else
62536+#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
62537+#define copy_gr_arg copy_gr_arg_normal
62538+#define copy_gr_hash_struct copy_gr_hash_struct_normal
62539+#define copy_acl_object_label copy_acl_object_label_normal
62540+#define copy_acl_subject_label copy_acl_subject_label_normal
62541+#define copy_acl_role_label copy_acl_role_label_normal
62542+#define copy_acl_ip_label copy_acl_ip_label_normal
62543+#define copy_pointer_from_array copy_pointer_from_array_normal
62544+#define copy_sprole_pw copy_sprole_pw_normal
62545+#define copy_role_transition copy_role_transition_normal
62546+#define copy_role_allowed_ip copy_role_allowed_ip_normal
62547+#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
62548+#endif
62549+
62550+__inline__ int
62551+gr_acl_is_enabled(void)
62552+{
62553+ return (gr_status & GR_READY);
62554+}
62555+
62556+static inline dev_t __get_dev(const struct dentry *dentry)
62557+{
62558+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
62559+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
62560+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
62561+ else
62562+#endif
62563+ return dentry->d_sb->s_dev;
62564+}
62565+
62566+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
62567+{
62568+ return __get_dev(dentry);
62569+}
62570+
62571+static char gr_task_roletype_to_char(struct task_struct *task)
62572+{
62573+ switch (task->role->roletype &
62574+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
62575+ GR_ROLE_SPECIAL)) {
62576+ case GR_ROLE_DEFAULT:
62577+ return 'D';
62578+ case GR_ROLE_USER:
62579+ return 'U';
62580+ case GR_ROLE_GROUP:
62581+ return 'G';
62582+ case GR_ROLE_SPECIAL:
62583+ return 'S';
62584+ }
62585+
62586+ return 'X';
62587+}
62588+
62589+char gr_roletype_to_char(void)
62590+{
62591+ return gr_task_roletype_to_char(current);
62592+}
62593+
62594+__inline__ int
62595+gr_acl_tpe_check(void)
62596+{
62597+ if (unlikely(!(gr_status & GR_READY)))
62598+ return 0;
62599+ if (current->role->roletype & GR_ROLE_TPE)
62600+ return 1;
62601+ else
62602+ return 0;
62603+}
62604+
62605+int
62606+gr_handle_rawio(const struct inode *inode)
62607+{
62608+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
62609+ if (inode && S_ISBLK(inode->i_mode) &&
62610+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
62611+ !capable(CAP_SYS_RAWIO))
62612+ return 1;
62613+#endif
62614+ return 0;
62615+}
62616+
62617+static int
62618+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
62619+{
62620+ if (likely(lena != lenb))
62621+ return 0;
62622+
62623+ return !memcmp(a, b, lena);
62624+}
62625+
62626+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
62627+{
62628+ *buflen -= namelen;
62629+ if (*buflen < 0)
62630+ return -ENAMETOOLONG;
62631+ *buffer -= namelen;
62632+ memcpy(*buffer, str, namelen);
62633+ return 0;
62634+}
62635+
62636+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
62637+{
62638+ return prepend(buffer, buflen, name->name, name->len);
62639+}
62640+
62641+static int prepend_path(const struct path *path, struct path *root,
62642+ char **buffer, int *buflen)
62643+{
62644+ struct dentry *dentry = path->dentry;
62645+ struct vfsmount *vfsmnt = path->mnt;
62646+ struct mount *mnt = real_mount(vfsmnt);
62647+ bool slash = false;
62648+ int error = 0;
62649+
62650+ while (dentry != root->dentry || vfsmnt != root->mnt) {
62651+ struct dentry * parent;
62652+
62653+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
62654+ /* Global root? */
62655+ if (!mnt_has_parent(mnt)) {
62656+ goto out;
62657+ }
62658+ dentry = mnt->mnt_mountpoint;
62659+ mnt = mnt->mnt_parent;
62660+ vfsmnt = &mnt->mnt;
62661+ continue;
62662+ }
62663+ parent = dentry->d_parent;
62664+ prefetch(parent);
62665+ spin_lock(&dentry->d_lock);
62666+ error = prepend_name(buffer, buflen, &dentry->d_name);
62667+ spin_unlock(&dentry->d_lock);
62668+ if (!error)
62669+ error = prepend(buffer, buflen, "/", 1);
62670+ if (error)
62671+ break;
62672+
62673+ slash = true;
62674+ dentry = parent;
62675+ }
62676+
62677+out:
62678+ if (!error && !slash)
62679+ error = prepend(buffer, buflen, "/", 1);
62680+
62681+ return error;
62682+}
62683+
62684+/* this must be called with vfsmount_lock and rename_lock held */
62685+
62686+static char *__our_d_path(const struct path *path, struct path *root,
62687+ char *buf, int buflen)
62688+{
62689+ char *res = buf + buflen;
62690+ int error;
62691+
62692+ prepend(&res, &buflen, "\0", 1);
62693+ error = prepend_path(path, root, &res, &buflen);
62694+ if (error)
62695+ return ERR_PTR(error);
62696+
62697+ return res;
62698+}
62699+
62700+static char *
62701+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
62702+{
62703+ char *retval;
62704+
62705+ retval = __our_d_path(path, root, buf, buflen);
62706+ if (unlikely(IS_ERR(retval)))
62707+ retval = strcpy(buf, "<path too long>");
62708+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
62709+ retval[1] = '\0';
62710+
62711+ return retval;
62712+}
62713+
62714+static char *
62715+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
62716+ char *buf, int buflen)
62717+{
62718+ struct path path;
62719+ char *res;
62720+
62721+ path.dentry = (struct dentry *)dentry;
62722+ path.mnt = (struct vfsmount *)vfsmnt;
62723+
62724+ /* we can use real_root.dentry, real_root.mnt, because this is only called
62725+ by the RBAC system */
62726+ res = gen_full_path(&path, &real_root, buf, buflen);
62727+
62728+ return res;
62729+}
62730+
62731+static char *
62732+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
62733+ char *buf, int buflen)
62734+{
62735+ char *res;
62736+ struct path path;
62737+ struct path root;
62738+ struct task_struct *reaper = init_pid_ns.child_reaper;
62739+
62740+ path.dentry = (struct dentry *)dentry;
62741+ path.mnt = (struct vfsmount *)vfsmnt;
62742+
62743+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
62744+ get_fs_root(reaper->fs, &root);
62745+
62746+ br_read_lock(&vfsmount_lock);
62747+ write_seqlock(&rename_lock);
62748+ res = gen_full_path(&path, &root, buf, buflen);
62749+ write_sequnlock(&rename_lock);
62750+ br_read_unlock(&vfsmount_lock);
62751+
62752+ path_put(&root);
62753+ return res;
62754+}
62755+
62756+static char *
62757+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
62758+{
62759+ char *ret;
62760+ br_read_lock(&vfsmount_lock);
62761+ write_seqlock(&rename_lock);
62762+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
62763+ PAGE_SIZE);
62764+ write_sequnlock(&rename_lock);
62765+ br_read_unlock(&vfsmount_lock);
62766+ return ret;
62767+}
62768+
62769+static char *
62770+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
62771+{
62772+ char *ret;
62773+ char *buf;
62774+ int buflen;
62775+
62776+ br_read_lock(&vfsmount_lock);
62777+ write_seqlock(&rename_lock);
62778+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
62779+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
62780+ buflen = (int)(ret - buf);
62781+ if (buflen >= 5)
62782+ prepend(&ret, &buflen, "/proc", 5);
62783+ else
62784+ ret = strcpy(buf, "<path too long>");
62785+ write_sequnlock(&rename_lock);
62786+ br_read_unlock(&vfsmount_lock);
62787+ return ret;
62788+}
62789+
62790+char *
62791+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
62792+{
62793+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
62794+ PAGE_SIZE);
62795+}
62796+
62797+char *
62798+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
62799+{
62800+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
62801+ PAGE_SIZE);
62802+}
62803+
62804+char *
62805+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
62806+{
62807+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
62808+ PAGE_SIZE);
62809+}
62810+
62811+char *
62812+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
62813+{
62814+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
62815+ PAGE_SIZE);
62816+}
62817+
62818+char *
62819+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
62820+{
62821+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
62822+ PAGE_SIZE);
62823+}
62824+
62825+__inline__ __u32
62826+to_gr_audit(const __u32 reqmode)
62827+{
62828+ /* masks off auditable permission flags, then shifts them to create
62829+ auditing flags, and adds the special case of append auditing if
62830+ we're requesting write */
62831+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
62832+}
62833+
62834+struct acl_subject_label *
62835+lookup_subject_map(const struct acl_subject_label *userp)
62836+{
62837+ unsigned int index = gr_shash(userp, subj_map_set.s_size);
62838+ struct subject_map *match;
62839+
62840+ match = subj_map_set.s_hash[index];
62841+
62842+ while (match && match->user != userp)
62843+ match = match->next;
62844+
62845+ if (match != NULL)
62846+ return match->kernel;
62847+ else
62848+ return NULL;
62849+}
62850+
62851+static void
62852+insert_subj_map_entry(struct subject_map *subjmap)
62853+{
62854+ unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
62855+ struct subject_map **curr;
62856+
62857+ subjmap->prev = NULL;
62858+
62859+ curr = &subj_map_set.s_hash[index];
62860+ if (*curr != NULL)
62861+ (*curr)->prev = subjmap;
62862+
62863+ subjmap->next = *curr;
62864+ *curr = subjmap;
62865+
62866+ return;
62867+}
62868+
62869+static struct acl_role_label *
62870+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
62871+ const gid_t gid)
62872+{
62873+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
62874+ struct acl_role_label *match;
62875+ struct role_allowed_ip *ipp;
62876+ unsigned int x;
62877+ u32 curr_ip = task->signal->curr_ip;
62878+
62879+ task->signal->saved_ip = curr_ip;
62880+
62881+ match = acl_role_set.r_hash[index];
62882+
62883+ while (match) {
62884+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
62885+ for (x = 0; x < match->domain_child_num; x++) {
62886+ if (match->domain_children[x] == uid)
62887+ goto found;
62888+ }
62889+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
62890+ break;
62891+ match = match->next;
62892+ }
62893+found:
62894+ if (match == NULL) {
62895+ try_group:
62896+ index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
62897+ match = acl_role_set.r_hash[index];
62898+
62899+ while (match) {
62900+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
62901+ for (x = 0; x < match->domain_child_num; x++) {
62902+ if (match->domain_children[x] == gid)
62903+ goto found2;
62904+ }
62905+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
62906+ break;
62907+ match = match->next;
62908+ }
62909+found2:
62910+ if (match == NULL)
62911+ match = default_role;
62912+ if (match->allowed_ips == NULL)
62913+ return match;
62914+ else {
62915+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
62916+ if (likely
62917+ ((ntohl(curr_ip) & ipp->netmask) ==
62918+ (ntohl(ipp->addr) & ipp->netmask)))
62919+ return match;
62920+ }
62921+ match = default_role;
62922+ }
62923+ } else if (match->allowed_ips == NULL) {
62924+ return match;
62925+ } else {
62926+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
62927+ if (likely
62928+ ((ntohl(curr_ip) & ipp->netmask) ==
62929+ (ntohl(ipp->addr) & ipp->netmask)))
62930+ return match;
62931+ }
62932+ goto try_group;
62933+ }
62934+
62935+ return match;
62936+}
62937+
62938+struct acl_subject_label *
62939+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
62940+ const struct acl_role_label *role)
62941+{
62942+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
62943+ struct acl_subject_label *match;
62944+
62945+ match = role->subj_hash[index];
62946+
62947+ while (match && (match->inode != ino || match->device != dev ||
62948+ (match->mode & GR_DELETED))) {
62949+ match = match->next;
62950+ }
62951+
62952+ if (match && !(match->mode & GR_DELETED))
62953+ return match;
62954+ else
62955+ return NULL;
62956+}
62957+
62958+struct acl_subject_label *
62959+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
62960+ const struct acl_role_label *role)
62961+{
62962+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
62963+ struct acl_subject_label *match;
62964+
62965+ match = role->subj_hash[index];
62966+
62967+ while (match && (match->inode != ino || match->device != dev ||
62968+ !(match->mode & GR_DELETED))) {
62969+ match = match->next;
62970+ }
62971+
62972+ if (match && (match->mode & GR_DELETED))
62973+ return match;
62974+ else
62975+ return NULL;
62976+}
62977+
62978+static struct acl_object_label *
62979+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
62980+ const struct acl_subject_label *subj)
62981+{
62982+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
62983+ struct acl_object_label *match;
62984+
62985+ match = subj->obj_hash[index];
62986+
62987+ while (match && (match->inode != ino || match->device != dev ||
62988+ (match->mode & GR_DELETED))) {
62989+ match = match->next;
62990+ }
62991+
62992+ if (match && !(match->mode & GR_DELETED))
62993+ return match;
62994+ else
62995+ return NULL;
62996+}
62997+
62998+static struct acl_object_label *
62999+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
63000+ const struct acl_subject_label *subj)
63001+{
63002+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
63003+ struct acl_object_label *match;
63004+
63005+ match = subj->obj_hash[index];
63006+
63007+ while (match && (match->inode != ino || match->device != dev ||
63008+ !(match->mode & GR_DELETED))) {
63009+ match = match->next;
63010+ }
63011+
63012+ if (match && (match->mode & GR_DELETED))
63013+ return match;
63014+
63015+ match = subj->obj_hash[index];
63016+
63017+ while (match && (match->inode != ino || match->device != dev ||
63018+ (match->mode & GR_DELETED))) {
63019+ match = match->next;
63020+ }
63021+
63022+ if (match && !(match->mode & GR_DELETED))
63023+ return match;
63024+ else
63025+ return NULL;
63026+}
63027+
63028+static struct name_entry *
63029+lookup_name_entry(const char *name)
63030+{
63031+ unsigned int len = strlen(name);
63032+ unsigned int key = full_name_hash(name, len);
63033+ unsigned int index = key % name_set.n_size;
63034+ struct name_entry *match;
63035+
63036+ match = name_set.n_hash[index];
63037+
63038+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
63039+ match = match->next;
63040+
63041+ return match;
63042+}
63043+
63044+static struct name_entry *
63045+lookup_name_entry_create(const char *name)
63046+{
63047+ unsigned int len = strlen(name);
63048+ unsigned int key = full_name_hash(name, len);
63049+ unsigned int index = key % name_set.n_size;
63050+ struct name_entry *match;
63051+
63052+ match = name_set.n_hash[index];
63053+
63054+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
63055+ !match->deleted))
63056+ match = match->next;
63057+
63058+ if (match && match->deleted)
63059+ return match;
63060+
63061+ match = name_set.n_hash[index];
63062+
63063+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
63064+ match->deleted))
63065+ match = match->next;
63066+
63067+ if (match && !match->deleted)
63068+ return match;
63069+ else
63070+ return NULL;
63071+}
63072+
63073+static struct inodev_entry *
63074+lookup_inodev_entry(const ino_t ino, const dev_t dev)
63075+{
63076+ unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
63077+ struct inodev_entry *match;
63078+
63079+ match = inodev_set.i_hash[index];
63080+
63081+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
63082+ match = match->next;
63083+
63084+ return match;
63085+}
63086+
63087+static void
63088+insert_inodev_entry(struct inodev_entry *entry)
63089+{
63090+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
63091+ inodev_set.i_size);
63092+ struct inodev_entry **curr;
63093+
63094+ entry->prev = NULL;
63095+
63096+ curr = &inodev_set.i_hash[index];
63097+ if (*curr != NULL)
63098+ (*curr)->prev = entry;
63099+
63100+ entry->next = *curr;
63101+ *curr = entry;
63102+
63103+ return;
63104+}
63105+
63106+static void
63107+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
63108+{
63109+ unsigned int index =
63110+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
63111+ struct acl_role_label **curr;
63112+ struct acl_role_label *tmp, *tmp2;
63113+
63114+ curr = &acl_role_set.r_hash[index];
63115+
63116+ /* simple case, slot is empty, just set it to our role */
63117+ if (*curr == NULL) {
63118+ *curr = role;
63119+ } else {
63120+ /* example:
63121+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
63122+ 2 -> 3
63123+ */
63124+ /* first check to see if we can already be reached via this slot */
63125+ tmp = *curr;
63126+ while (tmp && tmp != role)
63127+ tmp = tmp->next;
63128+ if (tmp == role) {
63129+ /* we don't need to add ourselves to this slot's chain */
63130+ return;
63131+ }
63132+ /* we need to add ourselves to this chain, two cases */
63133+ if (role->next == NULL) {
63134+ /* simple case, append the current chain to our role */
63135+ role->next = *curr;
63136+ *curr = role;
63137+ } else {
63138+ /* 1 -> 2 -> 3 -> 4
63139+ 2 -> 3 -> 4
63140+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
63141+ */
63142+ /* trickier case: walk our role's chain until we find
63143+ the role for the start of the current slot's chain */
63144+ tmp = role;
63145+ tmp2 = *curr;
63146+ while (tmp->next && tmp->next != tmp2)
63147+ tmp = tmp->next;
63148+ if (tmp->next == tmp2) {
63149+ /* from example above, we found 3, so just
63150+ replace this slot's chain with ours */
63151+ *curr = role;
63152+ } else {
63153+ /* we didn't find a subset of our role's chain
63154+ in the current slot's chain, so append their
63155+ chain to ours, and set us as the first role in
63156+ the slot's chain
63157+
63158+ we could fold this case with the case above,
63159+ but making it explicit for clarity
63160+ */
63161+ tmp->next = tmp2;
63162+ *curr = role;
63163+ }
63164+ }
63165+ }
63166+
63167+ return;
63168+}
63169+
63170+static void
63171+insert_acl_role_label(struct acl_role_label *role)
63172+{
63173+ int i;
63174+
63175+ if (role_list == NULL) {
63176+ role_list = role;
63177+ role->prev = NULL;
63178+ } else {
63179+ role->prev = role_list;
63180+ role_list = role;
63181+ }
63182+
63183+ /* used for hash chains */
63184+ role->next = NULL;
63185+
63186+ if (role->roletype & GR_ROLE_DOMAIN) {
63187+ for (i = 0; i < role->domain_child_num; i++)
63188+ __insert_acl_role_label(role, role->domain_children[i]);
63189+ } else
63190+ __insert_acl_role_label(role, role->uidgid);
63191+}
63192+
63193+static int
63194+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
63195+{
63196+ struct name_entry **curr, *nentry;
63197+ struct inodev_entry *ientry;
63198+ unsigned int len = strlen(name);
63199+ unsigned int key = full_name_hash(name, len);
63200+ unsigned int index = key % name_set.n_size;
63201+
63202+ curr = &name_set.n_hash[index];
63203+
63204+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
63205+ curr = &((*curr)->next);
63206+
63207+ if (*curr != NULL)
63208+ return 1;
63209+
63210+ nentry = acl_alloc(sizeof (struct name_entry));
63211+ if (nentry == NULL)
63212+ return 0;
63213+ ientry = acl_alloc(sizeof (struct inodev_entry));
63214+ if (ientry == NULL)
63215+ return 0;
63216+ ientry->nentry = nentry;
63217+
63218+ nentry->key = key;
63219+ nentry->name = name;
63220+ nentry->inode = inode;
63221+ nentry->device = device;
63222+ nentry->len = len;
63223+ nentry->deleted = deleted;
63224+
63225+ nentry->prev = NULL;
63226+ curr = &name_set.n_hash[index];
63227+ if (*curr != NULL)
63228+ (*curr)->prev = nentry;
63229+ nentry->next = *curr;
63230+ *curr = nentry;
63231+
63232+ /* insert us into the table searchable by inode/dev */
63233+ insert_inodev_entry(ientry);
63234+
63235+ return 1;
63236+}
63237+
63238+static void
63239+insert_acl_obj_label(struct acl_object_label *obj,
63240+ struct acl_subject_label *subj)
63241+{
63242+ unsigned int index =
63243+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
63244+ struct acl_object_label **curr;
63245+
63246+
63247+ obj->prev = NULL;
63248+
63249+ curr = &subj->obj_hash[index];
63250+ if (*curr != NULL)
63251+ (*curr)->prev = obj;
63252+
63253+ obj->next = *curr;
63254+ *curr = obj;
63255+
63256+ return;
63257+}
63258+
63259+static void
63260+insert_acl_subj_label(struct acl_subject_label *obj,
63261+ struct acl_role_label *role)
63262+{
63263+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
63264+ struct acl_subject_label **curr;
63265+
63266+ obj->prev = NULL;
63267+
63268+ curr = &role->subj_hash[index];
63269+ if (*curr != NULL)
63270+ (*curr)->prev = obj;
63271+
63272+ obj->next = *curr;
63273+ *curr = obj;
63274+
63275+ return;
63276+}
63277+
63278+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
63279+
63280+static void *
63281+create_table(__u32 * len, int elementsize)
63282+{
63283+ unsigned int table_sizes[] = {
63284+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
63285+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
63286+ 4194301, 8388593, 16777213, 33554393, 67108859
63287+ };
63288+ void *newtable = NULL;
63289+ unsigned int pwr = 0;
63290+
63291+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
63292+ table_sizes[pwr] <= *len)
63293+ pwr++;
63294+
63295+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
63296+ return newtable;
63297+
63298+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
63299+ newtable =
63300+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
63301+ else
63302+ newtable = vmalloc(table_sizes[pwr] * elementsize);
63303+
63304+ *len = table_sizes[pwr];
63305+
63306+ return newtable;
63307+}
63308+
63309+static int
63310+init_variables(const struct gr_arg *arg)
63311+{
63312+ struct task_struct *reaper = init_pid_ns.child_reaper;
63313+ unsigned int stacksize;
63314+
63315+ subj_map_set.s_size = arg->role_db.num_subjects;
63316+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
63317+ name_set.n_size = arg->role_db.num_objects;
63318+ inodev_set.i_size = arg->role_db.num_objects;
63319+
63320+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
63321+ !name_set.n_size || !inodev_set.i_size)
63322+ return 1;
63323+
63324+ if (!gr_init_uidset())
63325+ return 1;
63326+
63327+ /* set up the stack that holds allocation info */
63328+
63329+ stacksize = arg->role_db.num_pointers + 5;
63330+
63331+ if (!acl_alloc_stack_init(stacksize))
63332+ return 1;
63333+
63334+ /* grab reference for the real root dentry and vfsmount */
63335+ get_fs_root(reaper->fs, &real_root);
63336+
63337+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
63338+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
63339+#endif
63340+
63341+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
63342+ if (fakefs_obj_rw == NULL)
63343+ return 1;
63344+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
63345+
63346+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
63347+ if (fakefs_obj_rwx == NULL)
63348+ return 1;
63349+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
63350+
63351+ subj_map_set.s_hash =
63352+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
63353+ acl_role_set.r_hash =
63354+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
63355+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
63356+ inodev_set.i_hash =
63357+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
63358+
63359+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
63360+ !name_set.n_hash || !inodev_set.i_hash)
63361+ return 1;
63362+
63363+ memset(subj_map_set.s_hash, 0,
63364+ sizeof(struct subject_map *) * subj_map_set.s_size);
63365+ memset(acl_role_set.r_hash, 0,
63366+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
63367+ memset(name_set.n_hash, 0,
63368+ sizeof (struct name_entry *) * name_set.n_size);
63369+ memset(inodev_set.i_hash, 0,
63370+ sizeof (struct inodev_entry *) * inodev_set.i_size);
63371+
63372+ return 0;
63373+}
63374+
63375+/* free information not needed after startup
63376+ currently contains user->kernel pointer mappings for subjects
63377+*/
63378+
63379+static void
63380+free_init_variables(void)
63381+{
63382+ __u32 i;
63383+
63384+ if (subj_map_set.s_hash) {
63385+ for (i = 0; i < subj_map_set.s_size; i++) {
63386+ if (subj_map_set.s_hash[i]) {
63387+ kfree(subj_map_set.s_hash[i]);
63388+ subj_map_set.s_hash[i] = NULL;
63389+ }
63390+ }
63391+
63392+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
63393+ PAGE_SIZE)
63394+ kfree(subj_map_set.s_hash);
63395+ else
63396+ vfree(subj_map_set.s_hash);
63397+ }
63398+
63399+ return;
63400+}
63401+
63402+static void
63403+free_variables(void)
63404+{
63405+ struct acl_subject_label *s;
63406+ struct acl_role_label *r;
63407+ struct task_struct *task, *task2;
63408+ unsigned int x;
63409+
63410+ gr_clear_learn_entries();
63411+
63412+ read_lock(&tasklist_lock);
63413+ do_each_thread(task2, task) {
63414+ task->acl_sp_role = 0;
63415+ task->acl_role_id = 0;
63416+ task->acl = NULL;
63417+ task->role = NULL;
63418+ } while_each_thread(task2, task);
63419+ read_unlock(&tasklist_lock);
63420+
63421+ /* release the reference to the real root dentry and vfsmount */
63422+ path_put(&real_root);
63423+ memset(&real_root, 0, sizeof(real_root));
63424+
63425+ /* free all object hash tables */
63426+
63427+ FOR_EACH_ROLE_START(r)
63428+ if (r->subj_hash == NULL)
63429+ goto next_role;
63430+ FOR_EACH_SUBJECT_START(r, s, x)
63431+ if (s->obj_hash == NULL)
63432+ break;
63433+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
63434+ kfree(s->obj_hash);
63435+ else
63436+ vfree(s->obj_hash);
63437+ FOR_EACH_SUBJECT_END(s, x)
63438+ FOR_EACH_NESTED_SUBJECT_START(r, s)
63439+ if (s->obj_hash == NULL)
63440+ break;
63441+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
63442+ kfree(s->obj_hash);
63443+ else
63444+ vfree(s->obj_hash);
63445+ FOR_EACH_NESTED_SUBJECT_END(s)
63446+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
63447+ kfree(r->subj_hash);
63448+ else
63449+ vfree(r->subj_hash);
63450+ r->subj_hash = NULL;
63451+next_role:
63452+ FOR_EACH_ROLE_END(r)
63453+
63454+ acl_free_all();
63455+
63456+ if (acl_role_set.r_hash) {
63457+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
63458+ PAGE_SIZE)
63459+ kfree(acl_role_set.r_hash);
63460+ else
63461+ vfree(acl_role_set.r_hash);
63462+ }
63463+ if (name_set.n_hash) {
63464+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
63465+ PAGE_SIZE)
63466+ kfree(name_set.n_hash);
63467+ else
63468+ vfree(name_set.n_hash);
63469+ }
63470+
63471+ if (inodev_set.i_hash) {
63472+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
63473+ PAGE_SIZE)
63474+ kfree(inodev_set.i_hash);
63475+ else
63476+ vfree(inodev_set.i_hash);
63477+ }
63478+
63479+ gr_free_uidset();
63480+
63481+ memset(&name_set, 0, sizeof (struct name_db));
63482+ memset(&inodev_set, 0, sizeof (struct inodev_db));
63483+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
63484+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
63485+
63486+ default_role = NULL;
63487+ kernel_role = NULL;
63488+ role_list = NULL;
63489+
63490+ return;
63491+}
63492+
63493+static struct acl_subject_label *
63494+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
63495+
63496+static int alloc_and_copy_string(char **name, unsigned int maxlen)
63497+{
63498+ unsigned int len = strnlen_user(*name, maxlen);
63499+ char *tmp;
63500+
63501+ if (!len || len >= maxlen)
63502+ return -EINVAL;
63503+
63504+ if ((tmp = (char *) acl_alloc(len)) == NULL)
63505+ return -ENOMEM;
63506+
63507+ if (copy_from_user(tmp, *name, len))
63508+ return -EFAULT;
63509+
63510+ tmp[len-1] = '\0';
63511+ *name = tmp;
63512+
63513+ return 0;
63514+}
63515+
63516+static int
63517+copy_user_glob(struct acl_object_label *obj)
63518+{
63519+ struct acl_object_label *g_tmp, **guser;
63520+ int error;
63521+
63522+ if (obj->globbed == NULL)
63523+ return 0;
63524+
63525+ guser = &obj->globbed;
63526+ while (*guser) {
63527+ g_tmp = (struct acl_object_label *)
63528+ acl_alloc(sizeof (struct acl_object_label));
63529+ if (g_tmp == NULL)
63530+ return -ENOMEM;
63531+
63532+ if (copy_acl_object_label(g_tmp, *guser))
63533+ return -EFAULT;
63534+
63535+ error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
63536+ if (error)
63537+ return error;
63538+
63539+ *guser = g_tmp;
63540+ guser = &(g_tmp->next);
63541+ }
63542+
63543+ return 0;
63544+}
63545+
63546+static int
63547+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
63548+ struct acl_role_label *role)
63549+{
63550+ struct acl_object_label *o_tmp;
63551+ int ret;
63552+
63553+ while (userp) {
63554+ if ((o_tmp = (struct acl_object_label *)
63555+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
63556+ return -ENOMEM;
63557+
63558+ if (copy_acl_object_label(o_tmp, userp))
63559+ return -EFAULT;
63560+
63561+ userp = o_tmp->prev;
63562+
63563+ ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
63564+ if (ret)
63565+ return ret;
63566+
63567+ insert_acl_obj_label(o_tmp, subj);
63568+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
63569+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
63570+ return -ENOMEM;
63571+
63572+ ret = copy_user_glob(o_tmp);
63573+ if (ret)
63574+ return ret;
63575+
63576+ if (o_tmp->nested) {
63577+ int already_copied;
63578+
63579+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
63580+ if (IS_ERR(o_tmp->nested))
63581+ return PTR_ERR(o_tmp->nested);
63582+
63583+ /* insert into nested subject list if we haven't copied this one yet
63584+ to prevent duplicate entries */
63585+ if (!already_copied) {
63586+ o_tmp->nested->next = role->hash->first;
63587+ role->hash->first = o_tmp->nested;
63588+ }
63589+ }
63590+ }
63591+
63592+ return 0;
63593+}
63594+
63595+static __u32
63596+count_user_subjs(struct acl_subject_label *userp)
63597+{
63598+ struct acl_subject_label s_tmp;
63599+ __u32 num = 0;
63600+
63601+ while (userp) {
63602+ if (copy_acl_subject_label(&s_tmp, userp))
63603+ break;
63604+
63605+ userp = s_tmp.prev;
63606+ }
63607+
63608+ return num;
63609+}
63610+
63611+static int
63612+copy_user_allowedips(struct acl_role_label *rolep)
63613+{
63614+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
63615+
63616+ ruserip = rolep->allowed_ips;
63617+
63618+ while (ruserip) {
63619+ rlast = rtmp;
63620+
63621+ if ((rtmp = (struct role_allowed_ip *)
63622+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
63623+ return -ENOMEM;
63624+
63625+ if (copy_role_allowed_ip(rtmp, ruserip))
63626+ return -EFAULT;
63627+
63628+ ruserip = rtmp->prev;
63629+
63630+ if (!rlast) {
63631+ rtmp->prev = NULL;
63632+ rolep->allowed_ips = rtmp;
63633+ } else {
63634+ rlast->next = rtmp;
63635+ rtmp->prev = rlast;
63636+ }
63637+
63638+ if (!ruserip)
63639+ rtmp->next = NULL;
63640+ }
63641+
63642+ return 0;
63643+}
63644+
63645+static int
63646+copy_user_transitions(struct acl_role_label *rolep)
63647+{
63648+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
63649+ int error;
63650+
63651+ rusertp = rolep->transitions;
63652+
63653+ while (rusertp) {
63654+ rlast = rtmp;
63655+
63656+ if ((rtmp = (struct role_transition *)
63657+ acl_alloc(sizeof (struct role_transition))) == NULL)
63658+ return -ENOMEM;
63659+
63660+ if (copy_role_transition(rtmp, rusertp))
63661+ return -EFAULT;
63662+
63663+ rusertp = rtmp->prev;
63664+
63665+ error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
63666+ if (error)
63667+ return error;
63668+
63669+ if (!rlast) {
63670+ rtmp->prev = NULL;
63671+ rolep->transitions = rtmp;
63672+ } else {
63673+ rlast->next = rtmp;
63674+ rtmp->prev = rlast;
63675+ }
63676+
63677+ if (!rusertp)
63678+ rtmp->next = NULL;
63679+ }
63680+
63681+ return 0;
63682+}
63683+
63684+static __u32 count_user_objs(const struct acl_object_label __user *userp)
63685+{
63686+ struct acl_object_label o_tmp;
63687+ __u32 num = 0;
63688+
63689+ while (userp) {
63690+ if (copy_acl_object_label(&o_tmp, userp))
63691+ break;
63692+
63693+ userp = o_tmp.prev;
63694+ num++;
63695+ }
63696+
63697+ return num;
63698+}
63699+
63700+static struct acl_subject_label *
63701+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
63702+{
63703+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
63704+ __u32 num_objs;
63705+ struct acl_ip_label **i_tmp, *i_utmp2;
63706+ struct gr_hash_struct ghash;
63707+ struct subject_map *subjmap;
63708+ unsigned int i_num;
63709+ int err;
63710+
63711+ if (already_copied != NULL)
63712+ *already_copied = 0;
63713+
63714+ s_tmp = lookup_subject_map(userp);
63715+
63716+ /* we've already copied this subject into the kernel, just return
63717+ the reference to it, and don't copy it over again
63718+ */
63719+ if (s_tmp) {
63720+ if (already_copied != NULL)
63721+ *already_copied = 1;
63722+ return(s_tmp);
63723+ }
63724+
63725+ if ((s_tmp = (struct acl_subject_label *)
63726+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
63727+ return ERR_PTR(-ENOMEM);
63728+
63729+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
63730+ if (subjmap == NULL)
63731+ return ERR_PTR(-ENOMEM);
63732+
63733+ subjmap->user = userp;
63734+ subjmap->kernel = s_tmp;
63735+ insert_subj_map_entry(subjmap);
63736+
63737+ if (copy_acl_subject_label(s_tmp, userp))
63738+ return ERR_PTR(-EFAULT);
63739+
63740+ err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
63741+ if (err)
63742+ return ERR_PTR(err);
63743+
63744+ if (!strcmp(s_tmp->filename, "/"))
63745+ role->root_label = s_tmp;
63746+
63747+ if (copy_gr_hash_struct(&ghash, s_tmp->hash))
63748+ return ERR_PTR(-EFAULT);
63749+
63750+ /* copy user and group transition tables */
63751+
63752+ if (s_tmp->user_trans_num) {
63753+ uid_t *uidlist;
63754+
63755+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
63756+ if (uidlist == NULL)
63757+ return ERR_PTR(-ENOMEM);
63758+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
63759+ return ERR_PTR(-EFAULT);
63760+
63761+ s_tmp->user_transitions = uidlist;
63762+ }
63763+
63764+ if (s_tmp->group_trans_num) {
63765+ gid_t *gidlist;
63766+
63767+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
63768+ if (gidlist == NULL)
63769+ return ERR_PTR(-ENOMEM);
63770+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
63771+ return ERR_PTR(-EFAULT);
63772+
63773+ s_tmp->group_transitions = gidlist;
63774+ }
63775+
63776+ /* set up object hash table */
63777+ num_objs = count_user_objs(ghash.first);
63778+
63779+ s_tmp->obj_hash_size = num_objs;
63780+ s_tmp->obj_hash =
63781+ (struct acl_object_label **)
63782+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
63783+
63784+ if (!s_tmp->obj_hash)
63785+ return ERR_PTR(-ENOMEM);
63786+
63787+ memset(s_tmp->obj_hash, 0,
63788+ s_tmp->obj_hash_size *
63789+ sizeof (struct acl_object_label *));
63790+
63791+ /* add in objects */
63792+ err = copy_user_objs(ghash.first, s_tmp, role);
63793+
63794+ if (err)
63795+ return ERR_PTR(err);
63796+
63797+ /* set pointer for parent subject */
63798+ if (s_tmp->parent_subject) {
63799+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
63800+
63801+ if (IS_ERR(s_tmp2))
63802+ return s_tmp2;
63803+
63804+ s_tmp->parent_subject = s_tmp2;
63805+ }
63806+
63807+ /* add in ip acls */
63808+
63809+ if (!s_tmp->ip_num) {
63810+ s_tmp->ips = NULL;
63811+ goto insert;
63812+ }
63813+
63814+ i_tmp =
63815+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
63816+ sizeof (struct acl_ip_label *));
63817+
63818+ if (!i_tmp)
63819+ return ERR_PTR(-ENOMEM);
63820+
63821+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
63822+ *(i_tmp + i_num) =
63823+ (struct acl_ip_label *)
63824+ acl_alloc(sizeof (struct acl_ip_label));
63825+ if (!*(i_tmp + i_num))
63826+ return ERR_PTR(-ENOMEM);
63827+
63828+ if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
63829+ return ERR_PTR(-EFAULT);
63830+
63831+ if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
63832+ return ERR_PTR(-EFAULT);
63833+
63834+ if ((*(i_tmp + i_num))->iface == NULL)
63835+ continue;
63836+
63837+ err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
63838+ if (err)
63839+ return ERR_PTR(err);
63840+ }
63841+
63842+ s_tmp->ips = i_tmp;
63843+
63844+insert:
63845+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
63846+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
63847+ return ERR_PTR(-ENOMEM);
63848+
63849+ return s_tmp;
63850+}
63851+
63852+static int
63853+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
63854+{
63855+ struct acl_subject_label s_pre;
63856+ struct acl_subject_label * ret;
63857+ int err;
63858+
63859+ while (userp) {
63860+ if (copy_acl_subject_label(&s_pre, userp))
63861+ return -EFAULT;
63862+
63863+ ret = do_copy_user_subj(userp, role, NULL);
63864+
63865+ err = PTR_ERR(ret);
63866+ if (IS_ERR(ret))
63867+ return err;
63868+
63869+ insert_acl_subj_label(ret, role);
63870+
63871+ userp = s_pre.prev;
63872+ }
63873+
63874+ return 0;
63875+}
63876+
63877+static int
63878+copy_user_acl(struct gr_arg *arg)
63879+{
63880+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
63881+ struct acl_subject_label *subj_list;
63882+ struct sprole_pw *sptmp;
63883+ struct gr_hash_struct *ghash;
63884+ uid_t *domainlist;
63885+ unsigned int r_num;
63886+ int err = 0;
63887+ __u16 i;
63888+ __u32 num_subjs;
63889+
63890+ /* we need a default and kernel role */
63891+ if (arg->role_db.num_roles < 2)
63892+ return -EINVAL;
63893+
63894+ /* copy special role authentication info from userspace */
63895+
63896+ num_sprole_pws = arg->num_sprole_pws;
63897+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
63898+
63899+ if (!acl_special_roles && num_sprole_pws)
63900+ return -ENOMEM;
63901+
63902+ for (i = 0; i < num_sprole_pws; i++) {
63903+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
63904+ if (!sptmp)
63905+ return -ENOMEM;
63906+ if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
63907+ return -EFAULT;
63908+
63909+ err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
63910+ if (err)
63911+ return err;
63912+
63913+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
63914+ printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
63915+#endif
63916+
63917+ acl_special_roles[i] = sptmp;
63918+ }
63919+
63920+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
63921+
63922+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
63923+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
63924+
63925+ if (!r_tmp)
63926+ return -ENOMEM;
63927+
63928+ if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
63929+ return -EFAULT;
63930+
63931+ if (copy_acl_role_label(r_tmp, r_utmp2))
63932+ return -EFAULT;
63933+
63934+ err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
63935+ if (err)
63936+ return err;
63937+
63938+ if (!strcmp(r_tmp->rolename, "default")
63939+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
63940+ default_role = r_tmp;
63941+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
63942+ kernel_role = r_tmp;
63943+ }
63944+
63945+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
63946+ return -ENOMEM;
63947+
63948+ if (copy_gr_hash_struct(ghash, r_tmp->hash))
63949+ return -EFAULT;
63950+
63951+ r_tmp->hash = ghash;
63952+
63953+ num_subjs = count_user_subjs(r_tmp->hash->first);
63954+
63955+ r_tmp->subj_hash_size = num_subjs;
63956+ r_tmp->subj_hash =
63957+ (struct acl_subject_label **)
63958+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
63959+
63960+ if (!r_tmp->subj_hash)
63961+ return -ENOMEM;
63962+
63963+ err = copy_user_allowedips(r_tmp);
63964+ if (err)
63965+ return err;
63966+
63967+ /* copy domain info */
63968+ if (r_tmp->domain_children != NULL) {
63969+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
63970+ if (domainlist == NULL)
63971+ return -ENOMEM;
63972+
63973+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
63974+ return -EFAULT;
63975+
63976+ r_tmp->domain_children = domainlist;
63977+ }
63978+
63979+ err = copy_user_transitions(r_tmp);
63980+ if (err)
63981+ return err;
63982+
63983+ memset(r_tmp->subj_hash, 0,
63984+ r_tmp->subj_hash_size *
63985+ sizeof (struct acl_subject_label *));
63986+
63987+ /* acquire the list of subjects, then NULL out
63988+ the list prior to parsing the subjects for this role,
63989+ as during this parsing the list is replaced with a list
63990+ of *nested* subjects for the role
63991+ */
63992+ subj_list = r_tmp->hash->first;
63993+
63994+ /* set nested subject list to null */
63995+ r_tmp->hash->first = NULL;
63996+
63997+ err = copy_user_subjs(subj_list, r_tmp);
63998+
63999+ if (err)
64000+ return err;
64001+
64002+ insert_acl_role_label(r_tmp);
64003+ }
64004+
64005+ if (default_role == NULL || kernel_role == NULL)
64006+ return -EINVAL;
64007+
64008+ return err;
64009+}
64010+
64011+static int
64012+gracl_init(struct gr_arg *args)
64013+{
64014+ int error = 0;
64015+
64016+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
64017+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
64018+
64019+ if (init_variables(args)) {
64020+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
64021+ error = -ENOMEM;
64022+ free_variables();
64023+ goto out;
64024+ }
64025+
64026+ error = copy_user_acl(args);
64027+ free_init_variables();
64028+ if (error) {
64029+ free_variables();
64030+ goto out;
64031+ }
64032+
64033+ if ((error = gr_set_acls(0))) {
64034+ free_variables();
64035+ goto out;
64036+ }
64037+
64038+ pax_open_kernel();
64039+ gr_status |= GR_READY;
64040+ pax_close_kernel();
64041+
64042+ out:
64043+ return error;
64044+}
64045+
64046+/* derived from glibc fnmatch() 0: match, 1: no match*/
64047+
64048+static int
64049+glob_match(const char *p, const char *n)
64050+{
64051+ char c;
64052+
64053+ while ((c = *p++) != '\0') {
64054+ switch (c) {
64055+ case '?':
64056+ if (*n == '\0')
64057+ return 1;
64058+ else if (*n == '/')
64059+ return 1;
64060+ break;
64061+ case '\\':
64062+ if (*n != c)
64063+ return 1;
64064+ break;
64065+ case '*':
64066+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
64067+ if (*n == '/')
64068+ return 1;
64069+ else if (c == '?') {
64070+ if (*n == '\0')
64071+ return 1;
64072+ else
64073+ ++n;
64074+ }
64075+ }
64076+ if (c == '\0') {
64077+ return 0;
64078+ } else {
64079+ const char *endp;
64080+
64081+ if ((endp = strchr(n, '/')) == NULL)
64082+ endp = n + strlen(n);
64083+
64084+ if (c == '[') {
64085+ for (--p; n < endp; ++n)
64086+ if (!glob_match(p, n))
64087+ return 0;
64088+ } else if (c == '/') {
64089+ while (*n != '\0' && *n != '/')
64090+ ++n;
64091+ if (*n == '/' && !glob_match(p, n + 1))
64092+ return 0;
64093+ } else {
64094+ for (--p; n < endp; ++n)
64095+ if (*n == c && !glob_match(p, n))
64096+ return 0;
64097+ }
64098+
64099+ return 1;
64100+ }
64101+ case '[':
64102+ {
64103+ int not;
64104+ char cold;
64105+
64106+ if (*n == '\0' || *n == '/')
64107+ return 1;
64108+
64109+ not = (*p == '!' || *p == '^');
64110+ if (not)
64111+ ++p;
64112+
64113+ c = *p++;
64114+ for (;;) {
64115+ unsigned char fn = (unsigned char)*n;
64116+
64117+ if (c == '\0')
64118+ return 1;
64119+ else {
64120+ if (c == fn)
64121+ goto matched;
64122+ cold = c;
64123+ c = *p++;
64124+
64125+ if (c == '-' && *p != ']') {
64126+ unsigned char cend = *p++;
64127+
64128+ if (cend == '\0')
64129+ return 1;
64130+
64131+ if (cold <= fn && fn <= cend)
64132+ goto matched;
64133+
64134+ c = *p++;
64135+ }
64136+ }
64137+
64138+ if (c == ']')
64139+ break;
64140+ }
64141+ if (!not)
64142+ return 1;
64143+ break;
64144+ matched:
64145+ while (c != ']') {
64146+ if (c == '\0')
64147+ return 1;
64148+
64149+ c = *p++;
64150+ }
64151+ if (not)
64152+ return 1;
64153+ }
64154+ break;
64155+ default:
64156+ if (c != *n)
64157+ return 1;
64158+ }
64159+
64160+ ++n;
64161+ }
64162+
64163+ if (*n == '\0')
64164+ return 0;
64165+
64166+ if (*n == '/')
64167+ return 0;
64168+
64169+ return 1;
64170+}
64171+
64172+static struct acl_object_label *
64173+chk_glob_label(struct acl_object_label *globbed,
64174+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
64175+{
64176+ struct acl_object_label *tmp;
64177+
64178+ if (*path == NULL)
64179+ *path = gr_to_filename_nolock(dentry, mnt);
64180+
64181+ tmp = globbed;
64182+
64183+ while (tmp) {
64184+ if (!glob_match(tmp->filename, *path))
64185+ return tmp;
64186+ tmp = tmp->next;
64187+ }
64188+
64189+ return NULL;
64190+}
64191+
64192+static struct acl_object_label *
64193+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
64194+ const ino_t curr_ino, const dev_t curr_dev,
64195+ const struct acl_subject_label *subj, char **path, const int checkglob)
64196+{
64197+ struct acl_subject_label *tmpsubj;
64198+ struct acl_object_label *retval;
64199+ struct acl_object_label *retval2;
64200+
64201+ tmpsubj = (struct acl_subject_label *) subj;
64202+ read_lock(&gr_inode_lock);
64203+ do {
64204+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
64205+ if (retval) {
64206+ if (checkglob && retval->globbed) {
64207+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
64208+ if (retval2)
64209+ retval = retval2;
64210+ }
64211+ break;
64212+ }
64213+ } while ((tmpsubj = tmpsubj->parent_subject));
64214+ read_unlock(&gr_inode_lock);
64215+
64216+ return retval;
64217+}
64218+
64219+static __inline__ struct acl_object_label *
64220+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
64221+ struct dentry *curr_dentry,
64222+ const struct acl_subject_label *subj, char **path, const int checkglob)
64223+{
64224+ int newglob = checkglob;
64225+ ino_t inode;
64226+ dev_t device;
64227+
64228+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
64229+ as we don't want a / * rule to match instead of the / object
64230+ don't do this for create lookups that call this function though, since they're looking up
64231+ on the parent and thus need globbing checks on all paths
64232+ */
64233+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
64234+ newglob = GR_NO_GLOB;
64235+
64236+ spin_lock(&curr_dentry->d_lock);
64237+ inode = curr_dentry->d_inode->i_ino;
64238+ device = __get_dev(curr_dentry);
64239+ spin_unlock(&curr_dentry->d_lock);
64240+
64241+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
64242+}
64243+
64244+#ifdef CONFIG_HUGETLBFS
64245+static inline bool
64246+is_hugetlbfs_mnt(const struct vfsmount *mnt)
64247+{
64248+ int i;
64249+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
64250+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
64251+ return true;
64252+ }
64253+
64254+ return false;
64255+}
64256+#endif
64257+
64258+static struct acl_object_label *
64259+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64260+ const struct acl_subject_label *subj, char *path, const int checkglob)
64261+{
64262+ struct dentry *dentry = (struct dentry *) l_dentry;
64263+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
64264+ struct mount *real_mnt = real_mount(mnt);
64265+ struct acl_object_label *retval;
64266+ struct dentry *parent;
64267+
64268+ br_read_lock(&vfsmount_lock);
64269+ write_seqlock(&rename_lock);
64270+
64271+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
64272+#ifdef CONFIG_NET
64273+ mnt == sock_mnt ||
64274+#endif
64275+#ifdef CONFIG_HUGETLBFS
64276+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
64277+#endif
64278+ /* ignore Eric Biederman */
64279+ IS_PRIVATE(l_dentry->d_inode))) {
64280+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
64281+ goto out;
64282+ }
64283+
64284+ for (;;) {
64285+ if (dentry == real_root.dentry && mnt == real_root.mnt)
64286+ break;
64287+
64288+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
64289+ if (!mnt_has_parent(real_mnt))
64290+ break;
64291+
64292+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
64293+ if (retval != NULL)
64294+ goto out;
64295+
64296+ dentry = real_mnt->mnt_mountpoint;
64297+ real_mnt = real_mnt->mnt_parent;
64298+ mnt = &real_mnt->mnt;
64299+ continue;
64300+ }
64301+
64302+ parent = dentry->d_parent;
64303+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
64304+ if (retval != NULL)
64305+ goto out;
64306+
64307+ dentry = parent;
64308+ }
64309+
64310+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
64311+
64312+ /* real_root is pinned so we don't have to hold a reference */
64313+ if (retval == NULL)
64314+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
64315+out:
64316+ write_sequnlock(&rename_lock);
64317+ br_read_unlock(&vfsmount_lock);
64318+
64319+ BUG_ON(retval == NULL);
64320+
64321+ return retval;
64322+}
64323+
64324+static __inline__ struct acl_object_label *
64325+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64326+ const struct acl_subject_label *subj)
64327+{
64328+ char *path = NULL;
64329+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
64330+}
64331+
64332+static __inline__ struct acl_object_label *
64333+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64334+ const struct acl_subject_label *subj)
64335+{
64336+ char *path = NULL;
64337+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
64338+}
64339+
64340+static __inline__ struct acl_object_label *
64341+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64342+ const struct acl_subject_label *subj, char *path)
64343+{
64344+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
64345+}
64346+
64347+static struct acl_subject_label *
64348+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
64349+ const struct acl_role_label *role)
64350+{
64351+ struct dentry *dentry = (struct dentry *) l_dentry;
64352+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
64353+ struct mount *real_mnt = real_mount(mnt);
64354+ struct acl_subject_label *retval;
64355+ struct dentry *parent;
64356+
64357+ br_read_lock(&vfsmount_lock);
64358+ write_seqlock(&rename_lock);
64359+
64360+ for (;;) {
64361+ if (dentry == real_root.dentry && mnt == real_root.mnt)
64362+ break;
64363+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
64364+ if (!mnt_has_parent(real_mnt))
64365+ break;
64366+
64367+ spin_lock(&dentry->d_lock);
64368+ read_lock(&gr_inode_lock);
64369+ retval =
64370+ lookup_acl_subj_label(dentry->d_inode->i_ino,
64371+ __get_dev(dentry), role);
64372+ read_unlock(&gr_inode_lock);
64373+ spin_unlock(&dentry->d_lock);
64374+ if (retval != NULL)
64375+ goto out;
64376+
64377+ dentry = real_mnt->mnt_mountpoint;
64378+ real_mnt = real_mnt->mnt_parent;
64379+ mnt = &real_mnt->mnt;
64380+ continue;
64381+ }
64382+
64383+ spin_lock(&dentry->d_lock);
64384+ read_lock(&gr_inode_lock);
64385+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
64386+ __get_dev(dentry), role);
64387+ read_unlock(&gr_inode_lock);
64388+ parent = dentry->d_parent;
64389+ spin_unlock(&dentry->d_lock);
64390+
64391+ if (retval != NULL)
64392+ goto out;
64393+
64394+ dentry = parent;
64395+ }
64396+
64397+ spin_lock(&dentry->d_lock);
64398+ read_lock(&gr_inode_lock);
64399+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
64400+ __get_dev(dentry), role);
64401+ read_unlock(&gr_inode_lock);
64402+ spin_unlock(&dentry->d_lock);
64403+
64404+ if (unlikely(retval == NULL)) {
64405+ /* real_root is pinned, we don't need to hold a reference */
64406+ read_lock(&gr_inode_lock);
64407+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
64408+ __get_dev(real_root.dentry), role);
64409+ read_unlock(&gr_inode_lock);
64410+ }
64411+out:
64412+ write_sequnlock(&rename_lock);
64413+ br_read_unlock(&vfsmount_lock);
64414+
64415+ BUG_ON(retval == NULL);
64416+
64417+ return retval;
64418+}
64419+
64420+static void
64421+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
64422+{
64423+ struct task_struct *task = current;
64424+ const struct cred *cred = current_cred();
64425+
64426+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
64427+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
64428+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
64429+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
64430+
64431+ return;
64432+}
64433+
64434+static void
64435+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
64436+{
64437+ struct task_struct *task = current;
64438+ const struct cred *cred = current_cred();
64439+
64440+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
64441+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
64442+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
64443+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
64444+
64445+ return;
64446+}
64447+
64448+static void
64449+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
64450+{
64451+ struct task_struct *task = current;
64452+ const struct cred *cred = current_cred();
64453+
64454+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
64455+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
64456+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
64457+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
64458+
64459+ return;
64460+}
64461+
64462+__u32
64463+gr_search_file(const struct dentry * dentry, const __u32 mode,
64464+ const struct vfsmount * mnt)
64465+{
64466+ __u32 retval = mode;
64467+ struct acl_subject_label *curracl;
64468+ struct acl_object_label *currobj;
64469+
64470+ if (unlikely(!(gr_status & GR_READY)))
64471+ return (mode & ~GR_AUDITS);
64472+
64473+ curracl = current->acl;
64474+
64475+ currobj = chk_obj_label(dentry, mnt, curracl);
64476+ retval = currobj->mode & mode;
64477+
64478+ /* if we're opening a specified transfer file for writing
64479+ (e.g. /dev/initctl), then transfer our role to init
64480+ */
64481+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
64482+ current->role->roletype & GR_ROLE_PERSIST)) {
64483+ struct task_struct *task = init_pid_ns.child_reaper;
64484+
64485+ if (task->role != current->role) {
64486+ task->acl_sp_role = 0;
64487+ task->acl_role_id = current->acl_role_id;
64488+ task->role = current->role;
64489+ rcu_read_lock();
64490+ read_lock(&grsec_exec_file_lock);
64491+ gr_apply_subject_to_task(task);
64492+ read_unlock(&grsec_exec_file_lock);
64493+ rcu_read_unlock();
64494+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
64495+ }
64496+ }
64497+
64498+ if (unlikely
64499+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
64500+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
64501+ __u32 new_mode = mode;
64502+
64503+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
64504+
64505+ retval = new_mode;
64506+
64507+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
64508+ new_mode |= GR_INHERIT;
64509+
64510+ if (!(mode & GR_NOLEARN))
64511+ gr_log_learn(dentry, mnt, new_mode);
64512+ }
64513+
64514+ return retval;
64515+}
64516+
64517+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
64518+ const struct dentry *parent,
64519+ const struct vfsmount *mnt)
64520+{
64521+ struct name_entry *match;
64522+ struct acl_object_label *matchpo;
64523+ struct acl_subject_label *curracl;
64524+ char *path;
64525+
64526+ if (unlikely(!(gr_status & GR_READY)))
64527+ return NULL;
64528+
64529+ preempt_disable();
64530+ path = gr_to_filename_rbac(new_dentry, mnt);
64531+ match = lookup_name_entry_create(path);
64532+
64533+ curracl = current->acl;
64534+
64535+ if (match) {
64536+ read_lock(&gr_inode_lock);
64537+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
64538+ read_unlock(&gr_inode_lock);
64539+
64540+ if (matchpo) {
64541+ preempt_enable();
64542+ return matchpo;
64543+ }
64544+ }
64545+
64546+ // lookup parent
64547+
64548+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
64549+
64550+ preempt_enable();
64551+ return matchpo;
64552+}
64553+
64554+__u32
64555+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
64556+ const struct vfsmount * mnt, const __u32 mode)
64557+{
64558+ struct acl_object_label *matchpo;
64559+ __u32 retval;
64560+
64561+ if (unlikely(!(gr_status & GR_READY)))
64562+ return (mode & ~GR_AUDITS);
64563+
64564+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
64565+
64566+ retval = matchpo->mode & mode;
64567+
64568+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
64569+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
64570+ __u32 new_mode = mode;
64571+
64572+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
64573+
64574+ gr_log_learn(new_dentry, mnt, new_mode);
64575+ return new_mode;
64576+ }
64577+
64578+ return retval;
64579+}
64580+
64581+__u32
64582+gr_check_link(const struct dentry * new_dentry,
64583+ const struct dentry * parent_dentry,
64584+ const struct vfsmount * parent_mnt,
64585+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
64586+{
64587+ struct acl_object_label *obj;
64588+ __u32 oldmode, newmode;
64589+ __u32 needmode;
64590+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
64591+ GR_DELETE | GR_INHERIT;
64592+
64593+ if (unlikely(!(gr_status & GR_READY)))
64594+ return (GR_CREATE | GR_LINK);
64595+
64596+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
64597+ oldmode = obj->mode;
64598+
64599+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
64600+ newmode = obj->mode;
64601+
64602+ needmode = newmode & checkmodes;
64603+
64604+ // old name for hardlink must have at least the permissions of the new name
64605+ if ((oldmode & needmode) != needmode)
64606+ goto bad;
64607+
64608+ // if old name had restrictions/auditing, make sure the new name does as well
64609+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
64610+
64611+ // don't allow hardlinking of suid/sgid/fcapped files without permission
64612+ if (is_privileged_binary(old_dentry))
64613+ needmode |= GR_SETID;
64614+
64615+ if ((newmode & needmode) != needmode)
64616+ goto bad;
64617+
64618+ // enforce minimum permissions
64619+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
64620+ return newmode;
64621+bad:
64622+ needmode = oldmode;
64623+ if (is_privileged_binary(old_dentry))
64624+ needmode |= GR_SETID;
64625+
64626+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
64627+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
64628+ return (GR_CREATE | GR_LINK);
64629+ } else if (newmode & GR_SUPPRESS)
64630+ return GR_SUPPRESS;
64631+ else
64632+ return 0;
64633+}
64634+
64635+int
64636+gr_check_hidden_task(const struct task_struct *task)
64637+{
64638+ if (unlikely(!(gr_status & GR_READY)))
64639+ return 0;
64640+
64641+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
64642+ return 1;
64643+
64644+ return 0;
64645+}
64646+
64647+int
64648+gr_check_protected_task(const struct task_struct *task)
64649+{
64650+ if (unlikely(!(gr_status & GR_READY) || !task))
64651+ return 0;
64652+
64653+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
64654+ task->acl != current->acl)
64655+ return 1;
64656+
64657+ return 0;
64658+}
64659+
64660+int
64661+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
64662+{
64663+ struct task_struct *p;
64664+ int ret = 0;
64665+
64666+ if (unlikely(!(gr_status & GR_READY) || !pid))
64667+ return ret;
64668+
64669+ read_lock(&tasklist_lock);
64670+ do_each_pid_task(pid, type, p) {
64671+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
64672+ p->acl != current->acl) {
64673+ ret = 1;
64674+ goto out;
64675+ }
64676+ } while_each_pid_task(pid, type, p);
64677+out:
64678+ read_unlock(&tasklist_lock);
64679+
64680+ return ret;
64681+}
64682+
64683+void
64684+gr_copy_label(struct task_struct *tsk)
64685+{
64686+ tsk->signal->used_accept = 0;
64687+ tsk->acl_sp_role = 0;
64688+ tsk->acl_role_id = current->acl_role_id;
64689+ tsk->acl = current->acl;
64690+ tsk->role = current->role;
64691+ tsk->signal->curr_ip = current->signal->curr_ip;
64692+ tsk->signal->saved_ip = current->signal->saved_ip;
64693+ if (current->exec_file)
64694+ get_file(current->exec_file);
64695+ tsk->exec_file = current->exec_file;
64696+ tsk->is_writable = current->is_writable;
64697+ if (unlikely(current->signal->used_accept)) {
64698+ current->signal->curr_ip = 0;
64699+ current->signal->saved_ip = 0;
64700+ }
64701+
64702+ return;
64703+}
64704+
64705+static void
64706+gr_set_proc_res(struct task_struct *task)
64707+{
64708+ struct acl_subject_label *proc;
64709+ unsigned short i;
64710+
64711+ proc = task->acl;
64712+
64713+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
64714+ return;
64715+
64716+ for (i = 0; i < RLIM_NLIMITS; i++) {
64717+ if (!(proc->resmask & (1U << i)))
64718+ continue;
64719+
64720+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
64721+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
64722+
64723+ if (i == RLIMIT_CPU)
64724+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
64725+ }
64726+
64727+ return;
64728+}
64729+
64730+extern int gr_process_kernel_setuid_ban(struct user_struct *user);
64731+
64732+int
64733+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
64734+{
64735+ unsigned int i;
64736+ __u16 num;
64737+ uid_t *uidlist;
64738+ uid_t curuid;
64739+ int realok = 0;
64740+ int effectiveok = 0;
64741+ int fsok = 0;
64742+ uid_t globalreal, globaleffective, globalfs;
64743+
64744+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
64745+ struct user_struct *user;
64746+
64747+ if (!uid_valid(real))
64748+ goto skipit;
64749+
64750+ /* find user based on global namespace */
64751+
64752+ globalreal = GR_GLOBAL_UID(real);
64753+
64754+ user = find_user(make_kuid(&init_user_ns, globalreal));
64755+ if (user == NULL)
64756+ goto skipit;
64757+
64758+ if (gr_process_kernel_setuid_ban(user)) {
64759+ /* for find_user */
64760+ free_uid(user);
64761+ return 1;
64762+ }
64763+
64764+ /* for find_user */
64765+ free_uid(user);
64766+
64767+skipit:
64768+#endif
64769+
64770+ if (unlikely(!(gr_status & GR_READY)))
64771+ return 0;
64772+
64773+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
64774+ gr_log_learn_uid_change(real, effective, fs);
64775+
64776+ num = current->acl->user_trans_num;
64777+ uidlist = current->acl->user_transitions;
64778+
64779+ if (uidlist == NULL)
64780+ return 0;
64781+
64782+ if (!uid_valid(real)) {
64783+ realok = 1;
64784+ globalreal = (uid_t)-1;
64785+ } else {
64786+ globalreal = GR_GLOBAL_UID(real);
64787+ }
64788+ if (!uid_valid(effective)) {
64789+ effectiveok = 1;
64790+ globaleffective = (uid_t)-1;
64791+ } else {
64792+ globaleffective = GR_GLOBAL_UID(effective);
64793+ }
64794+ if (!uid_valid(fs)) {
64795+ fsok = 1;
64796+ globalfs = (uid_t)-1;
64797+ } else {
64798+ globalfs = GR_GLOBAL_UID(fs);
64799+ }
64800+
64801+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
64802+ for (i = 0; i < num; i++) {
64803+ curuid = uidlist[i];
64804+ if (globalreal == curuid)
64805+ realok = 1;
64806+ if (globaleffective == curuid)
64807+ effectiveok = 1;
64808+ if (globalfs == curuid)
64809+ fsok = 1;
64810+ }
64811+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
64812+ for (i = 0; i < num; i++) {
64813+ curuid = uidlist[i];
64814+ if (globalreal == curuid)
64815+ break;
64816+ if (globaleffective == curuid)
64817+ break;
64818+ if (globalfs == curuid)
64819+ break;
64820+ }
64821+ /* not in deny list */
64822+ if (i == num) {
64823+ realok = 1;
64824+ effectiveok = 1;
64825+ fsok = 1;
64826+ }
64827+ }
64828+
64829+ if (realok && effectiveok && fsok)
64830+ return 0;
64831+ else {
64832+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
64833+ return 1;
64834+ }
64835+}
64836+
64837+int
64838+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
64839+{
64840+ unsigned int i;
64841+ __u16 num;
64842+ gid_t *gidlist;
64843+ gid_t curgid;
64844+ int realok = 0;
64845+ int effectiveok = 0;
64846+ int fsok = 0;
64847+ gid_t globalreal, globaleffective, globalfs;
64848+
64849+ if (unlikely(!(gr_status & GR_READY)))
64850+ return 0;
64851+
64852+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
64853+ gr_log_learn_gid_change(real, effective, fs);
64854+
64855+ num = current->acl->group_trans_num;
64856+ gidlist = current->acl->group_transitions;
64857+
64858+ if (gidlist == NULL)
64859+ return 0;
64860+
64861+ if (!gid_valid(real)) {
64862+ realok = 1;
64863+ globalreal = (gid_t)-1;
64864+ } else {
64865+ globalreal = GR_GLOBAL_GID(real);
64866+ }
64867+ if (!gid_valid(effective)) {
64868+ effectiveok = 1;
64869+ globaleffective = (gid_t)-1;
64870+ } else {
64871+ globaleffective = GR_GLOBAL_GID(effective);
64872+ }
64873+ if (!gid_valid(fs)) {
64874+ fsok = 1;
64875+ globalfs = (gid_t)-1;
64876+ } else {
64877+ globalfs = GR_GLOBAL_GID(fs);
64878+ }
64879+
64880+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
64881+ for (i = 0; i < num; i++) {
64882+ curgid = gidlist[i];
64883+ if (globalreal == curgid)
64884+ realok = 1;
64885+ if (globaleffective == curgid)
64886+ effectiveok = 1;
64887+ if (globalfs == curgid)
64888+ fsok = 1;
64889+ }
64890+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
64891+ for (i = 0; i < num; i++) {
64892+ curgid = gidlist[i];
64893+ if (globalreal == curgid)
64894+ break;
64895+ if (globaleffective == curgid)
64896+ break;
64897+ if (globalfs == curgid)
64898+ break;
64899+ }
64900+ /* not in deny list */
64901+ if (i == num) {
64902+ realok = 1;
64903+ effectiveok = 1;
64904+ fsok = 1;
64905+ }
64906+ }
64907+
64908+ if (realok && effectiveok && fsok)
64909+ return 0;
64910+ else {
64911+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
64912+ return 1;
64913+ }
64914+}
64915+
64916+extern int gr_acl_is_capable(const int cap);
64917+
64918+void
64919+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
64920+{
64921+ struct acl_role_label *role = task->role;
64922+ struct acl_subject_label *subj = NULL;
64923+ struct acl_object_label *obj;
64924+ struct file *filp;
64925+ uid_t uid;
64926+ gid_t gid;
64927+
64928+ if (unlikely(!(gr_status & GR_READY)))
64929+ return;
64930+
64931+ uid = GR_GLOBAL_UID(kuid);
64932+ gid = GR_GLOBAL_GID(kgid);
64933+
64934+ filp = task->exec_file;
64935+
64936+ /* kernel process, we'll give them the kernel role */
64937+ if (unlikely(!filp)) {
64938+ task->role = kernel_role;
64939+ task->acl = kernel_role->root_label;
64940+ return;
64941+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
64942+ role = lookup_acl_role_label(task, uid, gid);
64943+
64944+ /* don't change the role if we're not a privileged process */
64945+ if (role && task->role != role &&
64946+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
64947+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
64948+ return;
64949+
64950+ /* perform subject lookup in possibly new role
64951+ we can use this result below in the case where role == task->role
64952+ */
64953+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
64954+
64955+ /* if we changed uid/gid, but result in the same role
64956+ and are using inheritance, don't lose the inherited subject
64957+ if current subject is other than what normal lookup
64958+ would result in, we arrived via inheritance, don't
64959+ lose subject
64960+ */
64961+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
64962+ (subj == task->acl)))
64963+ task->acl = subj;
64964+
64965+ task->role = role;
64966+
64967+ task->is_writable = 0;
64968+
64969+ /* ignore additional mmap checks for processes that are writable
64970+ by the default ACL */
64971+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
64972+ if (unlikely(obj->mode & GR_WRITE))
64973+ task->is_writable = 1;
64974+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
64975+ if (unlikely(obj->mode & GR_WRITE))
64976+ task->is_writable = 1;
64977+
64978+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
64979+ 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);
64980+#endif
64981+
64982+ gr_set_proc_res(task);
64983+
64984+ return;
64985+}
64986+
64987+int
64988+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
64989+ const int unsafe_flags)
64990+{
64991+ struct task_struct *task = current;
64992+ struct acl_subject_label *newacl;
64993+ struct acl_object_label *obj;
64994+ __u32 retmode;
64995+
64996+ if (unlikely(!(gr_status & GR_READY)))
64997+ return 0;
64998+
64999+ newacl = chk_subj_label(dentry, mnt, task->role);
65000+
65001+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
65002+ did an exec
65003+ */
65004+ rcu_read_lock();
65005+ read_lock(&tasklist_lock);
65006+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
65007+ (task->parent->acl->mode & GR_POVERRIDE))) {
65008+ read_unlock(&tasklist_lock);
65009+ rcu_read_unlock();
65010+ goto skip_check;
65011+ }
65012+ read_unlock(&tasklist_lock);
65013+ rcu_read_unlock();
65014+
65015+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
65016+ !(task->role->roletype & GR_ROLE_GOD) &&
65017+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
65018+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
65019+ if (unsafe_flags & LSM_UNSAFE_SHARE)
65020+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
65021+ else
65022+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
65023+ return -EACCES;
65024+ }
65025+
65026+skip_check:
65027+
65028+ obj = chk_obj_label(dentry, mnt, task->acl);
65029+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
65030+
65031+ if (!(task->acl->mode & GR_INHERITLEARN) &&
65032+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
65033+ if (obj->nested)
65034+ task->acl = obj->nested;
65035+ else
65036+ task->acl = newacl;
65037+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
65038+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
65039+
65040+ task->is_writable = 0;
65041+
65042+ /* ignore additional mmap checks for processes that are writable
65043+ by the default ACL */
65044+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
65045+ if (unlikely(obj->mode & GR_WRITE))
65046+ task->is_writable = 1;
65047+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
65048+ if (unlikely(obj->mode & GR_WRITE))
65049+ task->is_writable = 1;
65050+
65051+ gr_set_proc_res(task);
65052+
65053+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
65054+ 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);
65055+#endif
65056+ return 0;
65057+}
65058+
65059+/* always called with valid inodev ptr */
65060+static void
65061+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
65062+{
65063+ struct acl_object_label *matchpo;
65064+ struct acl_subject_label *matchps;
65065+ struct acl_subject_label *subj;
65066+ struct acl_role_label *role;
65067+ unsigned int x;
65068+
65069+ FOR_EACH_ROLE_START(role)
65070+ FOR_EACH_SUBJECT_START(role, subj, x)
65071+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
65072+ matchpo->mode |= GR_DELETED;
65073+ FOR_EACH_SUBJECT_END(subj,x)
65074+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
65075+ /* nested subjects aren't in the role's subj_hash table */
65076+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
65077+ matchpo->mode |= GR_DELETED;
65078+ FOR_EACH_NESTED_SUBJECT_END(subj)
65079+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
65080+ matchps->mode |= GR_DELETED;
65081+ FOR_EACH_ROLE_END(role)
65082+
65083+ inodev->nentry->deleted = 1;
65084+
65085+ return;
65086+}
65087+
65088+void
65089+gr_handle_delete(const ino_t ino, const dev_t dev)
65090+{
65091+ struct inodev_entry *inodev;
65092+
65093+ if (unlikely(!(gr_status & GR_READY)))
65094+ return;
65095+
65096+ write_lock(&gr_inode_lock);
65097+ inodev = lookup_inodev_entry(ino, dev);
65098+ if (inodev != NULL)
65099+ do_handle_delete(inodev, ino, dev);
65100+ write_unlock(&gr_inode_lock);
65101+
65102+ return;
65103+}
65104+
65105+static void
65106+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
65107+ const ino_t newinode, const dev_t newdevice,
65108+ struct acl_subject_label *subj)
65109+{
65110+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
65111+ struct acl_object_label *match;
65112+
65113+ match = subj->obj_hash[index];
65114+
65115+ while (match && (match->inode != oldinode ||
65116+ match->device != olddevice ||
65117+ !(match->mode & GR_DELETED)))
65118+ match = match->next;
65119+
65120+ if (match && (match->inode == oldinode)
65121+ && (match->device == olddevice)
65122+ && (match->mode & GR_DELETED)) {
65123+ if (match->prev == NULL) {
65124+ subj->obj_hash[index] = match->next;
65125+ if (match->next != NULL)
65126+ match->next->prev = NULL;
65127+ } else {
65128+ match->prev->next = match->next;
65129+ if (match->next != NULL)
65130+ match->next->prev = match->prev;
65131+ }
65132+ match->prev = NULL;
65133+ match->next = NULL;
65134+ match->inode = newinode;
65135+ match->device = newdevice;
65136+ match->mode &= ~GR_DELETED;
65137+
65138+ insert_acl_obj_label(match, subj);
65139+ }
65140+
65141+ return;
65142+}
65143+
65144+static void
65145+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
65146+ const ino_t newinode, const dev_t newdevice,
65147+ struct acl_role_label *role)
65148+{
65149+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
65150+ struct acl_subject_label *match;
65151+
65152+ match = role->subj_hash[index];
65153+
65154+ while (match && (match->inode != oldinode ||
65155+ match->device != olddevice ||
65156+ !(match->mode & GR_DELETED)))
65157+ match = match->next;
65158+
65159+ if (match && (match->inode == oldinode)
65160+ && (match->device == olddevice)
65161+ && (match->mode & GR_DELETED)) {
65162+ if (match->prev == NULL) {
65163+ role->subj_hash[index] = match->next;
65164+ if (match->next != NULL)
65165+ match->next->prev = NULL;
65166+ } else {
65167+ match->prev->next = match->next;
65168+ if (match->next != NULL)
65169+ match->next->prev = match->prev;
65170+ }
65171+ match->prev = NULL;
65172+ match->next = NULL;
65173+ match->inode = newinode;
65174+ match->device = newdevice;
65175+ match->mode &= ~GR_DELETED;
65176+
65177+ insert_acl_subj_label(match, role);
65178+ }
65179+
65180+ return;
65181+}
65182+
65183+static void
65184+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
65185+ const ino_t newinode, const dev_t newdevice)
65186+{
65187+ unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
65188+ struct inodev_entry *match;
65189+
65190+ match = inodev_set.i_hash[index];
65191+
65192+ while (match && (match->nentry->inode != oldinode ||
65193+ match->nentry->device != olddevice || !match->nentry->deleted))
65194+ match = match->next;
65195+
65196+ if (match && (match->nentry->inode == oldinode)
65197+ && (match->nentry->device == olddevice) &&
65198+ match->nentry->deleted) {
65199+ if (match->prev == NULL) {
65200+ inodev_set.i_hash[index] = match->next;
65201+ if (match->next != NULL)
65202+ match->next->prev = NULL;
65203+ } else {
65204+ match->prev->next = match->next;
65205+ if (match->next != NULL)
65206+ match->next->prev = match->prev;
65207+ }
65208+ match->prev = NULL;
65209+ match->next = NULL;
65210+ match->nentry->inode = newinode;
65211+ match->nentry->device = newdevice;
65212+ match->nentry->deleted = 0;
65213+
65214+ insert_inodev_entry(match);
65215+ }
65216+
65217+ return;
65218+}
65219+
65220+static void
65221+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
65222+{
65223+ struct acl_subject_label *subj;
65224+ struct acl_role_label *role;
65225+ unsigned int x;
65226+
65227+ FOR_EACH_ROLE_START(role)
65228+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
65229+
65230+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
65231+ if ((subj->inode == ino) && (subj->device == dev)) {
65232+ subj->inode = ino;
65233+ subj->device = dev;
65234+ }
65235+ /* nested subjects aren't in the role's subj_hash table */
65236+ update_acl_obj_label(matchn->inode, matchn->device,
65237+ ino, dev, subj);
65238+ FOR_EACH_NESTED_SUBJECT_END(subj)
65239+ FOR_EACH_SUBJECT_START(role, subj, x)
65240+ update_acl_obj_label(matchn->inode, matchn->device,
65241+ ino, dev, subj);
65242+ FOR_EACH_SUBJECT_END(subj,x)
65243+ FOR_EACH_ROLE_END(role)
65244+
65245+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
65246+
65247+ return;
65248+}
65249+
65250+static void
65251+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
65252+ const struct vfsmount *mnt)
65253+{
65254+ ino_t ino = dentry->d_inode->i_ino;
65255+ dev_t dev = __get_dev(dentry);
65256+
65257+ __do_handle_create(matchn, ino, dev);
65258+
65259+ return;
65260+}
65261+
65262+void
65263+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
65264+{
65265+ struct name_entry *matchn;
65266+
65267+ if (unlikely(!(gr_status & GR_READY)))
65268+ return;
65269+
65270+ preempt_disable();
65271+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
65272+
65273+ if (unlikely((unsigned long)matchn)) {
65274+ write_lock(&gr_inode_lock);
65275+ do_handle_create(matchn, dentry, mnt);
65276+ write_unlock(&gr_inode_lock);
65277+ }
65278+ preempt_enable();
65279+
65280+ return;
65281+}
65282+
65283+void
65284+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
65285+{
65286+ struct name_entry *matchn;
65287+
65288+ if (unlikely(!(gr_status & GR_READY)))
65289+ return;
65290+
65291+ preempt_disable();
65292+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
65293+
65294+ if (unlikely((unsigned long)matchn)) {
65295+ write_lock(&gr_inode_lock);
65296+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
65297+ write_unlock(&gr_inode_lock);
65298+ }
65299+ preempt_enable();
65300+
65301+ return;
65302+}
65303+
65304+void
65305+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
65306+ struct dentry *old_dentry,
65307+ struct dentry *new_dentry,
65308+ struct vfsmount *mnt, const __u8 replace)
65309+{
65310+ struct name_entry *matchn;
65311+ struct inodev_entry *inodev;
65312+ struct inode *inode = new_dentry->d_inode;
65313+ ino_t old_ino = old_dentry->d_inode->i_ino;
65314+ dev_t old_dev = __get_dev(old_dentry);
65315+
65316+ /* vfs_rename swaps the name and parent link for old_dentry and
65317+ new_dentry
65318+ at this point, old_dentry has the new name, parent link, and inode
65319+ for the renamed file
65320+ if a file is being replaced by a rename, new_dentry has the inode
65321+ and name for the replaced file
65322+ */
65323+
65324+ if (unlikely(!(gr_status & GR_READY)))
65325+ return;
65326+
65327+ preempt_disable();
65328+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
65329+
65330+ /* we wouldn't have to check d_inode if it weren't for
65331+ NFS silly-renaming
65332+ */
65333+
65334+ write_lock(&gr_inode_lock);
65335+ if (unlikely(replace && inode)) {
65336+ ino_t new_ino = inode->i_ino;
65337+ dev_t new_dev = __get_dev(new_dentry);
65338+
65339+ inodev = lookup_inodev_entry(new_ino, new_dev);
65340+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
65341+ do_handle_delete(inodev, new_ino, new_dev);
65342+ }
65343+
65344+ inodev = lookup_inodev_entry(old_ino, old_dev);
65345+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
65346+ do_handle_delete(inodev, old_ino, old_dev);
65347+
65348+ if (unlikely((unsigned long)matchn))
65349+ do_handle_create(matchn, old_dentry, mnt);
65350+
65351+ write_unlock(&gr_inode_lock);
65352+ preempt_enable();
65353+
65354+ return;
65355+}
65356+
65357+static int
65358+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
65359+ unsigned char **sum)
65360+{
65361+ struct acl_role_label *r;
65362+ struct role_allowed_ip *ipp;
65363+ struct role_transition *trans;
65364+ unsigned int i;
65365+ int found = 0;
65366+ u32 curr_ip = current->signal->curr_ip;
65367+
65368+ current->signal->saved_ip = curr_ip;
65369+
65370+ /* check transition table */
65371+
65372+ for (trans = current->role->transitions; trans; trans = trans->next) {
65373+ if (!strcmp(rolename, trans->rolename)) {
65374+ found = 1;
65375+ break;
65376+ }
65377+ }
65378+
65379+ if (!found)
65380+ return 0;
65381+
65382+ /* handle special roles that do not require authentication
65383+ and check ip */
65384+
65385+ FOR_EACH_ROLE_START(r)
65386+ if (!strcmp(rolename, r->rolename) &&
65387+ (r->roletype & GR_ROLE_SPECIAL)) {
65388+ found = 0;
65389+ if (r->allowed_ips != NULL) {
65390+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
65391+ if ((ntohl(curr_ip) & ipp->netmask) ==
65392+ (ntohl(ipp->addr) & ipp->netmask))
65393+ found = 1;
65394+ }
65395+ } else
65396+ found = 2;
65397+ if (!found)
65398+ return 0;
65399+
65400+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
65401+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
65402+ *salt = NULL;
65403+ *sum = NULL;
65404+ return 1;
65405+ }
65406+ }
65407+ FOR_EACH_ROLE_END(r)
65408+
65409+ for (i = 0; i < num_sprole_pws; i++) {
65410+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
65411+ *salt = acl_special_roles[i]->salt;
65412+ *sum = acl_special_roles[i]->sum;
65413+ return 1;
65414+ }
65415+ }
65416+
65417+ return 0;
65418+}
65419+
65420+static void
65421+assign_special_role(char *rolename)
65422+{
65423+ struct acl_object_label *obj;
65424+ struct acl_role_label *r;
65425+ struct acl_role_label *assigned = NULL;
65426+ struct task_struct *tsk;
65427+ struct file *filp;
65428+
65429+ FOR_EACH_ROLE_START(r)
65430+ if (!strcmp(rolename, r->rolename) &&
65431+ (r->roletype & GR_ROLE_SPECIAL)) {
65432+ assigned = r;
65433+ break;
65434+ }
65435+ FOR_EACH_ROLE_END(r)
65436+
65437+ if (!assigned)
65438+ return;
65439+
65440+ read_lock(&tasklist_lock);
65441+ read_lock(&grsec_exec_file_lock);
65442+
65443+ tsk = current->real_parent;
65444+ if (tsk == NULL)
65445+ goto out_unlock;
65446+
65447+ filp = tsk->exec_file;
65448+ if (filp == NULL)
65449+ goto out_unlock;
65450+
65451+ tsk->is_writable = 0;
65452+
65453+ tsk->acl_sp_role = 1;
65454+ tsk->acl_role_id = ++acl_sp_role_value;
65455+ tsk->role = assigned;
65456+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
65457+
65458+ /* ignore additional mmap checks for processes that are writable
65459+ by the default ACL */
65460+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
65461+ if (unlikely(obj->mode & GR_WRITE))
65462+ tsk->is_writable = 1;
65463+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
65464+ if (unlikely(obj->mode & GR_WRITE))
65465+ tsk->is_writable = 1;
65466+
65467+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
65468+ 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));
65469+#endif
65470+
65471+out_unlock:
65472+ read_unlock(&grsec_exec_file_lock);
65473+ read_unlock(&tasklist_lock);
65474+ return;
65475+}
65476+
65477+int gr_check_secure_terminal(struct task_struct *task)
65478+{
65479+ struct task_struct *p, *p2, *p3;
65480+ struct files_struct *files;
65481+ struct fdtable *fdt;
65482+ struct file *our_file = NULL, *file;
65483+ int i;
65484+
65485+ if (task->signal->tty == NULL)
65486+ return 1;
65487+
65488+ files = get_files_struct(task);
65489+ if (files != NULL) {
65490+ rcu_read_lock();
65491+ fdt = files_fdtable(files);
65492+ for (i=0; i < fdt->max_fds; i++) {
65493+ file = fcheck_files(files, i);
65494+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
65495+ get_file(file);
65496+ our_file = file;
65497+ }
65498+ }
65499+ rcu_read_unlock();
65500+ put_files_struct(files);
65501+ }
65502+
65503+ if (our_file == NULL)
65504+ return 1;
65505+
65506+ read_lock(&tasklist_lock);
65507+ do_each_thread(p2, p) {
65508+ files = get_files_struct(p);
65509+ if (files == NULL ||
65510+ (p->signal && p->signal->tty == task->signal->tty)) {
65511+ if (files != NULL)
65512+ put_files_struct(files);
65513+ continue;
65514+ }
65515+ rcu_read_lock();
65516+ fdt = files_fdtable(files);
65517+ for (i=0; i < fdt->max_fds; i++) {
65518+ file = fcheck_files(files, i);
65519+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
65520+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
65521+ p3 = task;
65522+ while (task_pid_nr(p3) > 0) {
65523+ if (p3 == p)
65524+ break;
65525+ p3 = p3->real_parent;
65526+ }
65527+ if (p3 == p)
65528+ break;
65529+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
65530+ gr_handle_alertkill(p);
65531+ rcu_read_unlock();
65532+ put_files_struct(files);
65533+ read_unlock(&tasklist_lock);
65534+ fput(our_file);
65535+ return 0;
65536+ }
65537+ }
65538+ rcu_read_unlock();
65539+ put_files_struct(files);
65540+ } while_each_thread(p2, p);
65541+ read_unlock(&tasklist_lock);
65542+
65543+ fput(our_file);
65544+ return 1;
65545+}
65546+
65547+static int gr_rbac_disable(void *unused)
65548+{
65549+ pax_open_kernel();
65550+ gr_status &= ~GR_READY;
65551+ pax_close_kernel();
65552+
65553+ return 0;
65554+}
65555+
65556+ssize_t
65557+write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
65558+{
65559+ struct gr_arg_wrapper uwrap;
65560+ unsigned char *sprole_salt = NULL;
65561+ unsigned char *sprole_sum = NULL;
65562+ int error = 0;
65563+ int error2 = 0;
65564+ size_t req_count = 0;
65565+
65566+ mutex_lock(&gr_dev_mutex);
65567+
65568+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
65569+ error = -EPERM;
65570+ goto out;
65571+ }
65572+
65573+#ifdef CONFIG_COMPAT
65574+ pax_open_kernel();
65575+ if (is_compat_task()) {
65576+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
65577+ copy_gr_arg = &copy_gr_arg_compat;
65578+ copy_acl_object_label = &copy_acl_object_label_compat;
65579+ copy_acl_subject_label = &copy_acl_subject_label_compat;
65580+ copy_acl_role_label = &copy_acl_role_label_compat;
65581+ copy_acl_ip_label = &copy_acl_ip_label_compat;
65582+ copy_role_allowed_ip = &copy_role_allowed_ip_compat;
65583+ copy_role_transition = &copy_role_transition_compat;
65584+ copy_sprole_pw = &copy_sprole_pw_compat;
65585+ copy_gr_hash_struct = &copy_gr_hash_struct_compat;
65586+ copy_pointer_from_array = &copy_pointer_from_array_compat;
65587+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
65588+ } else {
65589+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
65590+ copy_gr_arg = &copy_gr_arg_normal;
65591+ copy_acl_object_label = &copy_acl_object_label_normal;
65592+ copy_acl_subject_label = &copy_acl_subject_label_normal;
65593+ copy_acl_role_label = &copy_acl_role_label_normal;
65594+ copy_acl_ip_label = &copy_acl_ip_label_normal;
65595+ copy_role_allowed_ip = &copy_role_allowed_ip_normal;
65596+ copy_role_transition = &copy_role_transition_normal;
65597+ copy_sprole_pw = &copy_sprole_pw_normal;
65598+ copy_gr_hash_struct = &copy_gr_hash_struct_normal;
65599+ copy_pointer_from_array = &copy_pointer_from_array_normal;
65600+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
65601+ }
65602+ pax_close_kernel();
65603+#endif
65604+
65605+ req_count = get_gr_arg_wrapper_size();
65606+
65607+ if (count != req_count) {
65608+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
65609+ error = -EINVAL;
65610+ goto out;
65611+ }
65612+
65613+
65614+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
65615+ gr_auth_expires = 0;
65616+ gr_auth_attempts = 0;
65617+ }
65618+
65619+ error = copy_gr_arg_wrapper(buf, &uwrap);
65620+ if (error)
65621+ goto out;
65622+
65623+ error = copy_gr_arg(uwrap.arg, gr_usermode);
65624+ if (error)
65625+ goto out;
65626+
65627+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
65628+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
65629+ time_after(gr_auth_expires, get_seconds())) {
65630+ error = -EBUSY;
65631+ goto out;
65632+ }
65633+
65634+ /* if non-root trying to do anything other than use a special role,
65635+ do not attempt authentication, do not count towards authentication
65636+ locking
65637+ */
65638+
65639+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
65640+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
65641+ gr_is_global_nonroot(current_uid())) {
65642+ error = -EPERM;
65643+ goto out;
65644+ }
65645+
65646+ /* ensure pw and special role name are null terminated */
65647+
65648+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
65649+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
65650+
65651+ /* Okay.
65652+ * We have our enough of the argument structure..(we have yet
65653+ * to copy_from_user the tables themselves) . Copy the tables
65654+ * only if we need them, i.e. for loading operations. */
65655+
65656+ switch (gr_usermode->mode) {
65657+ case GR_STATUS:
65658+ if (gr_status & GR_READY) {
65659+ error = 1;
65660+ if (!gr_check_secure_terminal(current))
65661+ error = 3;
65662+ } else
65663+ error = 2;
65664+ goto out;
65665+ case GR_SHUTDOWN:
65666+ if ((gr_status & GR_READY)
65667+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
65668+ stop_machine(gr_rbac_disable, NULL, NULL);
65669+ free_variables();
65670+ memset(gr_usermode, 0, sizeof (struct gr_arg));
65671+ memset(gr_system_salt, 0, GR_SALT_LEN);
65672+ memset(gr_system_sum, 0, GR_SHA_LEN);
65673+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
65674+ } else if (gr_status & GR_READY) {
65675+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
65676+ error = -EPERM;
65677+ } else {
65678+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
65679+ error = -EAGAIN;
65680+ }
65681+ break;
65682+ case GR_ENABLE:
65683+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
65684+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
65685+ else {
65686+ if (gr_status & GR_READY)
65687+ error = -EAGAIN;
65688+ else
65689+ error = error2;
65690+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
65691+ }
65692+ break;
65693+ case GR_RELOAD:
65694+ if (!(gr_status & GR_READY)) {
65695+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
65696+ error = -EAGAIN;
65697+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
65698+ stop_machine(gr_rbac_disable, NULL, NULL);
65699+ free_variables();
65700+ error2 = gracl_init(gr_usermode);
65701+ if (!error2)
65702+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
65703+ else {
65704+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
65705+ error = error2;
65706+ }
65707+ } else {
65708+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
65709+ error = -EPERM;
65710+ }
65711+ break;
65712+ case GR_SEGVMOD:
65713+ if (unlikely(!(gr_status & GR_READY))) {
65714+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
65715+ error = -EAGAIN;
65716+ break;
65717+ }
65718+
65719+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
65720+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
65721+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
65722+ struct acl_subject_label *segvacl;
65723+ segvacl =
65724+ lookup_acl_subj_label(gr_usermode->segv_inode,
65725+ gr_usermode->segv_device,
65726+ current->role);
65727+ if (segvacl) {
65728+ segvacl->crashes = 0;
65729+ segvacl->expires = 0;
65730+ }
65731+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
65732+ gr_remove_uid(gr_usermode->segv_uid);
65733+ }
65734+ } else {
65735+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
65736+ error = -EPERM;
65737+ }
65738+ break;
65739+ case GR_SPROLE:
65740+ case GR_SPROLEPAM:
65741+ if (unlikely(!(gr_status & GR_READY))) {
65742+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
65743+ error = -EAGAIN;
65744+ break;
65745+ }
65746+
65747+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
65748+ current->role->expires = 0;
65749+ current->role->auth_attempts = 0;
65750+ }
65751+
65752+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
65753+ time_after(current->role->expires, get_seconds())) {
65754+ error = -EBUSY;
65755+ goto out;
65756+ }
65757+
65758+ if (lookup_special_role_auth
65759+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
65760+ && ((!sprole_salt && !sprole_sum)
65761+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
65762+ char *p = "";
65763+ assign_special_role(gr_usermode->sp_role);
65764+ read_lock(&tasklist_lock);
65765+ if (current->real_parent)
65766+ p = current->real_parent->role->rolename;
65767+ read_unlock(&tasklist_lock);
65768+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
65769+ p, acl_sp_role_value);
65770+ } else {
65771+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
65772+ error = -EPERM;
65773+ if(!(current->role->auth_attempts++))
65774+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
65775+
65776+ goto out;
65777+ }
65778+ break;
65779+ case GR_UNSPROLE:
65780+ if (unlikely(!(gr_status & GR_READY))) {
65781+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
65782+ error = -EAGAIN;
65783+ break;
65784+ }
65785+
65786+ if (current->role->roletype & GR_ROLE_SPECIAL) {
65787+ char *p = "";
65788+ int i = 0;
65789+
65790+ read_lock(&tasklist_lock);
65791+ if (current->real_parent) {
65792+ p = current->real_parent->role->rolename;
65793+ i = current->real_parent->acl_role_id;
65794+ }
65795+ read_unlock(&tasklist_lock);
65796+
65797+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
65798+ gr_set_acls(1);
65799+ } else {
65800+ error = -EPERM;
65801+ goto out;
65802+ }
65803+ break;
65804+ default:
65805+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
65806+ error = -EINVAL;
65807+ break;
65808+ }
65809+
65810+ if (error != -EPERM)
65811+ goto out;
65812+
65813+ if(!(gr_auth_attempts++))
65814+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
65815+
65816+ out:
65817+ mutex_unlock(&gr_dev_mutex);
65818+
65819+ if (!error)
65820+ error = req_count;
65821+
65822+ return error;
65823+}
65824+
65825+/* must be called with
65826+ rcu_read_lock();
65827+ read_lock(&tasklist_lock);
65828+ read_lock(&grsec_exec_file_lock);
65829+*/
65830+int gr_apply_subject_to_task(struct task_struct *task)
65831+{
65832+ struct acl_object_label *obj;
65833+ char *tmpname;
65834+ struct acl_subject_label *tmpsubj;
65835+ struct file *filp;
65836+ struct name_entry *nmatch;
65837+
65838+ filp = task->exec_file;
65839+ if (filp == NULL)
65840+ return 0;
65841+
65842+ /* the following is to apply the correct subject
65843+ on binaries running when the RBAC system
65844+ is enabled, when the binaries have been
65845+ replaced or deleted since their execution
65846+ -----
65847+ when the RBAC system starts, the inode/dev
65848+ from exec_file will be one the RBAC system
65849+ is unaware of. It only knows the inode/dev
65850+ of the present file on disk, or the absence
65851+ of it.
65852+ */
65853+ preempt_disable();
65854+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
65855+
65856+ nmatch = lookup_name_entry(tmpname);
65857+ preempt_enable();
65858+ tmpsubj = NULL;
65859+ if (nmatch) {
65860+ if (nmatch->deleted)
65861+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
65862+ else
65863+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
65864+ if (tmpsubj != NULL)
65865+ task->acl = tmpsubj;
65866+ }
65867+ if (tmpsubj == NULL)
65868+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
65869+ task->role);
65870+ if (task->acl) {
65871+ task->is_writable = 0;
65872+ /* ignore additional mmap checks for processes that are writable
65873+ by the default ACL */
65874+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
65875+ if (unlikely(obj->mode & GR_WRITE))
65876+ task->is_writable = 1;
65877+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
65878+ if (unlikely(obj->mode & GR_WRITE))
65879+ task->is_writable = 1;
65880+
65881+ gr_set_proc_res(task);
65882+
65883+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
65884+ 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);
65885+#endif
65886+ } else {
65887+ return 1;
65888+ }
65889+
65890+ return 0;
65891+}
65892+
65893+int
65894+gr_set_acls(const int type)
65895+{
65896+ struct task_struct *task, *task2;
65897+ struct acl_role_label *role = current->role;
65898+ __u16 acl_role_id = current->acl_role_id;
65899+ const struct cred *cred;
65900+ int ret;
65901+
65902+ rcu_read_lock();
65903+ read_lock(&tasklist_lock);
65904+ read_lock(&grsec_exec_file_lock);
65905+ do_each_thread(task2, task) {
65906+ /* check to see if we're called from the exit handler,
65907+ if so, only replace ACLs that have inherited the admin
65908+ ACL */
65909+
65910+ if (type && (task->role != role ||
65911+ task->acl_role_id != acl_role_id))
65912+ continue;
65913+
65914+ task->acl_role_id = 0;
65915+ task->acl_sp_role = 0;
65916+
65917+ if (task->exec_file) {
65918+ cred = __task_cred(task);
65919+ task->role = lookup_acl_role_label(task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
65920+ ret = gr_apply_subject_to_task(task);
65921+ if (ret) {
65922+ read_unlock(&grsec_exec_file_lock);
65923+ read_unlock(&tasklist_lock);
65924+ rcu_read_unlock();
65925+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
65926+ return ret;
65927+ }
65928+ } else {
65929+ // it's a kernel process
65930+ task->role = kernel_role;
65931+ task->acl = kernel_role->root_label;
65932+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
65933+ task->acl->mode &= ~GR_PROCFIND;
65934+#endif
65935+ }
65936+ } while_each_thread(task2, task);
65937+ read_unlock(&grsec_exec_file_lock);
65938+ read_unlock(&tasklist_lock);
65939+ rcu_read_unlock();
65940+
65941+ return 0;
65942+}
65943+
65944+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
65945+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
65946+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
65947+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
65948+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
65949+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
65950+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
65951+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
65952+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
65953+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
65954+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
65955+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
65956+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
65957+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
65958+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
65959+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
65960+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
65961+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
65962+};
65963+
65964+void
65965+gr_learn_resource(const struct task_struct *task,
65966+ const int res, const unsigned long wanted, const int gt)
65967+{
65968+ struct acl_subject_label *acl;
65969+ const struct cred *cred;
65970+
65971+ if (unlikely((gr_status & GR_READY) &&
65972+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
65973+ goto skip_reslog;
65974+
65975+ gr_log_resource(task, res, wanted, gt);
65976+skip_reslog:
65977+
65978+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
65979+ return;
65980+
65981+ acl = task->acl;
65982+
65983+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
65984+ !(acl->resmask & (1U << (unsigned short) res))))
65985+ return;
65986+
65987+ if (wanted >= acl->res[res].rlim_cur) {
65988+ unsigned long res_add;
65989+
65990+ res_add = wanted + res_learn_bumps[res];
65991+
65992+ acl->res[res].rlim_cur = res_add;
65993+
65994+ if (wanted > acl->res[res].rlim_max)
65995+ acl->res[res].rlim_max = res_add;
65996+
65997+ /* only log the subject filename, since resource logging is supported for
65998+ single-subject learning only */
65999+ rcu_read_lock();
66000+ cred = __task_cred(task);
66001+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
66002+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
66003+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
66004+ "", (unsigned long) res, &task->signal->saved_ip);
66005+ rcu_read_unlock();
66006+ }
66007+
66008+ return;
66009+}
66010+EXPORT_SYMBOL(gr_learn_resource);
66011+#endif
66012+
66013+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
66014+void
66015+pax_set_initial_flags(struct linux_binprm *bprm)
66016+{
66017+ struct task_struct *task = current;
66018+ struct acl_subject_label *proc;
66019+ unsigned long flags;
66020+
66021+ if (unlikely(!(gr_status & GR_READY)))
66022+ return;
66023+
66024+ flags = pax_get_flags(task);
66025+
66026+ proc = task->acl;
66027+
66028+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
66029+ flags &= ~MF_PAX_PAGEEXEC;
66030+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
66031+ flags &= ~MF_PAX_SEGMEXEC;
66032+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
66033+ flags &= ~MF_PAX_RANDMMAP;
66034+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
66035+ flags &= ~MF_PAX_EMUTRAMP;
66036+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
66037+ flags &= ~MF_PAX_MPROTECT;
66038+
66039+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
66040+ flags |= MF_PAX_PAGEEXEC;
66041+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
66042+ flags |= MF_PAX_SEGMEXEC;
66043+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
66044+ flags |= MF_PAX_RANDMMAP;
66045+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
66046+ flags |= MF_PAX_EMUTRAMP;
66047+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
66048+ flags |= MF_PAX_MPROTECT;
66049+
66050+ pax_set_flags(task, flags);
66051+
66052+ return;
66053+}
66054+#endif
66055+
66056+int
66057+gr_handle_proc_ptrace(struct task_struct *task)
66058+{
66059+ struct file *filp;
66060+ struct task_struct *tmp = task;
66061+ struct task_struct *curtemp = current;
66062+ __u32 retmode;
66063+
66064+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
66065+ if (unlikely(!(gr_status & GR_READY)))
66066+ return 0;
66067+#endif
66068+
66069+ read_lock(&tasklist_lock);
66070+ read_lock(&grsec_exec_file_lock);
66071+ filp = task->exec_file;
66072+
66073+ while (task_pid_nr(tmp) > 0) {
66074+ if (tmp == curtemp)
66075+ break;
66076+ tmp = tmp->real_parent;
66077+ }
66078+
66079+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
66080+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
66081+ read_unlock(&grsec_exec_file_lock);
66082+ read_unlock(&tasklist_lock);
66083+ return 1;
66084+ }
66085+
66086+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
66087+ if (!(gr_status & GR_READY)) {
66088+ read_unlock(&grsec_exec_file_lock);
66089+ read_unlock(&tasklist_lock);
66090+ return 0;
66091+ }
66092+#endif
66093+
66094+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
66095+ read_unlock(&grsec_exec_file_lock);
66096+ read_unlock(&tasklist_lock);
66097+
66098+ if (retmode & GR_NOPTRACE)
66099+ return 1;
66100+
66101+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
66102+ && (current->acl != task->acl || (current->acl != current->role->root_label
66103+ && task_pid_nr(current) != task_pid_nr(task))))
66104+ return 1;
66105+
66106+ return 0;
66107+}
66108+
66109+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
66110+{
66111+ if (unlikely(!(gr_status & GR_READY)))
66112+ return;
66113+
66114+ if (!(current->role->roletype & GR_ROLE_GOD))
66115+ return;
66116+
66117+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
66118+ p->role->rolename, gr_task_roletype_to_char(p),
66119+ p->acl->filename);
66120+}
66121+
66122+int
66123+gr_handle_ptrace(struct task_struct *task, const long request)
66124+{
66125+ struct task_struct *tmp = task;
66126+ struct task_struct *curtemp = current;
66127+ __u32 retmode;
66128+
66129+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
66130+ if (unlikely(!(gr_status & GR_READY)))
66131+ return 0;
66132+#endif
66133+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
66134+ read_lock(&tasklist_lock);
66135+ while (task_pid_nr(tmp) > 0) {
66136+ if (tmp == curtemp)
66137+ break;
66138+ tmp = tmp->real_parent;
66139+ }
66140+
66141+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
66142+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
66143+ read_unlock(&tasklist_lock);
66144+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
66145+ return 1;
66146+ }
66147+ read_unlock(&tasklist_lock);
66148+ }
66149+
66150+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
66151+ if (!(gr_status & GR_READY))
66152+ return 0;
66153+#endif
66154+
66155+ read_lock(&grsec_exec_file_lock);
66156+ if (unlikely(!task->exec_file)) {
66157+ read_unlock(&grsec_exec_file_lock);
66158+ return 0;
66159+ }
66160+
66161+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
66162+ read_unlock(&grsec_exec_file_lock);
66163+
66164+ if (retmode & GR_NOPTRACE) {
66165+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
66166+ return 1;
66167+ }
66168+
66169+ if (retmode & GR_PTRACERD) {
66170+ switch (request) {
66171+ case PTRACE_SEIZE:
66172+ case PTRACE_POKETEXT:
66173+ case PTRACE_POKEDATA:
66174+ case PTRACE_POKEUSR:
66175+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
66176+ case PTRACE_SETREGS:
66177+ case PTRACE_SETFPREGS:
66178+#endif
66179+#ifdef CONFIG_X86
66180+ case PTRACE_SETFPXREGS:
66181+#endif
66182+#ifdef CONFIG_ALTIVEC
66183+ case PTRACE_SETVRREGS:
66184+#endif
66185+ return 1;
66186+ default:
66187+ return 0;
66188+ }
66189+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
66190+ !(current->role->roletype & GR_ROLE_GOD) &&
66191+ (current->acl != task->acl)) {
66192+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
66193+ return 1;
66194+ }
66195+
66196+ return 0;
66197+}
66198+
66199+static int is_writable_mmap(const struct file *filp)
66200+{
66201+ struct task_struct *task = current;
66202+ struct acl_object_label *obj, *obj2;
66203+
66204+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
66205+ !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))) {
66206+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
66207+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
66208+ task->role->root_label);
66209+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
66210+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
66211+ return 1;
66212+ }
66213+ }
66214+ return 0;
66215+}
66216+
66217+int
66218+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
66219+{
66220+ __u32 mode;
66221+
66222+ if (unlikely(!file || !(prot & PROT_EXEC)))
66223+ return 1;
66224+
66225+ if (is_writable_mmap(file))
66226+ return 0;
66227+
66228+ mode =
66229+ gr_search_file(file->f_path.dentry,
66230+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
66231+ file->f_path.mnt);
66232+
66233+ if (!gr_tpe_allow(file))
66234+ return 0;
66235+
66236+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
66237+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
66238+ return 0;
66239+ } else if (unlikely(!(mode & GR_EXEC))) {
66240+ return 0;
66241+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
66242+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
66243+ return 1;
66244+ }
66245+
66246+ return 1;
66247+}
66248+
66249+int
66250+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
66251+{
66252+ __u32 mode;
66253+
66254+ if (unlikely(!file || !(prot & PROT_EXEC)))
66255+ return 1;
66256+
66257+ if (is_writable_mmap(file))
66258+ return 0;
66259+
66260+ mode =
66261+ gr_search_file(file->f_path.dentry,
66262+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
66263+ file->f_path.mnt);
66264+
66265+ if (!gr_tpe_allow(file))
66266+ return 0;
66267+
66268+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
66269+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
66270+ return 0;
66271+ } else if (unlikely(!(mode & GR_EXEC))) {
66272+ return 0;
66273+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
66274+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
66275+ return 1;
66276+ }
66277+
66278+ return 1;
66279+}
66280+
66281+void
66282+gr_acl_handle_psacct(struct task_struct *task, const long code)
66283+{
66284+ unsigned long runtime;
66285+ unsigned long cputime;
66286+ unsigned int wday, cday;
66287+ __u8 whr, chr;
66288+ __u8 wmin, cmin;
66289+ __u8 wsec, csec;
66290+ struct timespec timeval;
66291+
66292+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
66293+ !(task->acl->mode & GR_PROCACCT)))
66294+ return;
66295+
66296+ do_posix_clock_monotonic_gettime(&timeval);
66297+ runtime = timeval.tv_sec - task->start_time.tv_sec;
66298+ wday = runtime / (3600 * 24);
66299+ runtime -= wday * (3600 * 24);
66300+ whr = runtime / 3600;
66301+ runtime -= whr * 3600;
66302+ wmin = runtime / 60;
66303+ runtime -= wmin * 60;
66304+ wsec = runtime;
66305+
66306+ cputime = (task->utime + task->stime) / HZ;
66307+ cday = cputime / (3600 * 24);
66308+ cputime -= cday * (3600 * 24);
66309+ chr = cputime / 3600;
66310+ cputime -= chr * 3600;
66311+ cmin = cputime / 60;
66312+ cputime -= cmin * 60;
66313+ csec = cputime;
66314+
66315+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
66316+
66317+ return;
66318+}
66319+
66320+void gr_set_kernel_label(struct task_struct *task)
66321+{
66322+ if (gr_status & GR_READY) {
66323+ task->role = kernel_role;
66324+ task->acl = kernel_role->root_label;
66325+ }
66326+ return;
66327+}
66328+
66329+#ifdef CONFIG_TASKSTATS
66330+int gr_is_taskstats_denied(int pid)
66331+{
66332+ struct task_struct *task;
66333+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66334+ const struct cred *cred;
66335+#endif
66336+ int ret = 0;
66337+
66338+ /* restrict taskstats viewing to un-chrooted root users
66339+ who have the 'view' subject flag if the RBAC system is enabled
66340+ */
66341+
66342+ rcu_read_lock();
66343+ read_lock(&tasklist_lock);
66344+ task = find_task_by_vpid(pid);
66345+ if (task) {
66346+#ifdef CONFIG_GRKERNSEC_CHROOT
66347+ if (proc_is_chrooted(task))
66348+ ret = -EACCES;
66349+#endif
66350+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66351+ cred = __task_cred(task);
66352+#ifdef CONFIG_GRKERNSEC_PROC_USER
66353+ if (gr_is_global_nonroot(cred->uid))
66354+ ret = -EACCES;
66355+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66356+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
66357+ ret = -EACCES;
66358+#endif
66359+#endif
66360+ if (gr_status & GR_READY) {
66361+ if (!(task->acl->mode & GR_VIEW))
66362+ ret = -EACCES;
66363+ }
66364+ } else
66365+ ret = -ENOENT;
66366+
66367+ read_unlock(&tasklist_lock);
66368+ rcu_read_unlock();
66369+
66370+ return ret;
66371+}
66372+#endif
66373+
66374+/* AUXV entries are filled via a descendant of search_binary_handler
66375+ after we've already applied the subject for the target
66376+*/
66377+int gr_acl_enable_at_secure(void)
66378+{
66379+ if (unlikely(!(gr_status & GR_READY)))
66380+ return 0;
66381+
66382+ if (current->acl->mode & GR_ATSECURE)
66383+ return 1;
66384+
66385+ return 0;
66386+}
66387+
66388+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
66389+{
66390+ struct task_struct *task = current;
66391+ struct dentry *dentry = file->f_path.dentry;
66392+ struct vfsmount *mnt = file->f_path.mnt;
66393+ struct acl_object_label *obj, *tmp;
66394+ struct acl_subject_label *subj;
66395+ unsigned int bufsize;
66396+ int is_not_root;
66397+ char *path;
66398+ dev_t dev = __get_dev(dentry);
66399+
66400+ if (unlikely(!(gr_status & GR_READY)))
66401+ return 1;
66402+
66403+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
66404+ return 1;
66405+
66406+ /* ignore Eric Biederman */
66407+ if (IS_PRIVATE(dentry->d_inode))
66408+ return 1;
66409+
66410+ subj = task->acl;
66411+ read_lock(&gr_inode_lock);
66412+ do {
66413+ obj = lookup_acl_obj_label(ino, dev, subj);
66414+ if (obj != NULL) {
66415+ read_unlock(&gr_inode_lock);
66416+ return (obj->mode & GR_FIND) ? 1 : 0;
66417+ }
66418+ } while ((subj = subj->parent_subject));
66419+ read_unlock(&gr_inode_lock);
66420+
66421+ /* this is purely an optimization since we're looking for an object
66422+ for the directory we're doing a readdir on
66423+ if it's possible for any globbed object to match the entry we're
66424+ filling into the directory, then the object we find here will be
66425+ an anchor point with attached globbed objects
66426+ */
66427+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
66428+ if (obj->globbed == NULL)
66429+ return (obj->mode & GR_FIND) ? 1 : 0;
66430+
66431+ is_not_root = ((obj->filename[0] == '/') &&
66432+ (obj->filename[1] == '\0')) ? 0 : 1;
66433+ bufsize = PAGE_SIZE - namelen - is_not_root;
66434+
66435+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
66436+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
66437+ return 1;
66438+
66439+ preempt_disable();
66440+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
66441+ bufsize);
66442+
66443+ bufsize = strlen(path);
66444+
66445+ /* if base is "/", don't append an additional slash */
66446+ if (is_not_root)
66447+ *(path + bufsize) = '/';
66448+ memcpy(path + bufsize + is_not_root, name, namelen);
66449+ *(path + bufsize + namelen + is_not_root) = '\0';
66450+
66451+ tmp = obj->globbed;
66452+ while (tmp) {
66453+ if (!glob_match(tmp->filename, path)) {
66454+ preempt_enable();
66455+ return (tmp->mode & GR_FIND) ? 1 : 0;
66456+ }
66457+ tmp = tmp->next;
66458+ }
66459+ preempt_enable();
66460+ return (obj->mode & GR_FIND) ? 1 : 0;
66461+}
66462+
66463+void gr_put_exec_file(struct task_struct *task)
66464+{
66465+ struct file *filp;
66466+
66467+ write_lock(&grsec_exec_file_lock);
66468+ filp = task->exec_file;
66469+ task->exec_file = NULL;
66470+ write_unlock(&grsec_exec_file_lock);
66471+
66472+ if (filp)
66473+ fput(filp);
66474+
66475+ return;
66476+}
66477+
66478+
66479+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
66480+EXPORT_SYMBOL(gr_acl_is_enabled);
66481+#endif
66482+EXPORT_SYMBOL(gr_set_kernel_label);
66483+#ifdef CONFIG_SECURITY
66484+EXPORT_SYMBOL(gr_check_user_change);
66485+EXPORT_SYMBOL(gr_check_group_change);
66486+#endif
66487+
66488diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
66489new file mode 100644
66490index 0000000..34fefda
66491--- /dev/null
66492+++ b/grsecurity/gracl_alloc.c
66493@@ -0,0 +1,105 @@
66494+#include <linux/kernel.h>
66495+#include <linux/mm.h>
66496+#include <linux/slab.h>
66497+#include <linux/vmalloc.h>
66498+#include <linux/gracl.h>
66499+#include <linux/grsecurity.h>
66500+
66501+static unsigned long alloc_stack_next = 1;
66502+static unsigned long alloc_stack_size = 1;
66503+static void **alloc_stack;
66504+
66505+static __inline__ int
66506+alloc_pop(void)
66507+{
66508+ if (alloc_stack_next == 1)
66509+ return 0;
66510+
66511+ kfree(alloc_stack[alloc_stack_next - 2]);
66512+
66513+ alloc_stack_next--;
66514+
66515+ return 1;
66516+}
66517+
66518+static __inline__ int
66519+alloc_push(void *buf)
66520+{
66521+ if (alloc_stack_next >= alloc_stack_size)
66522+ return 1;
66523+
66524+ alloc_stack[alloc_stack_next - 1] = buf;
66525+
66526+ alloc_stack_next++;
66527+
66528+ return 0;
66529+}
66530+
66531+void *
66532+acl_alloc(unsigned long len)
66533+{
66534+ void *ret = NULL;
66535+
66536+ if (!len || len > PAGE_SIZE)
66537+ goto out;
66538+
66539+ ret = kmalloc(len, GFP_KERNEL);
66540+
66541+ if (ret) {
66542+ if (alloc_push(ret)) {
66543+ kfree(ret);
66544+ ret = NULL;
66545+ }
66546+ }
66547+
66548+out:
66549+ return ret;
66550+}
66551+
66552+void *
66553+acl_alloc_num(unsigned long num, unsigned long len)
66554+{
66555+ if (!len || (num > (PAGE_SIZE / len)))
66556+ return NULL;
66557+
66558+ return acl_alloc(num * len);
66559+}
66560+
66561+void
66562+acl_free_all(void)
66563+{
66564+ if (gr_acl_is_enabled() || !alloc_stack)
66565+ return;
66566+
66567+ while (alloc_pop()) ;
66568+
66569+ if (alloc_stack) {
66570+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
66571+ kfree(alloc_stack);
66572+ else
66573+ vfree(alloc_stack);
66574+ }
66575+
66576+ alloc_stack = NULL;
66577+ alloc_stack_size = 1;
66578+ alloc_stack_next = 1;
66579+
66580+ return;
66581+}
66582+
66583+int
66584+acl_alloc_stack_init(unsigned long size)
66585+{
66586+ if ((size * sizeof (void *)) <= PAGE_SIZE)
66587+ alloc_stack =
66588+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
66589+ else
66590+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
66591+
66592+ alloc_stack_size = size;
66593+
66594+ if (!alloc_stack)
66595+ return 0;
66596+ else
66597+ return 1;
66598+}
66599diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
66600new file mode 100644
66601index 0000000..bdd51ea
66602--- /dev/null
66603+++ b/grsecurity/gracl_cap.c
66604@@ -0,0 +1,110 @@
66605+#include <linux/kernel.h>
66606+#include <linux/module.h>
66607+#include <linux/sched.h>
66608+#include <linux/gracl.h>
66609+#include <linux/grsecurity.h>
66610+#include <linux/grinternal.h>
66611+
66612+extern const char *captab_log[];
66613+extern int captab_log_entries;
66614+
66615+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
66616+{
66617+ struct acl_subject_label *curracl;
66618+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
66619+ kernel_cap_t cap_audit = __cap_empty_set;
66620+
66621+ if (!gr_acl_is_enabled())
66622+ return 1;
66623+
66624+ curracl = task->acl;
66625+
66626+ cap_drop = curracl->cap_lower;
66627+ cap_mask = curracl->cap_mask;
66628+ cap_audit = curracl->cap_invert_audit;
66629+
66630+ while ((curracl = curracl->parent_subject)) {
66631+ /* if the cap isn't specified in the current computed mask but is specified in the
66632+ current level subject, and is lowered in the current level subject, then add
66633+ it to the set of dropped capabilities
66634+ otherwise, add the current level subject's mask to the current computed mask
66635+ */
66636+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
66637+ cap_raise(cap_mask, cap);
66638+ if (cap_raised(curracl->cap_lower, cap))
66639+ cap_raise(cap_drop, cap);
66640+ if (cap_raised(curracl->cap_invert_audit, cap))
66641+ cap_raise(cap_audit, cap);
66642+ }
66643+ }
66644+
66645+ if (!cap_raised(cap_drop, cap)) {
66646+ if (cap_raised(cap_audit, cap))
66647+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
66648+ return 1;
66649+ }
66650+
66651+ curracl = task->acl;
66652+
66653+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
66654+ && cap_raised(cred->cap_effective, cap)) {
66655+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
66656+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
66657+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
66658+ gr_to_filename(task->exec_file->f_path.dentry,
66659+ task->exec_file->f_path.mnt) : curracl->filename,
66660+ curracl->filename, 0UL,
66661+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
66662+ return 1;
66663+ }
66664+
66665+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
66666+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
66667+
66668+ return 0;
66669+}
66670+
66671+int
66672+gr_acl_is_capable(const int cap)
66673+{
66674+ return gr_task_acl_is_capable(current, current_cred(), cap);
66675+}
66676+
66677+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
66678+{
66679+ struct acl_subject_label *curracl;
66680+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
66681+
66682+ if (!gr_acl_is_enabled())
66683+ return 1;
66684+
66685+ curracl = task->acl;
66686+
66687+ cap_drop = curracl->cap_lower;
66688+ cap_mask = curracl->cap_mask;
66689+
66690+ while ((curracl = curracl->parent_subject)) {
66691+ /* if the cap isn't specified in the current computed mask but is specified in the
66692+ current level subject, and is lowered in the current level subject, then add
66693+ it to the set of dropped capabilities
66694+ otherwise, add the current level subject's mask to the current computed mask
66695+ */
66696+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
66697+ cap_raise(cap_mask, cap);
66698+ if (cap_raised(curracl->cap_lower, cap))
66699+ cap_raise(cap_drop, cap);
66700+ }
66701+ }
66702+
66703+ if (!cap_raised(cap_drop, cap))
66704+ return 1;
66705+
66706+ return 0;
66707+}
66708+
66709+int
66710+gr_acl_is_capable_nolog(const int cap)
66711+{
66712+ return gr_task_acl_is_capable_nolog(current, cap);
66713+}
66714+
66715diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
66716new file mode 100644
66717index 0000000..a43dd06
66718--- /dev/null
66719+++ b/grsecurity/gracl_compat.c
66720@@ -0,0 +1,269 @@
66721+#include <linux/kernel.h>
66722+#include <linux/gracl.h>
66723+#include <linux/compat.h>
66724+#include <linux/gracl_compat.h>
66725+
66726+#include <asm/uaccess.h>
66727+
66728+int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
66729+{
66730+ struct gr_arg_wrapper_compat uwrapcompat;
66731+
66732+ if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
66733+ return -EFAULT;
66734+
66735+ if ((uwrapcompat.version != GRSECURITY_VERSION) ||
66736+ (uwrapcompat.size != sizeof(struct gr_arg_compat)))
66737+ return -EINVAL;
66738+
66739+ uwrap->arg = compat_ptr(uwrapcompat.arg);
66740+ uwrap->version = uwrapcompat.version;
66741+ uwrap->size = sizeof(struct gr_arg);
66742+
66743+ return 0;
66744+}
66745+
66746+int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
66747+{
66748+ struct gr_arg_compat argcompat;
66749+
66750+ if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
66751+ return -EFAULT;
66752+
66753+ arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
66754+ arg->role_db.num_pointers = argcompat.role_db.num_pointers;
66755+ arg->role_db.num_roles = argcompat.role_db.num_roles;
66756+ arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
66757+ arg->role_db.num_subjects = argcompat.role_db.num_subjects;
66758+ arg->role_db.num_objects = argcompat.role_db.num_objects;
66759+
66760+ memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
66761+ memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
66762+ memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
66763+ memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
66764+ arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
66765+ arg->segv_device = argcompat.segv_device;
66766+ arg->segv_inode = argcompat.segv_inode;
66767+ arg->segv_uid = argcompat.segv_uid;
66768+ arg->num_sprole_pws = argcompat.num_sprole_pws;
66769+ arg->mode = argcompat.mode;
66770+
66771+ return 0;
66772+}
66773+
66774+int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
66775+{
66776+ struct acl_object_label_compat objcompat;
66777+
66778+ if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
66779+ return -EFAULT;
66780+
66781+ obj->filename = compat_ptr(objcompat.filename);
66782+ obj->inode = objcompat.inode;
66783+ obj->device = objcompat.device;
66784+ obj->mode = objcompat.mode;
66785+
66786+ obj->nested = compat_ptr(objcompat.nested);
66787+ obj->globbed = compat_ptr(objcompat.globbed);
66788+
66789+ obj->prev = compat_ptr(objcompat.prev);
66790+ obj->next = compat_ptr(objcompat.next);
66791+
66792+ return 0;
66793+}
66794+
66795+int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
66796+{
66797+ unsigned int i;
66798+ struct acl_subject_label_compat subjcompat;
66799+
66800+ if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
66801+ return -EFAULT;
66802+
66803+ subj->filename = compat_ptr(subjcompat.filename);
66804+ subj->inode = subjcompat.inode;
66805+ subj->device = subjcompat.device;
66806+ subj->mode = subjcompat.mode;
66807+ subj->cap_mask = subjcompat.cap_mask;
66808+ subj->cap_lower = subjcompat.cap_lower;
66809+ subj->cap_invert_audit = subjcompat.cap_invert_audit;
66810+
66811+ for (i = 0; i < GR_NLIMITS; i++) {
66812+ if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
66813+ subj->res[i].rlim_cur = RLIM_INFINITY;
66814+ else
66815+ subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
66816+ if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
66817+ subj->res[i].rlim_max = RLIM_INFINITY;
66818+ else
66819+ subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
66820+ }
66821+ subj->resmask = subjcompat.resmask;
66822+
66823+ subj->user_trans_type = subjcompat.user_trans_type;
66824+ subj->group_trans_type = subjcompat.group_trans_type;
66825+ subj->user_transitions = compat_ptr(subjcompat.user_transitions);
66826+ subj->group_transitions = compat_ptr(subjcompat.group_transitions);
66827+ subj->user_trans_num = subjcompat.user_trans_num;
66828+ subj->group_trans_num = subjcompat.group_trans_num;
66829+
66830+ memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
66831+ memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
66832+ subj->ip_type = subjcompat.ip_type;
66833+ subj->ips = compat_ptr(subjcompat.ips);
66834+ subj->ip_num = subjcompat.ip_num;
66835+ subj->inaddr_any_override = subjcompat.inaddr_any_override;
66836+
66837+ subj->crashes = subjcompat.crashes;
66838+ subj->expires = subjcompat.expires;
66839+
66840+ subj->parent_subject = compat_ptr(subjcompat.parent_subject);
66841+ subj->hash = compat_ptr(subjcompat.hash);
66842+ subj->prev = compat_ptr(subjcompat.prev);
66843+ subj->next = compat_ptr(subjcompat.next);
66844+
66845+ subj->obj_hash = compat_ptr(subjcompat.obj_hash);
66846+ subj->obj_hash_size = subjcompat.obj_hash_size;
66847+ subj->pax_flags = subjcompat.pax_flags;
66848+
66849+ return 0;
66850+}
66851+
66852+int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
66853+{
66854+ struct acl_role_label_compat rolecompat;
66855+
66856+ if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
66857+ return -EFAULT;
66858+
66859+ role->rolename = compat_ptr(rolecompat.rolename);
66860+ role->uidgid = rolecompat.uidgid;
66861+ role->roletype = rolecompat.roletype;
66862+
66863+ role->auth_attempts = rolecompat.auth_attempts;
66864+ role->expires = rolecompat.expires;
66865+
66866+ role->root_label = compat_ptr(rolecompat.root_label);
66867+ role->hash = compat_ptr(rolecompat.hash);
66868+
66869+ role->prev = compat_ptr(rolecompat.prev);
66870+ role->next = compat_ptr(rolecompat.next);
66871+
66872+ role->transitions = compat_ptr(rolecompat.transitions);
66873+ role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
66874+ role->domain_children = compat_ptr(rolecompat.domain_children);
66875+ role->domain_child_num = rolecompat.domain_child_num;
66876+
66877+ role->umask = rolecompat.umask;
66878+
66879+ role->subj_hash = compat_ptr(rolecompat.subj_hash);
66880+ role->subj_hash_size = rolecompat.subj_hash_size;
66881+
66882+ return 0;
66883+}
66884+
66885+int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
66886+{
66887+ struct role_allowed_ip_compat roleip_compat;
66888+
66889+ if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
66890+ return -EFAULT;
66891+
66892+ roleip->addr = roleip_compat.addr;
66893+ roleip->netmask = roleip_compat.netmask;
66894+
66895+ roleip->prev = compat_ptr(roleip_compat.prev);
66896+ roleip->next = compat_ptr(roleip_compat.next);
66897+
66898+ return 0;
66899+}
66900+
66901+int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
66902+{
66903+ struct role_transition_compat trans_compat;
66904+
66905+ if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
66906+ return -EFAULT;
66907+
66908+ trans->rolename = compat_ptr(trans_compat.rolename);
66909+
66910+ trans->prev = compat_ptr(trans_compat.prev);
66911+ trans->next = compat_ptr(trans_compat.next);
66912+
66913+ return 0;
66914+
66915+}
66916+
66917+int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
66918+{
66919+ struct gr_hash_struct_compat hash_compat;
66920+
66921+ if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
66922+ return -EFAULT;
66923+
66924+ hash->table = compat_ptr(hash_compat.table);
66925+ hash->nametable = compat_ptr(hash_compat.nametable);
66926+ hash->first = compat_ptr(hash_compat.first);
66927+
66928+ hash->table_size = hash_compat.table_size;
66929+ hash->used_size = hash_compat.used_size;
66930+
66931+ hash->type = hash_compat.type;
66932+
66933+ return 0;
66934+}
66935+
66936+int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
66937+{
66938+ compat_uptr_t ptrcompat;
66939+
66940+ if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
66941+ return -EFAULT;
66942+
66943+ *(void **)ptr = compat_ptr(ptrcompat);
66944+
66945+ return 0;
66946+}
66947+
66948+int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
66949+{
66950+ struct acl_ip_label_compat ip_compat;
66951+
66952+ if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
66953+ return -EFAULT;
66954+
66955+ ip->iface = compat_ptr(ip_compat.iface);
66956+ ip->addr = ip_compat.addr;
66957+ ip->netmask = ip_compat.netmask;
66958+ ip->low = ip_compat.low;
66959+ ip->high = ip_compat.high;
66960+ ip->mode = ip_compat.mode;
66961+ ip->type = ip_compat.type;
66962+
66963+ memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
66964+
66965+ ip->prev = compat_ptr(ip_compat.prev);
66966+ ip->next = compat_ptr(ip_compat.next);
66967+
66968+ return 0;
66969+}
66970+
66971+int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
66972+{
66973+ struct sprole_pw_compat pw_compat;
66974+
66975+ if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
66976+ return -EFAULT;
66977+
66978+ pw->rolename = compat_ptr(pw_compat.rolename);
66979+ memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
66980+ memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
66981+
66982+ return 0;
66983+}
66984+
66985+size_t get_gr_arg_wrapper_size_compat(void)
66986+{
66987+ return sizeof(struct gr_arg_wrapper_compat);
66988+}
66989+
66990diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
66991new file mode 100644
66992index 0000000..a340c17
66993--- /dev/null
66994+++ b/grsecurity/gracl_fs.c
66995@@ -0,0 +1,431 @@
66996+#include <linux/kernel.h>
66997+#include <linux/sched.h>
66998+#include <linux/types.h>
66999+#include <linux/fs.h>
67000+#include <linux/file.h>
67001+#include <linux/stat.h>
67002+#include <linux/grsecurity.h>
67003+#include <linux/grinternal.h>
67004+#include <linux/gracl.h>
67005+
67006+umode_t
67007+gr_acl_umask(void)
67008+{
67009+ if (unlikely(!gr_acl_is_enabled()))
67010+ return 0;
67011+
67012+ return current->role->umask;
67013+}
67014+
67015+__u32
67016+gr_acl_handle_hidden_file(const struct dentry * dentry,
67017+ const struct vfsmount * mnt)
67018+{
67019+ __u32 mode;
67020+
67021+ if (unlikely(!dentry->d_inode))
67022+ return GR_FIND;
67023+
67024+ mode =
67025+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
67026+
67027+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
67028+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
67029+ return mode;
67030+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
67031+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
67032+ return 0;
67033+ } else if (unlikely(!(mode & GR_FIND)))
67034+ return 0;
67035+
67036+ return GR_FIND;
67037+}
67038+
67039+__u32
67040+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
67041+ int acc_mode)
67042+{
67043+ __u32 reqmode = GR_FIND;
67044+ __u32 mode;
67045+
67046+ if (unlikely(!dentry->d_inode))
67047+ return reqmode;
67048+
67049+ if (acc_mode & MAY_APPEND)
67050+ reqmode |= GR_APPEND;
67051+ else if (acc_mode & MAY_WRITE)
67052+ reqmode |= GR_WRITE;
67053+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
67054+ reqmode |= GR_READ;
67055+
67056+ mode =
67057+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
67058+ mnt);
67059+
67060+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
67061+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
67062+ reqmode & GR_READ ? " reading" : "",
67063+ reqmode & GR_WRITE ? " writing" : reqmode &
67064+ GR_APPEND ? " appending" : "");
67065+ return reqmode;
67066+ } else
67067+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
67068+ {
67069+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
67070+ reqmode & GR_READ ? " reading" : "",
67071+ reqmode & GR_WRITE ? " writing" : reqmode &
67072+ GR_APPEND ? " appending" : "");
67073+ return 0;
67074+ } else if (unlikely((mode & reqmode) != reqmode))
67075+ return 0;
67076+
67077+ return reqmode;
67078+}
67079+
67080+__u32
67081+gr_acl_handle_creat(const struct dentry * dentry,
67082+ const struct dentry * p_dentry,
67083+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
67084+ const int imode)
67085+{
67086+ __u32 reqmode = GR_WRITE | GR_CREATE;
67087+ __u32 mode;
67088+
67089+ if (acc_mode & MAY_APPEND)
67090+ reqmode |= GR_APPEND;
67091+ // if a directory was required or the directory already exists, then
67092+ // don't count this open as a read
67093+ if ((acc_mode & MAY_READ) &&
67094+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
67095+ reqmode |= GR_READ;
67096+ if ((open_flags & O_CREAT) &&
67097+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
67098+ reqmode |= GR_SETID;
67099+
67100+ mode =
67101+ gr_check_create(dentry, p_dentry, p_mnt,
67102+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
67103+
67104+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
67105+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
67106+ reqmode & GR_READ ? " reading" : "",
67107+ reqmode & GR_WRITE ? " writing" : reqmode &
67108+ GR_APPEND ? " appending" : "");
67109+ return reqmode;
67110+ } else
67111+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
67112+ {
67113+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
67114+ reqmode & GR_READ ? " reading" : "",
67115+ reqmode & GR_WRITE ? " writing" : reqmode &
67116+ GR_APPEND ? " appending" : "");
67117+ return 0;
67118+ } else if (unlikely((mode & reqmode) != reqmode))
67119+ return 0;
67120+
67121+ return reqmode;
67122+}
67123+
67124+__u32
67125+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
67126+ const int fmode)
67127+{
67128+ __u32 mode, reqmode = GR_FIND;
67129+
67130+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
67131+ reqmode |= GR_EXEC;
67132+ if (fmode & S_IWOTH)
67133+ reqmode |= GR_WRITE;
67134+ if (fmode & S_IROTH)
67135+ reqmode |= GR_READ;
67136+
67137+ mode =
67138+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
67139+ mnt);
67140+
67141+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
67142+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
67143+ reqmode & GR_READ ? " reading" : "",
67144+ reqmode & GR_WRITE ? " writing" : "",
67145+ reqmode & GR_EXEC ? " executing" : "");
67146+ return reqmode;
67147+ } else
67148+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
67149+ {
67150+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
67151+ reqmode & GR_READ ? " reading" : "",
67152+ reqmode & GR_WRITE ? " writing" : "",
67153+ reqmode & GR_EXEC ? " executing" : "");
67154+ return 0;
67155+ } else if (unlikely((mode & reqmode) != reqmode))
67156+ return 0;
67157+
67158+ return reqmode;
67159+}
67160+
67161+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
67162+{
67163+ __u32 mode;
67164+
67165+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
67166+
67167+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
67168+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
67169+ return mode;
67170+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
67171+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
67172+ return 0;
67173+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
67174+ return 0;
67175+
67176+ return (reqmode);
67177+}
67178+
67179+__u32
67180+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
67181+{
67182+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
67183+}
67184+
67185+__u32
67186+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
67187+{
67188+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
67189+}
67190+
67191+__u32
67192+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
67193+{
67194+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
67195+}
67196+
67197+__u32
67198+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
67199+{
67200+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
67201+}
67202+
67203+__u32
67204+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
67205+ umode_t *modeptr)
67206+{
67207+ umode_t mode;
67208+
67209+ *modeptr &= ~gr_acl_umask();
67210+ mode = *modeptr;
67211+
67212+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
67213+ return 1;
67214+
67215+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
67216+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
67217+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
67218+ GR_CHMOD_ACL_MSG);
67219+ } else {
67220+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
67221+ }
67222+}
67223+
67224+__u32
67225+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
67226+{
67227+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
67228+}
67229+
67230+__u32
67231+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
67232+{
67233+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
67234+}
67235+
67236+__u32
67237+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
67238+{
67239+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
67240+}
67241+
67242+__u32
67243+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
67244+{
67245+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
67246+ GR_UNIXCONNECT_ACL_MSG);
67247+}
67248+
67249+/* hardlinks require at minimum create and link permission,
67250+ any additional privilege required is based on the
67251+ privilege of the file being linked to
67252+*/
67253+__u32
67254+gr_acl_handle_link(const struct dentry * new_dentry,
67255+ const struct dentry * parent_dentry,
67256+ const struct vfsmount * parent_mnt,
67257+ const struct dentry * old_dentry,
67258+ const struct vfsmount * old_mnt, const struct filename *to)
67259+{
67260+ __u32 mode;
67261+ __u32 needmode = GR_CREATE | GR_LINK;
67262+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
67263+
67264+ mode =
67265+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
67266+ old_mnt);
67267+
67268+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
67269+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
67270+ return mode;
67271+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
67272+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
67273+ return 0;
67274+ } else if (unlikely((mode & needmode) != needmode))
67275+ return 0;
67276+
67277+ return 1;
67278+}
67279+
67280+__u32
67281+gr_acl_handle_symlink(const struct dentry * new_dentry,
67282+ const struct dentry * parent_dentry,
67283+ const struct vfsmount * parent_mnt, const struct filename *from)
67284+{
67285+ __u32 needmode = GR_WRITE | GR_CREATE;
67286+ __u32 mode;
67287+
67288+ mode =
67289+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
67290+ GR_CREATE | GR_AUDIT_CREATE |
67291+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
67292+
67293+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
67294+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
67295+ return mode;
67296+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
67297+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
67298+ return 0;
67299+ } else if (unlikely((mode & needmode) != needmode))
67300+ return 0;
67301+
67302+ return (GR_WRITE | GR_CREATE);
67303+}
67304+
67305+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)
67306+{
67307+ __u32 mode;
67308+
67309+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
67310+
67311+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
67312+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
67313+ return mode;
67314+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
67315+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
67316+ return 0;
67317+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
67318+ return 0;
67319+
67320+ return (reqmode);
67321+}
67322+
67323+__u32
67324+gr_acl_handle_mknod(const struct dentry * new_dentry,
67325+ const struct dentry * parent_dentry,
67326+ const struct vfsmount * parent_mnt,
67327+ const int mode)
67328+{
67329+ __u32 reqmode = GR_WRITE | GR_CREATE;
67330+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
67331+ reqmode |= GR_SETID;
67332+
67333+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
67334+ reqmode, GR_MKNOD_ACL_MSG);
67335+}
67336+
67337+__u32
67338+gr_acl_handle_mkdir(const struct dentry *new_dentry,
67339+ const struct dentry *parent_dentry,
67340+ const struct vfsmount *parent_mnt)
67341+{
67342+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
67343+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
67344+}
67345+
67346+#define RENAME_CHECK_SUCCESS(old, new) \
67347+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
67348+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
67349+
67350+int
67351+gr_acl_handle_rename(struct dentry *new_dentry,
67352+ struct dentry *parent_dentry,
67353+ const struct vfsmount *parent_mnt,
67354+ struct dentry *old_dentry,
67355+ struct inode *old_parent_inode,
67356+ struct vfsmount *old_mnt, const struct filename *newname)
67357+{
67358+ __u32 comp1, comp2;
67359+ int error = 0;
67360+
67361+ if (unlikely(!gr_acl_is_enabled()))
67362+ return 0;
67363+
67364+ if (!new_dentry->d_inode) {
67365+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
67366+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
67367+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
67368+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
67369+ GR_DELETE | GR_AUDIT_DELETE |
67370+ GR_AUDIT_READ | GR_AUDIT_WRITE |
67371+ GR_SUPPRESS, old_mnt);
67372+ } else {
67373+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
67374+ GR_CREATE | GR_DELETE |
67375+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
67376+ GR_AUDIT_READ | GR_AUDIT_WRITE |
67377+ GR_SUPPRESS, parent_mnt);
67378+ comp2 =
67379+ gr_search_file(old_dentry,
67380+ GR_READ | GR_WRITE | GR_AUDIT_READ |
67381+ GR_DELETE | GR_AUDIT_DELETE |
67382+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
67383+ }
67384+
67385+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
67386+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
67387+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
67388+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
67389+ && !(comp2 & GR_SUPPRESS)) {
67390+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
67391+ error = -EACCES;
67392+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
67393+ error = -EACCES;
67394+
67395+ return error;
67396+}
67397+
67398+void
67399+gr_acl_handle_exit(void)
67400+{
67401+ u16 id;
67402+ char *rolename;
67403+
67404+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
67405+ !(current->role->roletype & GR_ROLE_PERSIST))) {
67406+ id = current->acl_role_id;
67407+ rolename = current->role->rolename;
67408+ gr_set_acls(1);
67409+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
67410+ }
67411+
67412+ gr_put_exec_file(current);
67413+ return;
67414+}
67415+
67416+int
67417+gr_acl_handle_procpidmem(const struct task_struct *task)
67418+{
67419+ if (unlikely(!gr_acl_is_enabled()))
67420+ return 0;
67421+
67422+ if (task != current && task->acl->mode & GR_PROTPROCFD)
67423+ return -EACCES;
67424+
67425+ return 0;
67426+}
67427diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
67428new file mode 100644
67429index 0000000..8132048
67430--- /dev/null
67431+++ b/grsecurity/gracl_ip.c
67432@@ -0,0 +1,387 @@
67433+#include <linux/kernel.h>
67434+#include <asm/uaccess.h>
67435+#include <asm/errno.h>
67436+#include <net/sock.h>
67437+#include <linux/file.h>
67438+#include <linux/fs.h>
67439+#include <linux/net.h>
67440+#include <linux/in.h>
67441+#include <linux/skbuff.h>
67442+#include <linux/ip.h>
67443+#include <linux/udp.h>
67444+#include <linux/types.h>
67445+#include <linux/sched.h>
67446+#include <linux/netdevice.h>
67447+#include <linux/inetdevice.h>
67448+#include <linux/gracl.h>
67449+#include <linux/grsecurity.h>
67450+#include <linux/grinternal.h>
67451+
67452+#define GR_BIND 0x01
67453+#define GR_CONNECT 0x02
67454+#define GR_INVERT 0x04
67455+#define GR_BINDOVERRIDE 0x08
67456+#define GR_CONNECTOVERRIDE 0x10
67457+#define GR_SOCK_FAMILY 0x20
67458+
67459+static const char * gr_protocols[IPPROTO_MAX] = {
67460+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
67461+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
67462+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
67463+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
67464+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
67465+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
67466+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
67467+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
67468+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
67469+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
67470+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
67471+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
67472+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
67473+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
67474+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
67475+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
67476+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
67477+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
67478+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
67479+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
67480+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
67481+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
67482+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
67483+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
67484+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
67485+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
67486+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
67487+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
67488+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
67489+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
67490+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
67491+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
67492+ };
67493+
67494+static const char * gr_socktypes[SOCK_MAX] = {
67495+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
67496+ "unknown:7", "unknown:8", "unknown:9", "packet"
67497+ };
67498+
67499+static const char * gr_sockfamilies[AF_MAX+1] = {
67500+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
67501+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
67502+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
67503+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
67504+ };
67505+
67506+const char *
67507+gr_proto_to_name(unsigned char proto)
67508+{
67509+ return gr_protocols[proto];
67510+}
67511+
67512+const char *
67513+gr_socktype_to_name(unsigned char type)
67514+{
67515+ return gr_socktypes[type];
67516+}
67517+
67518+const char *
67519+gr_sockfamily_to_name(unsigned char family)
67520+{
67521+ return gr_sockfamilies[family];
67522+}
67523+
67524+int
67525+gr_search_socket(const int domain, const int type, const int protocol)
67526+{
67527+ struct acl_subject_label *curr;
67528+ const struct cred *cred = current_cred();
67529+
67530+ if (unlikely(!gr_acl_is_enabled()))
67531+ goto exit;
67532+
67533+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
67534+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
67535+ goto exit; // let the kernel handle it
67536+
67537+ curr = current->acl;
67538+
67539+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
67540+ /* the family is allowed, if this is PF_INET allow it only if
67541+ the extra sock type/protocol checks pass */
67542+ if (domain == PF_INET)
67543+ goto inet_check;
67544+ goto exit;
67545+ } else {
67546+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
67547+ __u32 fakeip = 0;
67548+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67549+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67550+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67551+ gr_to_filename(current->exec_file->f_path.dentry,
67552+ current->exec_file->f_path.mnt) :
67553+ curr->filename, curr->filename,
67554+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
67555+ &current->signal->saved_ip);
67556+ goto exit;
67557+ }
67558+ goto exit_fail;
67559+ }
67560+
67561+inet_check:
67562+ /* the rest of this checking is for IPv4 only */
67563+ if (!curr->ips)
67564+ goto exit;
67565+
67566+ if ((curr->ip_type & (1U << type)) &&
67567+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
67568+ goto exit;
67569+
67570+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
67571+ /* we don't place acls on raw sockets , and sometimes
67572+ dgram/ip sockets are opened for ioctl and not
67573+ bind/connect, so we'll fake a bind learn log */
67574+ if (type == SOCK_RAW || type == SOCK_PACKET) {
67575+ __u32 fakeip = 0;
67576+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67577+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67578+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67579+ gr_to_filename(current->exec_file->f_path.dentry,
67580+ current->exec_file->f_path.mnt) :
67581+ curr->filename, curr->filename,
67582+ &fakeip, 0, type,
67583+ protocol, GR_CONNECT, &current->signal->saved_ip);
67584+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
67585+ __u32 fakeip = 0;
67586+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67587+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67588+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67589+ gr_to_filename(current->exec_file->f_path.dentry,
67590+ current->exec_file->f_path.mnt) :
67591+ curr->filename, curr->filename,
67592+ &fakeip, 0, type,
67593+ protocol, GR_BIND, &current->signal->saved_ip);
67594+ }
67595+ /* we'll log when they use connect or bind */
67596+ goto exit;
67597+ }
67598+
67599+exit_fail:
67600+ if (domain == PF_INET)
67601+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
67602+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
67603+ else
67604+#ifndef CONFIG_IPV6
67605+ if (domain != PF_INET6)
67606+#endif
67607+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
67608+ gr_socktype_to_name(type), protocol);
67609+
67610+ return 0;
67611+exit:
67612+ return 1;
67613+}
67614+
67615+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)
67616+{
67617+ if ((ip->mode & mode) &&
67618+ (ip_port >= ip->low) &&
67619+ (ip_port <= ip->high) &&
67620+ ((ntohl(ip_addr) & our_netmask) ==
67621+ (ntohl(our_addr) & our_netmask))
67622+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
67623+ && (ip->type & (1U << type))) {
67624+ if (ip->mode & GR_INVERT)
67625+ return 2; // specifically denied
67626+ else
67627+ return 1; // allowed
67628+ }
67629+
67630+ return 0; // not specifically allowed, may continue parsing
67631+}
67632+
67633+static int
67634+gr_search_connectbind(const int full_mode, struct sock *sk,
67635+ struct sockaddr_in *addr, const int type)
67636+{
67637+ char iface[IFNAMSIZ] = {0};
67638+ struct acl_subject_label *curr;
67639+ struct acl_ip_label *ip;
67640+ struct inet_sock *isk;
67641+ struct net_device *dev;
67642+ struct in_device *idev;
67643+ unsigned long i;
67644+ int ret;
67645+ int mode = full_mode & (GR_BIND | GR_CONNECT);
67646+ __u32 ip_addr = 0;
67647+ __u32 our_addr;
67648+ __u32 our_netmask;
67649+ char *p;
67650+ __u16 ip_port = 0;
67651+ const struct cred *cred = current_cred();
67652+
67653+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
67654+ return 0;
67655+
67656+ curr = current->acl;
67657+ isk = inet_sk(sk);
67658+
67659+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
67660+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
67661+ addr->sin_addr.s_addr = curr->inaddr_any_override;
67662+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
67663+ struct sockaddr_in saddr;
67664+ int err;
67665+
67666+ saddr.sin_family = AF_INET;
67667+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
67668+ saddr.sin_port = isk->inet_sport;
67669+
67670+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
67671+ if (err)
67672+ return err;
67673+
67674+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
67675+ if (err)
67676+ return err;
67677+ }
67678+
67679+ if (!curr->ips)
67680+ return 0;
67681+
67682+ ip_addr = addr->sin_addr.s_addr;
67683+ ip_port = ntohs(addr->sin_port);
67684+
67685+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
67686+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
67687+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
67688+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
67689+ gr_to_filename(current->exec_file->f_path.dentry,
67690+ current->exec_file->f_path.mnt) :
67691+ curr->filename, curr->filename,
67692+ &ip_addr, ip_port, type,
67693+ sk->sk_protocol, mode, &current->signal->saved_ip);
67694+ return 0;
67695+ }
67696+
67697+ for (i = 0; i < curr->ip_num; i++) {
67698+ ip = *(curr->ips + i);
67699+ if (ip->iface != NULL) {
67700+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
67701+ p = strchr(iface, ':');
67702+ if (p != NULL)
67703+ *p = '\0';
67704+ dev = dev_get_by_name(sock_net(sk), iface);
67705+ if (dev == NULL)
67706+ continue;
67707+ idev = in_dev_get(dev);
67708+ if (idev == NULL) {
67709+ dev_put(dev);
67710+ continue;
67711+ }
67712+ rcu_read_lock();
67713+ for_ifa(idev) {
67714+ if (!strcmp(ip->iface, ifa->ifa_label)) {
67715+ our_addr = ifa->ifa_address;
67716+ our_netmask = 0xffffffff;
67717+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
67718+ if (ret == 1) {
67719+ rcu_read_unlock();
67720+ in_dev_put(idev);
67721+ dev_put(dev);
67722+ return 0;
67723+ } else if (ret == 2) {
67724+ rcu_read_unlock();
67725+ in_dev_put(idev);
67726+ dev_put(dev);
67727+ goto denied;
67728+ }
67729+ }
67730+ } endfor_ifa(idev);
67731+ rcu_read_unlock();
67732+ in_dev_put(idev);
67733+ dev_put(dev);
67734+ } else {
67735+ our_addr = ip->addr;
67736+ our_netmask = ip->netmask;
67737+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
67738+ if (ret == 1)
67739+ return 0;
67740+ else if (ret == 2)
67741+ goto denied;
67742+ }
67743+ }
67744+
67745+denied:
67746+ if (mode == GR_BIND)
67747+ 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));
67748+ else if (mode == GR_CONNECT)
67749+ 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));
67750+
67751+ return -EACCES;
67752+}
67753+
67754+int
67755+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
67756+{
67757+ /* always allow disconnection of dgram sockets with connect */
67758+ if (addr->sin_family == AF_UNSPEC)
67759+ return 0;
67760+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
67761+}
67762+
67763+int
67764+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
67765+{
67766+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
67767+}
67768+
67769+int gr_search_listen(struct socket *sock)
67770+{
67771+ struct sock *sk = sock->sk;
67772+ struct sockaddr_in addr;
67773+
67774+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
67775+ addr.sin_port = inet_sk(sk)->inet_sport;
67776+
67777+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
67778+}
67779+
67780+int gr_search_accept(struct socket *sock)
67781+{
67782+ struct sock *sk = sock->sk;
67783+ struct sockaddr_in addr;
67784+
67785+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
67786+ addr.sin_port = inet_sk(sk)->inet_sport;
67787+
67788+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
67789+}
67790+
67791+int
67792+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
67793+{
67794+ if (addr)
67795+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
67796+ else {
67797+ struct sockaddr_in sin;
67798+ const struct inet_sock *inet = inet_sk(sk);
67799+
67800+ sin.sin_addr.s_addr = inet->inet_daddr;
67801+ sin.sin_port = inet->inet_dport;
67802+
67803+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
67804+ }
67805+}
67806+
67807+int
67808+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
67809+{
67810+ struct sockaddr_in sin;
67811+
67812+ if (unlikely(skb->len < sizeof (struct udphdr)))
67813+ return 0; // skip this packet
67814+
67815+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
67816+ sin.sin_port = udp_hdr(skb)->source;
67817+
67818+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
67819+}
67820diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
67821new file mode 100644
67822index 0000000..25f54ef
67823--- /dev/null
67824+++ b/grsecurity/gracl_learn.c
67825@@ -0,0 +1,207 @@
67826+#include <linux/kernel.h>
67827+#include <linux/mm.h>
67828+#include <linux/sched.h>
67829+#include <linux/poll.h>
67830+#include <linux/string.h>
67831+#include <linux/file.h>
67832+#include <linux/types.h>
67833+#include <linux/vmalloc.h>
67834+#include <linux/grinternal.h>
67835+
67836+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
67837+ size_t count, loff_t *ppos);
67838+extern int gr_acl_is_enabled(void);
67839+
67840+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
67841+static int gr_learn_attached;
67842+
67843+/* use a 512k buffer */
67844+#define LEARN_BUFFER_SIZE (512 * 1024)
67845+
67846+static DEFINE_SPINLOCK(gr_learn_lock);
67847+static DEFINE_MUTEX(gr_learn_user_mutex);
67848+
67849+/* we need to maintain two buffers, so that the kernel context of grlearn
67850+ uses a semaphore around the userspace copying, and the other kernel contexts
67851+ use a spinlock when copying into the buffer, since they cannot sleep
67852+*/
67853+static char *learn_buffer;
67854+static char *learn_buffer_user;
67855+static int learn_buffer_len;
67856+static int learn_buffer_user_len;
67857+
67858+static ssize_t
67859+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
67860+{
67861+ DECLARE_WAITQUEUE(wait, current);
67862+ ssize_t retval = 0;
67863+
67864+ add_wait_queue(&learn_wait, &wait);
67865+ set_current_state(TASK_INTERRUPTIBLE);
67866+ do {
67867+ mutex_lock(&gr_learn_user_mutex);
67868+ spin_lock(&gr_learn_lock);
67869+ if (learn_buffer_len)
67870+ break;
67871+ spin_unlock(&gr_learn_lock);
67872+ mutex_unlock(&gr_learn_user_mutex);
67873+ if (file->f_flags & O_NONBLOCK) {
67874+ retval = -EAGAIN;
67875+ goto out;
67876+ }
67877+ if (signal_pending(current)) {
67878+ retval = -ERESTARTSYS;
67879+ goto out;
67880+ }
67881+
67882+ schedule();
67883+ } while (1);
67884+
67885+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
67886+ learn_buffer_user_len = learn_buffer_len;
67887+ retval = learn_buffer_len;
67888+ learn_buffer_len = 0;
67889+
67890+ spin_unlock(&gr_learn_lock);
67891+
67892+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
67893+ retval = -EFAULT;
67894+
67895+ mutex_unlock(&gr_learn_user_mutex);
67896+out:
67897+ set_current_state(TASK_RUNNING);
67898+ remove_wait_queue(&learn_wait, &wait);
67899+ return retval;
67900+}
67901+
67902+static unsigned int
67903+poll_learn(struct file * file, poll_table * wait)
67904+{
67905+ poll_wait(file, &learn_wait, wait);
67906+
67907+ if (learn_buffer_len)
67908+ return (POLLIN | POLLRDNORM);
67909+
67910+ return 0;
67911+}
67912+
67913+void
67914+gr_clear_learn_entries(void)
67915+{
67916+ char *tmp;
67917+
67918+ mutex_lock(&gr_learn_user_mutex);
67919+ spin_lock(&gr_learn_lock);
67920+ tmp = learn_buffer;
67921+ learn_buffer = NULL;
67922+ spin_unlock(&gr_learn_lock);
67923+ if (tmp)
67924+ vfree(tmp);
67925+ if (learn_buffer_user != NULL) {
67926+ vfree(learn_buffer_user);
67927+ learn_buffer_user = NULL;
67928+ }
67929+ learn_buffer_len = 0;
67930+ mutex_unlock(&gr_learn_user_mutex);
67931+
67932+ return;
67933+}
67934+
67935+void
67936+gr_add_learn_entry(const char *fmt, ...)
67937+{
67938+ va_list args;
67939+ unsigned int len;
67940+
67941+ if (!gr_learn_attached)
67942+ return;
67943+
67944+ spin_lock(&gr_learn_lock);
67945+
67946+ /* leave a gap at the end so we know when it's "full" but don't have to
67947+ compute the exact length of the string we're trying to append
67948+ */
67949+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
67950+ spin_unlock(&gr_learn_lock);
67951+ wake_up_interruptible(&learn_wait);
67952+ return;
67953+ }
67954+ if (learn_buffer == NULL) {
67955+ spin_unlock(&gr_learn_lock);
67956+ return;
67957+ }
67958+
67959+ va_start(args, fmt);
67960+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
67961+ va_end(args);
67962+
67963+ learn_buffer_len += len + 1;
67964+
67965+ spin_unlock(&gr_learn_lock);
67966+ wake_up_interruptible(&learn_wait);
67967+
67968+ return;
67969+}
67970+
67971+static int
67972+open_learn(struct inode *inode, struct file *file)
67973+{
67974+ if (file->f_mode & FMODE_READ && gr_learn_attached)
67975+ return -EBUSY;
67976+ if (file->f_mode & FMODE_READ) {
67977+ int retval = 0;
67978+ mutex_lock(&gr_learn_user_mutex);
67979+ if (learn_buffer == NULL)
67980+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
67981+ if (learn_buffer_user == NULL)
67982+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
67983+ if (learn_buffer == NULL) {
67984+ retval = -ENOMEM;
67985+ goto out_error;
67986+ }
67987+ if (learn_buffer_user == NULL) {
67988+ retval = -ENOMEM;
67989+ goto out_error;
67990+ }
67991+ learn_buffer_len = 0;
67992+ learn_buffer_user_len = 0;
67993+ gr_learn_attached = 1;
67994+out_error:
67995+ mutex_unlock(&gr_learn_user_mutex);
67996+ return retval;
67997+ }
67998+ return 0;
67999+}
68000+
68001+static int
68002+close_learn(struct inode *inode, struct file *file)
68003+{
68004+ if (file->f_mode & FMODE_READ) {
68005+ char *tmp = NULL;
68006+ mutex_lock(&gr_learn_user_mutex);
68007+ spin_lock(&gr_learn_lock);
68008+ tmp = learn_buffer;
68009+ learn_buffer = NULL;
68010+ spin_unlock(&gr_learn_lock);
68011+ if (tmp)
68012+ vfree(tmp);
68013+ if (learn_buffer_user != NULL) {
68014+ vfree(learn_buffer_user);
68015+ learn_buffer_user = NULL;
68016+ }
68017+ learn_buffer_len = 0;
68018+ learn_buffer_user_len = 0;
68019+ gr_learn_attached = 0;
68020+ mutex_unlock(&gr_learn_user_mutex);
68021+ }
68022+
68023+ return 0;
68024+}
68025+
68026+const struct file_operations grsec_fops = {
68027+ .read = read_learn,
68028+ .write = write_grsec_handler,
68029+ .open = open_learn,
68030+ .release = close_learn,
68031+ .poll = poll_learn,
68032+};
68033diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
68034new file mode 100644
68035index 0000000..39645c9
68036--- /dev/null
68037+++ b/grsecurity/gracl_res.c
68038@@ -0,0 +1,68 @@
68039+#include <linux/kernel.h>
68040+#include <linux/sched.h>
68041+#include <linux/gracl.h>
68042+#include <linux/grinternal.h>
68043+
68044+static const char *restab_log[] = {
68045+ [RLIMIT_CPU] = "RLIMIT_CPU",
68046+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
68047+ [RLIMIT_DATA] = "RLIMIT_DATA",
68048+ [RLIMIT_STACK] = "RLIMIT_STACK",
68049+ [RLIMIT_CORE] = "RLIMIT_CORE",
68050+ [RLIMIT_RSS] = "RLIMIT_RSS",
68051+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
68052+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
68053+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
68054+ [RLIMIT_AS] = "RLIMIT_AS",
68055+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
68056+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
68057+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
68058+ [RLIMIT_NICE] = "RLIMIT_NICE",
68059+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
68060+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
68061+ [GR_CRASH_RES] = "RLIMIT_CRASH"
68062+};
68063+
68064+void
68065+gr_log_resource(const struct task_struct *task,
68066+ const int res, const unsigned long wanted, const int gt)
68067+{
68068+ const struct cred *cred;
68069+ unsigned long rlim;
68070+
68071+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
68072+ return;
68073+
68074+ // not yet supported resource
68075+ if (unlikely(!restab_log[res]))
68076+ return;
68077+
68078+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
68079+ rlim = task_rlimit_max(task, res);
68080+ else
68081+ rlim = task_rlimit(task, res);
68082+
68083+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
68084+ return;
68085+
68086+ rcu_read_lock();
68087+ cred = __task_cred(task);
68088+
68089+ if (res == RLIMIT_NPROC &&
68090+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
68091+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
68092+ goto out_rcu_unlock;
68093+ else if (res == RLIMIT_MEMLOCK &&
68094+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
68095+ goto out_rcu_unlock;
68096+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
68097+ goto out_rcu_unlock;
68098+ rcu_read_unlock();
68099+
68100+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
68101+
68102+ return;
68103+out_rcu_unlock:
68104+ rcu_read_unlock();
68105+ return;
68106+}
68107diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
68108new file mode 100644
68109index 0000000..3c38bfe
68110--- /dev/null
68111+++ b/grsecurity/gracl_segv.c
68112@@ -0,0 +1,305 @@
68113+#include <linux/kernel.h>
68114+#include <linux/mm.h>
68115+#include <asm/uaccess.h>
68116+#include <asm/errno.h>
68117+#include <asm/mman.h>
68118+#include <net/sock.h>
68119+#include <linux/file.h>
68120+#include <linux/fs.h>
68121+#include <linux/net.h>
68122+#include <linux/in.h>
68123+#include <linux/slab.h>
68124+#include <linux/types.h>
68125+#include <linux/sched.h>
68126+#include <linux/timer.h>
68127+#include <linux/gracl.h>
68128+#include <linux/grsecurity.h>
68129+#include <linux/grinternal.h>
68130+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
68131+#include <linux/magic.h>
68132+#include <linux/pagemap.h>
68133+#include "../fs/btrfs/async-thread.h"
68134+#include "../fs/btrfs/ctree.h"
68135+#include "../fs/btrfs/btrfs_inode.h"
68136+#endif
68137+
68138+static struct crash_uid *uid_set;
68139+static unsigned short uid_used;
68140+static DEFINE_SPINLOCK(gr_uid_lock);
68141+extern rwlock_t gr_inode_lock;
68142+extern struct acl_subject_label *
68143+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
68144+ struct acl_role_label *role);
68145+
68146+static inline dev_t __get_dev(const struct dentry *dentry)
68147+{
68148+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
68149+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
68150+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
68151+ else
68152+#endif
68153+ return dentry->d_sb->s_dev;
68154+}
68155+
68156+int
68157+gr_init_uidset(void)
68158+{
68159+ uid_set =
68160+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
68161+ uid_used = 0;
68162+
68163+ return uid_set ? 1 : 0;
68164+}
68165+
68166+void
68167+gr_free_uidset(void)
68168+{
68169+ if (uid_set)
68170+ kfree(uid_set);
68171+
68172+ return;
68173+}
68174+
68175+int
68176+gr_find_uid(const uid_t uid)
68177+{
68178+ struct crash_uid *tmp = uid_set;
68179+ uid_t buid;
68180+ int low = 0, high = uid_used - 1, mid;
68181+
68182+ while (high >= low) {
68183+ mid = (low + high) >> 1;
68184+ buid = tmp[mid].uid;
68185+ if (buid == uid)
68186+ return mid;
68187+ if (buid > uid)
68188+ high = mid - 1;
68189+ if (buid < uid)
68190+ low = mid + 1;
68191+ }
68192+
68193+ return -1;
68194+}
68195+
68196+static __inline__ void
68197+gr_insertsort(void)
68198+{
68199+ unsigned short i, j;
68200+ struct crash_uid index;
68201+
68202+ for (i = 1; i < uid_used; i++) {
68203+ index = uid_set[i];
68204+ j = i;
68205+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
68206+ uid_set[j] = uid_set[j - 1];
68207+ j--;
68208+ }
68209+ uid_set[j] = index;
68210+ }
68211+
68212+ return;
68213+}
68214+
68215+static __inline__ void
68216+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
68217+{
68218+ int loc;
68219+ uid_t uid = GR_GLOBAL_UID(kuid);
68220+
68221+ if (uid_used == GR_UIDTABLE_MAX)
68222+ return;
68223+
68224+ loc = gr_find_uid(uid);
68225+
68226+ if (loc >= 0) {
68227+ uid_set[loc].expires = expires;
68228+ return;
68229+ }
68230+
68231+ uid_set[uid_used].uid = uid;
68232+ uid_set[uid_used].expires = expires;
68233+ uid_used++;
68234+
68235+ gr_insertsort();
68236+
68237+ return;
68238+}
68239+
68240+void
68241+gr_remove_uid(const unsigned short loc)
68242+{
68243+ unsigned short i;
68244+
68245+ for (i = loc + 1; i < uid_used; i++)
68246+ uid_set[i - 1] = uid_set[i];
68247+
68248+ uid_used--;
68249+
68250+ return;
68251+}
68252+
68253+int
68254+gr_check_crash_uid(const kuid_t kuid)
68255+{
68256+ int loc;
68257+ int ret = 0;
68258+ uid_t uid;
68259+
68260+ if (unlikely(!gr_acl_is_enabled()))
68261+ return 0;
68262+
68263+ uid = GR_GLOBAL_UID(kuid);
68264+
68265+ spin_lock(&gr_uid_lock);
68266+ loc = gr_find_uid(uid);
68267+
68268+ if (loc < 0)
68269+ goto out_unlock;
68270+
68271+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
68272+ gr_remove_uid(loc);
68273+ else
68274+ ret = 1;
68275+
68276+out_unlock:
68277+ spin_unlock(&gr_uid_lock);
68278+ return ret;
68279+}
68280+
68281+static __inline__ int
68282+proc_is_setxid(const struct cred *cred)
68283+{
68284+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
68285+ !uid_eq(cred->uid, cred->fsuid))
68286+ return 1;
68287+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
68288+ !gid_eq(cred->gid, cred->fsgid))
68289+ return 1;
68290+
68291+ return 0;
68292+}
68293+
68294+extern int gr_fake_force_sig(int sig, struct task_struct *t);
68295+
68296+void
68297+gr_handle_crash(struct task_struct *task, const int sig)
68298+{
68299+ struct acl_subject_label *curr;
68300+ struct task_struct *tsk, *tsk2;
68301+ const struct cred *cred;
68302+ const struct cred *cred2;
68303+
68304+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
68305+ return;
68306+
68307+ if (unlikely(!gr_acl_is_enabled()))
68308+ return;
68309+
68310+ curr = task->acl;
68311+
68312+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
68313+ return;
68314+
68315+ if (time_before_eq(curr->expires, get_seconds())) {
68316+ curr->expires = 0;
68317+ curr->crashes = 0;
68318+ }
68319+
68320+ curr->crashes++;
68321+
68322+ if (!curr->expires)
68323+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
68324+
68325+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
68326+ time_after(curr->expires, get_seconds())) {
68327+ rcu_read_lock();
68328+ cred = __task_cred(task);
68329+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
68330+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
68331+ spin_lock(&gr_uid_lock);
68332+ gr_insert_uid(cred->uid, curr->expires);
68333+ spin_unlock(&gr_uid_lock);
68334+ curr->expires = 0;
68335+ curr->crashes = 0;
68336+ read_lock(&tasklist_lock);
68337+ do_each_thread(tsk2, tsk) {
68338+ cred2 = __task_cred(tsk);
68339+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
68340+ gr_fake_force_sig(SIGKILL, tsk);
68341+ } while_each_thread(tsk2, tsk);
68342+ read_unlock(&tasklist_lock);
68343+ } else {
68344+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
68345+ read_lock(&tasklist_lock);
68346+ read_lock(&grsec_exec_file_lock);
68347+ do_each_thread(tsk2, tsk) {
68348+ if (likely(tsk != task)) {
68349+ // if this thread has the same subject as the one that triggered
68350+ // RES_CRASH and it's the same binary, kill it
68351+ if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
68352+ gr_fake_force_sig(SIGKILL, tsk);
68353+ }
68354+ } while_each_thread(tsk2, tsk);
68355+ read_unlock(&grsec_exec_file_lock);
68356+ read_unlock(&tasklist_lock);
68357+ }
68358+ rcu_read_unlock();
68359+ }
68360+
68361+ return;
68362+}
68363+
68364+int
68365+gr_check_crash_exec(const struct file *filp)
68366+{
68367+ struct acl_subject_label *curr;
68368+
68369+ if (unlikely(!gr_acl_is_enabled()))
68370+ return 0;
68371+
68372+ read_lock(&gr_inode_lock);
68373+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
68374+ __get_dev(filp->f_path.dentry),
68375+ current->role);
68376+ read_unlock(&gr_inode_lock);
68377+
68378+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
68379+ (!curr->crashes && !curr->expires))
68380+ return 0;
68381+
68382+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
68383+ time_after(curr->expires, get_seconds()))
68384+ return 1;
68385+ else if (time_before_eq(curr->expires, get_seconds())) {
68386+ curr->crashes = 0;
68387+ curr->expires = 0;
68388+ }
68389+
68390+ return 0;
68391+}
68392+
68393+void
68394+gr_handle_alertkill(struct task_struct *task)
68395+{
68396+ struct acl_subject_label *curracl;
68397+ __u32 curr_ip;
68398+ struct task_struct *p, *p2;
68399+
68400+ if (unlikely(!gr_acl_is_enabled()))
68401+ return;
68402+
68403+ curracl = task->acl;
68404+ curr_ip = task->signal->curr_ip;
68405+
68406+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
68407+ read_lock(&tasklist_lock);
68408+ do_each_thread(p2, p) {
68409+ if (p->signal->curr_ip == curr_ip)
68410+ gr_fake_force_sig(SIGKILL, p);
68411+ } while_each_thread(p2, p);
68412+ read_unlock(&tasklist_lock);
68413+ } else if (curracl->mode & GR_KILLPROC)
68414+ gr_fake_force_sig(SIGKILL, task);
68415+
68416+ return;
68417+}
68418diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
68419new file mode 100644
68420index 0000000..98011b0
68421--- /dev/null
68422+++ b/grsecurity/gracl_shm.c
68423@@ -0,0 +1,40 @@
68424+#include <linux/kernel.h>
68425+#include <linux/mm.h>
68426+#include <linux/sched.h>
68427+#include <linux/file.h>
68428+#include <linux/ipc.h>
68429+#include <linux/gracl.h>
68430+#include <linux/grsecurity.h>
68431+#include <linux/grinternal.h>
68432+
68433+int
68434+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
68435+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
68436+{
68437+ struct task_struct *task;
68438+
68439+ if (!gr_acl_is_enabled())
68440+ return 1;
68441+
68442+ rcu_read_lock();
68443+ read_lock(&tasklist_lock);
68444+
68445+ task = find_task_by_vpid(shm_cprid);
68446+
68447+ if (unlikely(!task))
68448+ task = find_task_by_vpid(shm_lapid);
68449+
68450+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
68451+ (task_pid_nr(task) == shm_lapid)) &&
68452+ (task->acl->mode & GR_PROTSHM) &&
68453+ (task->acl != current->acl))) {
68454+ read_unlock(&tasklist_lock);
68455+ rcu_read_unlock();
68456+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
68457+ return 0;
68458+ }
68459+ read_unlock(&tasklist_lock);
68460+ rcu_read_unlock();
68461+
68462+ return 1;
68463+}
68464diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
68465new file mode 100644
68466index 0000000..bc0be01
68467--- /dev/null
68468+++ b/grsecurity/grsec_chdir.c
68469@@ -0,0 +1,19 @@
68470+#include <linux/kernel.h>
68471+#include <linux/sched.h>
68472+#include <linux/fs.h>
68473+#include <linux/file.h>
68474+#include <linux/grsecurity.h>
68475+#include <linux/grinternal.h>
68476+
68477+void
68478+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
68479+{
68480+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
68481+ if ((grsec_enable_chdir && grsec_enable_group &&
68482+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
68483+ !grsec_enable_group)) {
68484+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
68485+ }
68486+#endif
68487+ return;
68488+}
68489diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
68490new file mode 100644
68491index 0000000..bd6e105
68492--- /dev/null
68493+++ b/grsecurity/grsec_chroot.c
68494@@ -0,0 +1,370 @@
68495+#include <linux/kernel.h>
68496+#include <linux/module.h>
68497+#include <linux/sched.h>
68498+#include <linux/file.h>
68499+#include <linux/fs.h>
68500+#include <linux/mount.h>
68501+#include <linux/types.h>
68502+#include "../fs/mount.h"
68503+#include <linux/grsecurity.h>
68504+#include <linux/grinternal.h>
68505+
68506+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
68507+static int gr_init_ran;
68508+#endif
68509+
68510+void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
68511+{
68512+#ifdef CONFIG_GRKERNSEC
68513+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
68514+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
68515+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
68516+ && gr_init_ran
68517+#endif
68518+ )
68519+ task->gr_is_chrooted = 1;
68520+ else {
68521+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
68522+ if (task_pid_nr(task) == 1 && !gr_init_ran)
68523+ gr_init_ran = 1;
68524+#endif
68525+ task->gr_is_chrooted = 0;
68526+ }
68527+
68528+ task->gr_chroot_dentry = path->dentry;
68529+#endif
68530+ return;
68531+}
68532+
68533+void gr_clear_chroot_entries(struct task_struct *task)
68534+{
68535+#ifdef CONFIG_GRKERNSEC
68536+ task->gr_is_chrooted = 0;
68537+ task->gr_chroot_dentry = NULL;
68538+#endif
68539+ return;
68540+}
68541+
68542+int
68543+gr_handle_chroot_unix(const pid_t pid)
68544+{
68545+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
68546+ struct task_struct *p;
68547+
68548+ if (unlikely(!grsec_enable_chroot_unix))
68549+ return 1;
68550+
68551+ if (likely(!proc_is_chrooted(current)))
68552+ return 1;
68553+
68554+ rcu_read_lock();
68555+ read_lock(&tasklist_lock);
68556+ p = find_task_by_vpid_unrestricted(pid);
68557+ if (unlikely(p && !have_same_root(current, p))) {
68558+ read_unlock(&tasklist_lock);
68559+ rcu_read_unlock();
68560+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
68561+ return 0;
68562+ }
68563+ read_unlock(&tasklist_lock);
68564+ rcu_read_unlock();
68565+#endif
68566+ return 1;
68567+}
68568+
68569+int
68570+gr_handle_chroot_nice(void)
68571+{
68572+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
68573+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
68574+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
68575+ return -EPERM;
68576+ }
68577+#endif
68578+ return 0;
68579+}
68580+
68581+int
68582+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
68583+{
68584+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
68585+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
68586+ && proc_is_chrooted(current)) {
68587+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
68588+ return -EACCES;
68589+ }
68590+#endif
68591+ return 0;
68592+}
68593+
68594+int
68595+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
68596+{
68597+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
68598+ struct task_struct *p;
68599+ int ret = 0;
68600+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
68601+ return ret;
68602+
68603+ read_lock(&tasklist_lock);
68604+ do_each_pid_task(pid, type, p) {
68605+ if (!have_same_root(current, p)) {
68606+ ret = 1;
68607+ goto out;
68608+ }
68609+ } while_each_pid_task(pid, type, p);
68610+out:
68611+ read_unlock(&tasklist_lock);
68612+ return ret;
68613+#endif
68614+ return 0;
68615+}
68616+
68617+int
68618+gr_pid_is_chrooted(struct task_struct *p)
68619+{
68620+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
68621+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
68622+ return 0;
68623+
68624+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
68625+ !have_same_root(current, p)) {
68626+ return 1;
68627+ }
68628+#endif
68629+ return 0;
68630+}
68631+
68632+EXPORT_SYMBOL(gr_pid_is_chrooted);
68633+
68634+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
68635+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
68636+{
68637+ struct path path, currentroot;
68638+ int ret = 0;
68639+
68640+ path.dentry = (struct dentry *)u_dentry;
68641+ path.mnt = (struct vfsmount *)u_mnt;
68642+ get_fs_root(current->fs, &currentroot);
68643+ if (path_is_under(&path, &currentroot))
68644+ ret = 1;
68645+ path_put(&currentroot);
68646+
68647+ return ret;
68648+}
68649+#endif
68650+
68651+int
68652+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
68653+{
68654+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
68655+ if (!grsec_enable_chroot_fchdir)
68656+ return 1;
68657+
68658+ if (!proc_is_chrooted(current))
68659+ return 1;
68660+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
68661+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
68662+ return 0;
68663+ }
68664+#endif
68665+ return 1;
68666+}
68667+
68668+int
68669+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
68670+ const time_t shm_createtime)
68671+{
68672+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
68673+ struct task_struct *p;
68674+ time_t starttime;
68675+
68676+ if (unlikely(!grsec_enable_chroot_shmat))
68677+ return 1;
68678+
68679+ if (likely(!proc_is_chrooted(current)))
68680+ return 1;
68681+
68682+ rcu_read_lock();
68683+ read_lock(&tasklist_lock);
68684+
68685+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
68686+ starttime = p->start_time.tv_sec;
68687+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
68688+ if (have_same_root(current, p)) {
68689+ goto allow;
68690+ } else {
68691+ read_unlock(&tasklist_lock);
68692+ rcu_read_unlock();
68693+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
68694+ return 0;
68695+ }
68696+ }
68697+ /* creator exited, pid reuse, fall through to next check */
68698+ }
68699+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
68700+ if (unlikely(!have_same_root(current, p))) {
68701+ read_unlock(&tasklist_lock);
68702+ rcu_read_unlock();
68703+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
68704+ return 0;
68705+ }
68706+ }
68707+
68708+allow:
68709+ read_unlock(&tasklist_lock);
68710+ rcu_read_unlock();
68711+#endif
68712+ return 1;
68713+}
68714+
68715+void
68716+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
68717+{
68718+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
68719+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
68720+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
68721+#endif
68722+ return;
68723+}
68724+
68725+int
68726+gr_handle_chroot_mknod(const struct dentry *dentry,
68727+ const struct vfsmount *mnt, const int mode)
68728+{
68729+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
68730+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
68731+ proc_is_chrooted(current)) {
68732+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
68733+ return -EPERM;
68734+ }
68735+#endif
68736+ return 0;
68737+}
68738+
68739+int
68740+gr_handle_chroot_mount(const struct dentry *dentry,
68741+ const struct vfsmount *mnt, const char *dev_name)
68742+{
68743+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
68744+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
68745+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
68746+ return -EPERM;
68747+ }
68748+#endif
68749+ return 0;
68750+}
68751+
68752+int
68753+gr_handle_chroot_pivot(void)
68754+{
68755+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
68756+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
68757+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
68758+ return -EPERM;
68759+ }
68760+#endif
68761+ return 0;
68762+}
68763+
68764+int
68765+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
68766+{
68767+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
68768+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
68769+ !gr_is_outside_chroot(dentry, mnt)) {
68770+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
68771+ return -EPERM;
68772+ }
68773+#endif
68774+ return 0;
68775+}
68776+
68777+extern const char *captab_log[];
68778+extern int captab_log_entries;
68779+
68780+int
68781+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
68782+{
68783+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
68784+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
68785+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
68786+ if (cap_raised(chroot_caps, cap)) {
68787+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
68788+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
68789+ }
68790+ return 0;
68791+ }
68792+ }
68793+#endif
68794+ return 1;
68795+}
68796+
68797+int
68798+gr_chroot_is_capable(const int cap)
68799+{
68800+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
68801+ return gr_task_chroot_is_capable(current, current_cred(), cap);
68802+#endif
68803+ return 1;
68804+}
68805+
68806+int
68807+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
68808+{
68809+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
68810+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
68811+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
68812+ if (cap_raised(chroot_caps, cap)) {
68813+ return 0;
68814+ }
68815+ }
68816+#endif
68817+ return 1;
68818+}
68819+
68820+int
68821+gr_chroot_is_capable_nolog(const int cap)
68822+{
68823+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
68824+ return gr_task_chroot_is_capable_nolog(current, cap);
68825+#endif
68826+ return 1;
68827+}
68828+
68829+int
68830+gr_handle_chroot_sysctl(const int op)
68831+{
68832+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
68833+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
68834+ proc_is_chrooted(current))
68835+ return -EACCES;
68836+#endif
68837+ return 0;
68838+}
68839+
68840+void
68841+gr_handle_chroot_chdir(const struct path *path)
68842+{
68843+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
68844+ if (grsec_enable_chroot_chdir)
68845+ set_fs_pwd(current->fs, path);
68846+#endif
68847+ return;
68848+}
68849+
68850+int
68851+gr_handle_chroot_chmod(const struct dentry *dentry,
68852+ const struct vfsmount *mnt, const int mode)
68853+{
68854+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
68855+ /* allow chmod +s on directories, but not files */
68856+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
68857+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
68858+ proc_is_chrooted(current)) {
68859+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
68860+ return -EPERM;
68861+ }
68862+#endif
68863+ return 0;
68864+}
68865diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
68866new file mode 100644
68867index 0000000..ce65ceb
68868--- /dev/null
68869+++ b/grsecurity/grsec_disabled.c
68870@@ -0,0 +1,434 @@
68871+#include <linux/kernel.h>
68872+#include <linux/module.h>
68873+#include <linux/sched.h>
68874+#include <linux/file.h>
68875+#include <linux/fs.h>
68876+#include <linux/kdev_t.h>
68877+#include <linux/net.h>
68878+#include <linux/in.h>
68879+#include <linux/ip.h>
68880+#include <linux/skbuff.h>
68881+#include <linux/sysctl.h>
68882+
68883+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
68884+void
68885+pax_set_initial_flags(struct linux_binprm *bprm)
68886+{
68887+ return;
68888+}
68889+#endif
68890+
68891+#ifdef CONFIG_SYSCTL
68892+__u32
68893+gr_handle_sysctl(const struct ctl_table * table, const int op)
68894+{
68895+ return 0;
68896+}
68897+#endif
68898+
68899+#ifdef CONFIG_TASKSTATS
68900+int gr_is_taskstats_denied(int pid)
68901+{
68902+ return 0;
68903+}
68904+#endif
68905+
68906+int
68907+gr_acl_is_enabled(void)
68908+{
68909+ return 0;
68910+}
68911+
68912+void
68913+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
68914+{
68915+ return;
68916+}
68917+
68918+int
68919+gr_handle_rawio(const struct inode *inode)
68920+{
68921+ return 0;
68922+}
68923+
68924+void
68925+gr_acl_handle_psacct(struct task_struct *task, const long code)
68926+{
68927+ return;
68928+}
68929+
68930+int
68931+gr_handle_ptrace(struct task_struct *task, const long request)
68932+{
68933+ return 0;
68934+}
68935+
68936+int
68937+gr_handle_proc_ptrace(struct task_struct *task)
68938+{
68939+ return 0;
68940+}
68941+
68942+int
68943+gr_set_acls(const int type)
68944+{
68945+ return 0;
68946+}
68947+
68948+int
68949+gr_check_hidden_task(const struct task_struct *tsk)
68950+{
68951+ return 0;
68952+}
68953+
68954+int
68955+gr_check_protected_task(const struct task_struct *task)
68956+{
68957+ return 0;
68958+}
68959+
68960+int
68961+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
68962+{
68963+ return 0;
68964+}
68965+
68966+void
68967+gr_copy_label(struct task_struct *tsk)
68968+{
68969+ return;
68970+}
68971+
68972+void
68973+gr_set_pax_flags(struct task_struct *task)
68974+{
68975+ return;
68976+}
68977+
68978+int
68979+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
68980+ const int unsafe_share)
68981+{
68982+ return 0;
68983+}
68984+
68985+void
68986+gr_handle_delete(const ino_t ino, const dev_t dev)
68987+{
68988+ return;
68989+}
68990+
68991+void
68992+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
68993+{
68994+ return;
68995+}
68996+
68997+void
68998+gr_handle_crash(struct task_struct *task, const int sig)
68999+{
69000+ return;
69001+}
69002+
69003+int
69004+gr_check_crash_exec(const struct file *filp)
69005+{
69006+ return 0;
69007+}
69008+
69009+int
69010+gr_check_crash_uid(const kuid_t uid)
69011+{
69012+ return 0;
69013+}
69014+
69015+void
69016+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
69017+ struct dentry *old_dentry,
69018+ struct dentry *new_dentry,
69019+ struct vfsmount *mnt, const __u8 replace)
69020+{
69021+ return;
69022+}
69023+
69024+int
69025+gr_search_socket(const int family, const int type, const int protocol)
69026+{
69027+ return 1;
69028+}
69029+
69030+int
69031+gr_search_connectbind(const int mode, const struct socket *sock,
69032+ const struct sockaddr_in *addr)
69033+{
69034+ return 0;
69035+}
69036+
69037+void
69038+gr_handle_alertkill(struct task_struct *task)
69039+{
69040+ return;
69041+}
69042+
69043+__u32
69044+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
69045+{
69046+ return 1;
69047+}
69048+
69049+__u32
69050+gr_acl_handle_hidden_file(const struct dentry * dentry,
69051+ const struct vfsmount * mnt)
69052+{
69053+ return 1;
69054+}
69055+
69056+__u32
69057+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
69058+ int acc_mode)
69059+{
69060+ return 1;
69061+}
69062+
69063+__u32
69064+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
69065+{
69066+ return 1;
69067+}
69068+
69069+__u32
69070+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
69071+{
69072+ return 1;
69073+}
69074+
69075+int
69076+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
69077+ unsigned int *vm_flags)
69078+{
69079+ return 1;
69080+}
69081+
69082+__u32
69083+gr_acl_handle_truncate(const struct dentry * dentry,
69084+ const struct vfsmount * mnt)
69085+{
69086+ return 1;
69087+}
69088+
69089+__u32
69090+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
69091+{
69092+ return 1;
69093+}
69094+
69095+__u32
69096+gr_acl_handle_access(const struct dentry * dentry,
69097+ const struct vfsmount * mnt, const int fmode)
69098+{
69099+ return 1;
69100+}
69101+
69102+__u32
69103+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
69104+ umode_t *mode)
69105+{
69106+ return 1;
69107+}
69108+
69109+__u32
69110+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
69111+{
69112+ return 1;
69113+}
69114+
69115+__u32
69116+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
69117+{
69118+ return 1;
69119+}
69120+
69121+void
69122+grsecurity_init(void)
69123+{
69124+ return;
69125+}
69126+
69127+umode_t gr_acl_umask(void)
69128+{
69129+ return 0;
69130+}
69131+
69132+__u32
69133+gr_acl_handle_mknod(const struct dentry * new_dentry,
69134+ const struct dentry * parent_dentry,
69135+ const struct vfsmount * parent_mnt,
69136+ const int mode)
69137+{
69138+ return 1;
69139+}
69140+
69141+__u32
69142+gr_acl_handle_mkdir(const struct dentry * new_dentry,
69143+ const struct dentry * parent_dentry,
69144+ const struct vfsmount * parent_mnt)
69145+{
69146+ return 1;
69147+}
69148+
69149+__u32
69150+gr_acl_handle_symlink(const struct dentry * new_dentry,
69151+ const struct dentry * parent_dentry,
69152+ const struct vfsmount * parent_mnt, const struct filename *from)
69153+{
69154+ return 1;
69155+}
69156+
69157+__u32
69158+gr_acl_handle_link(const struct dentry * new_dentry,
69159+ const struct dentry * parent_dentry,
69160+ const struct vfsmount * parent_mnt,
69161+ const struct dentry * old_dentry,
69162+ const struct vfsmount * old_mnt, const struct filename *to)
69163+{
69164+ return 1;
69165+}
69166+
69167+int
69168+gr_acl_handle_rename(const struct dentry *new_dentry,
69169+ const struct dentry *parent_dentry,
69170+ const struct vfsmount *parent_mnt,
69171+ const struct dentry *old_dentry,
69172+ const struct inode *old_parent_inode,
69173+ const struct vfsmount *old_mnt, const struct filename *newname)
69174+{
69175+ return 0;
69176+}
69177+
69178+int
69179+gr_acl_handle_filldir(const struct file *file, const char *name,
69180+ const int namelen, const ino_t ino)
69181+{
69182+ return 1;
69183+}
69184+
69185+int
69186+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
69187+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
69188+{
69189+ return 1;
69190+}
69191+
69192+int
69193+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
69194+{
69195+ return 0;
69196+}
69197+
69198+int
69199+gr_search_accept(const struct socket *sock)
69200+{
69201+ return 0;
69202+}
69203+
69204+int
69205+gr_search_listen(const struct socket *sock)
69206+{
69207+ return 0;
69208+}
69209+
69210+int
69211+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
69212+{
69213+ return 0;
69214+}
69215+
69216+__u32
69217+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
69218+{
69219+ return 1;
69220+}
69221+
69222+__u32
69223+gr_acl_handle_creat(const struct dentry * dentry,
69224+ const struct dentry * p_dentry,
69225+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
69226+ const int imode)
69227+{
69228+ return 1;
69229+}
69230+
69231+void
69232+gr_acl_handle_exit(void)
69233+{
69234+ return;
69235+}
69236+
69237+int
69238+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
69239+{
69240+ return 1;
69241+}
69242+
69243+void
69244+gr_set_role_label(const kuid_t uid, const kgid_t gid)
69245+{
69246+ return;
69247+}
69248+
69249+int
69250+gr_acl_handle_procpidmem(const struct task_struct *task)
69251+{
69252+ return 0;
69253+}
69254+
69255+int
69256+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
69257+{
69258+ return 0;
69259+}
69260+
69261+int
69262+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
69263+{
69264+ return 0;
69265+}
69266+
69267+void
69268+gr_set_kernel_label(struct task_struct *task)
69269+{
69270+ return;
69271+}
69272+
69273+int
69274+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
69275+{
69276+ return 0;
69277+}
69278+
69279+int
69280+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
69281+{
69282+ return 0;
69283+}
69284+
69285+int gr_acl_enable_at_secure(void)
69286+{
69287+ return 0;
69288+}
69289+
69290+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
69291+{
69292+ return dentry->d_sb->s_dev;
69293+}
69294+
69295+void gr_put_exec_file(struct task_struct *task)
69296+{
69297+ return;
69298+}
69299+
69300+EXPORT_SYMBOL(gr_set_kernel_label);
69301+#ifdef CONFIG_SECURITY
69302+EXPORT_SYMBOL(gr_check_user_change);
69303+EXPORT_SYMBOL(gr_check_group_change);
69304+#endif
69305diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
69306new file mode 100644
69307index 0000000..387032b
69308--- /dev/null
69309+++ b/grsecurity/grsec_exec.c
69310@@ -0,0 +1,187 @@
69311+#include <linux/kernel.h>
69312+#include <linux/sched.h>
69313+#include <linux/file.h>
69314+#include <linux/binfmts.h>
69315+#include <linux/fs.h>
69316+#include <linux/types.h>
69317+#include <linux/grdefs.h>
69318+#include <linux/grsecurity.h>
69319+#include <linux/grinternal.h>
69320+#include <linux/capability.h>
69321+#include <linux/module.h>
69322+#include <linux/compat.h>
69323+
69324+#include <asm/uaccess.h>
69325+
69326+#ifdef CONFIG_GRKERNSEC_EXECLOG
69327+static char gr_exec_arg_buf[132];
69328+static DEFINE_MUTEX(gr_exec_arg_mutex);
69329+#endif
69330+
69331+struct user_arg_ptr {
69332+#ifdef CONFIG_COMPAT
69333+ bool is_compat;
69334+#endif
69335+ union {
69336+ const char __user *const __user *native;
69337+#ifdef CONFIG_COMPAT
69338+ const compat_uptr_t __user *compat;
69339+#endif
69340+ } ptr;
69341+};
69342+
69343+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
69344+
69345+void
69346+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
69347+{
69348+#ifdef CONFIG_GRKERNSEC_EXECLOG
69349+ char *grarg = gr_exec_arg_buf;
69350+ unsigned int i, x, execlen = 0;
69351+ char c;
69352+
69353+ if (!((grsec_enable_execlog && grsec_enable_group &&
69354+ in_group_p(grsec_audit_gid))
69355+ || (grsec_enable_execlog && !grsec_enable_group)))
69356+ return;
69357+
69358+ mutex_lock(&gr_exec_arg_mutex);
69359+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
69360+
69361+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
69362+ const char __user *p;
69363+ unsigned int len;
69364+
69365+ p = get_user_arg_ptr(argv, i);
69366+ if (IS_ERR(p))
69367+ goto log;
69368+
69369+ len = strnlen_user(p, 128 - execlen);
69370+ if (len > 128 - execlen)
69371+ len = 128 - execlen;
69372+ else if (len > 0)
69373+ len--;
69374+ if (copy_from_user(grarg + execlen, p, len))
69375+ goto log;
69376+
69377+ /* rewrite unprintable characters */
69378+ for (x = 0; x < len; x++) {
69379+ c = *(grarg + execlen + x);
69380+ if (c < 32 || c > 126)
69381+ *(grarg + execlen + x) = ' ';
69382+ }
69383+
69384+ execlen += len;
69385+ *(grarg + execlen) = ' ';
69386+ *(grarg + execlen + 1) = '\0';
69387+ execlen++;
69388+ }
69389+
69390+ log:
69391+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
69392+ bprm->file->f_path.mnt, grarg);
69393+ mutex_unlock(&gr_exec_arg_mutex);
69394+#endif
69395+ return;
69396+}
69397+
69398+#ifdef CONFIG_GRKERNSEC
69399+extern int gr_acl_is_capable(const int cap);
69400+extern int gr_acl_is_capable_nolog(const int cap);
69401+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
69402+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
69403+extern int gr_chroot_is_capable(const int cap);
69404+extern int gr_chroot_is_capable_nolog(const int cap);
69405+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
69406+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
69407+#endif
69408+
69409+const char *captab_log[] = {
69410+ "CAP_CHOWN",
69411+ "CAP_DAC_OVERRIDE",
69412+ "CAP_DAC_READ_SEARCH",
69413+ "CAP_FOWNER",
69414+ "CAP_FSETID",
69415+ "CAP_KILL",
69416+ "CAP_SETGID",
69417+ "CAP_SETUID",
69418+ "CAP_SETPCAP",
69419+ "CAP_LINUX_IMMUTABLE",
69420+ "CAP_NET_BIND_SERVICE",
69421+ "CAP_NET_BROADCAST",
69422+ "CAP_NET_ADMIN",
69423+ "CAP_NET_RAW",
69424+ "CAP_IPC_LOCK",
69425+ "CAP_IPC_OWNER",
69426+ "CAP_SYS_MODULE",
69427+ "CAP_SYS_RAWIO",
69428+ "CAP_SYS_CHROOT",
69429+ "CAP_SYS_PTRACE",
69430+ "CAP_SYS_PACCT",
69431+ "CAP_SYS_ADMIN",
69432+ "CAP_SYS_BOOT",
69433+ "CAP_SYS_NICE",
69434+ "CAP_SYS_RESOURCE",
69435+ "CAP_SYS_TIME",
69436+ "CAP_SYS_TTY_CONFIG",
69437+ "CAP_MKNOD",
69438+ "CAP_LEASE",
69439+ "CAP_AUDIT_WRITE",
69440+ "CAP_AUDIT_CONTROL",
69441+ "CAP_SETFCAP",
69442+ "CAP_MAC_OVERRIDE",
69443+ "CAP_MAC_ADMIN",
69444+ "CAP_SYSLOG",
69445+ "CAP_WAKE_ALARM"
69446+};
69447+
69448+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
69449+
69450+int gr_is_capable(const int cap)
69451+{
69452+#ifdef CONFIG_GRKERNSEC
69453+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
69454+ return 1;
69455+ return 0;
69456+#else
69457+ return 1;
69458+#endif
69459+}
69460+
69461+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
69462+{
69463+#ifdef CONFIG_GRKERNSEC
69464+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
69465+ return 1;
69466+ return 0;
69467+#else
69468+ return 1;
69469+#endif
69470+}
69471+
69472+int gr_is_capable_nolog(const int cap)
69473+{
69474+#ifdef CONFIG_GRKERNSEC
69475+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
69476+ return 1;
69477+ return 0;
69478+#else
69479+ return 1;
69480+#endif
69481+}
69482+
69483+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
69484+{
69485+#ifdef CONFIG_GRKERNSEC
69486+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
69487+ return 1;
69488+ return 0;
69489+#else
69490+ return 1;
69491+#endif
69492+}
69493+
69494+EXPORT_SYMBOL(gr_is_capable);
69495+EXPORT_SYMBOL(gr_is_capable_nolog);
69496+EXPORT_SYMBOL(gr_task_is_capable);
69497+EXPORT_SYMBOL(gr_task_is_capable_nolog);
69498diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
69499new file mode 100644
69500index 0000000..06cc6ea
69501--- /dev/null
69502+++ b/grsecurity/grsec_fifo.c
69503@@ -0,0 +1,24 @@
69504+#include <linux/kernel.h>
69505+#include <linux/sched.h>
69506+#include <linux/fs.h>
69507+#include <linux/file.h>
69508+#include <linux/grinternal.h>
69509+
69510+int
69511+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
69512+ const struct dentry *dir, const int flag, const int acc_mode)
69513+{
69514+#ifdef CONFIG_GRKERNSEC_FIFO
69515+ const struct cred *cred = current_cred();
69516+
69517+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
69518+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
69519+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
69520+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
69521+ if (!inode_permission(dentry->d_inode, acc_mode))
69522+ 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));
69523+ return -EACCES;
69524+ }
69525+#endif
69526+ return 0;
69527+}
69528diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
69529new file mode 100644
69530index 0000000..8ca18bf
69531--- /dev/null
69532+++ b/grsecurity/grsec_fork.c
69533@@ -0,0 +1,23 @@
69534+#include <linux/kernel.h>
69535+#include <linux/sched.h>
69536+#include <linux/grsecurity.h>
69537+#include <linux/grinternal.h>
69538+#include <linux/errno.h>
69539+
69540+void
69541+gr_log_forkfail(const int retval)
69542+{
69543+#ifdef CONFIG_GRKERNSEC_FORKFAIL
69544+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
69545+ switch (retval) {
69546+ case -EAGAIN:
69547+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
69548+ break;
69549+ case -ENOMEM:
69550+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
69551+ break;
69552+ }
69553+ }
69554+#endif
69555+ return;
69556+}
69557diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
69558new file mode 100644
69559index 0000000..99a0cb9
69560--- /dev/null
69561+++ b/grsecurity/grsec_init.c
69562@@ -0,0 +1,283 @@
69563+#include <linux/kernel.h>
69564+#include <linux/sched.h>
69565+#include <linux/mm.h>
69566+#include <linux/gracl.h>
69567+#include <linux/slab.h>
69568+#include <linux/vmalloc.h>
69569+#include <linux/percpu.h>
69570+#include <linux/module.h>
69571+
69572+int grsec_enable_ptrace_readexec;
69573+int grsec_enable_setxid;
69574+int grsec_enable_symlinkown;
69575+kgid_t grsec_symlinkown_gid;
69576+int grsec_enable_brute;
69577+int grsec_enable_link;
69578+int grsec_enable_dmesg;
69579+int grsec_enable_harden_ptrace;
69580+int grsec_enable_fifo;
69581+int grsec_enable_execlog;
69582+int grsec_enable_signal;
69583+int grsec_enable_forkfail;
69584+int grsec_enable_audit_ptrace;
69585+int grsec_enable_time;
69586+int grsec_enable_group;
69587+kgid_t grsec_audit_gid;
69588+int grsec_enable_chdir;
69589+int grsec_enable_mount;
69590+int grsec_enable_rofs;
69591+int grsec_deny_new_usb;
69592+int grsec_enable_chroot_findtask;
69593+int grsec_enable_chroot_mount;
69594+int grsec_enable_chroot_shmat;
69595+int grsec_enable_chroot_fchdir;
69596+int grsec_enable_chroot_double;
69597+int grsec_enable_chroot_pivot;
69598+int grsec_enable_chroot_chdir;
69599+int grsec_enable_chroot_chmod;
69600+int grsec_enable_chroot_mknod;
69601+int grsec_enable_chroot_nice;
69602+int grsec_enable_chroot_execlog;
69603+int grsec_enable_chroot_caps;
69604+int grsec_enable_chroot_sysctl;
69605+int grsec_enable_chroot_unix;
69606+int grsec_enable_tpe;
69607+kgid_t grsec_tpe_gid;
69608+int grsec_enable_blackhole;
69609+#ifdef CONFIG_IPV6_MODULE
69610+EXPORT_SYMBOL(grsec_enable_blackhole);
69611+#endif
69612+int grsec_lastack_retries;
69613+int grsec_enable_tpe_all;
69614+int grsec_enable_tpe_invert;
69615+int grsec_enable_socket_all;
69616+kgid_t grsec_socket_all_gid;
69617+int grsec_enable_socket_client;
69618+kgid_t grsec_socket_client_gid;
69619+int grsec_enable_socket_server;
69620+kgid_t grsec_socket_server_gid;
69621+int grsec_resource_logging;
69622+int grsec_disable_privio;
69623+int grsec_enable_log_rwxmaps;
69624+int grsec_lock;
69625+
69626+DEFINE_SPINLOCK(grsec_alert_lock);
69627+unsigned long grsec_alert_wtime = 0;
69628+unsigned long grsec_alert_fyet = 0;
69629+
69630+DEFINE_SPINLOCK(grsec_audit_lock);
69631+
69632+DEFINE_RWLOCK(grsec_exec_file_lock);
69633+
69634+char *gr_shared_page[4];
69635+
69636+char *gr_alert_log_fmt;
69637+char *gr_audit_log_fmt;
69638+char *gr_alert_log_buf;
69639+char *gr_audit_log_buf;
69640+
69641+extern struct gr_arg *gr_usermode;
69642+extern unsigned char *gr_system_salt;
69643+extern unsigned char *gr_system_sum;
69644+
69645+void __init
69646+grsecurity_init(void)
69647+{
69648+ int j;
69649+ /* create the per-cpu shared pages */
69650+
69651+#ifdef CONFIG_X86
69652+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
69653+#endif
69654+
69655+ for (j = 0; j < 4; j++) {
69656+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
69657+ if (gr_shared_page[j] == NULL) {
69658+ panic("Unable to allocate grsecurity shared page");
69659+ return;
69660+ }
69661+ }
69662+
69663+ /* allocate log buffers */
69664+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
69665+ if (!gr_alert_log_fmt) {
69666+ panic("Unable to allocate grsecurity alert log format buffer");
69667+ return;
69668+ }
69669+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
69670+ if (!gr_audit_log_fmt) {
69671+ panic("Unable to allocate grsecurity audit log format buffer");
69672+ return;
69673+ }
69674+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
69675+ if (!gr_alert_log_buf) {
69676+ panic("Unable to allocate grsecurity alert log buffer");
69677+ return;
69678+ }
69679+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
69680+ if (!gr_audit_log_buf) {
69681+ panic("Unable to allocate grsecurity audit log buffer");
69682+ return;
69683+ }
69684+
69685+ /* allocate memory for authentication structure */
69686+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
69687+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
69688+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
69689+
69690+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
69691+ panic("Unable to allocate grsecurity authentication structure");
69692+ return;
69693+ }
69694+
69695+
69696+#ifdef CONFIG_GRKERNSEC_IO
69697+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
69698+ grsec_disable_privio = 1;
69699+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
69700+ grsec_disable_privio = 1;
69701+#else
69702+ grsec_disable_privio = 0;
69703+#endif
69704+#endif
69705+
69706+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
69707+ /* for backward compatibility, tpe_invert always defaults to on if
69708+ enabled in the kernel
69709+ */
69710+ grsec_enable_tpe_invert = 1;
69711+#endif
69712+
69713+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
69714+#ifndef CONFIG_GRKERNSEC_SYSCTL
69715+ grsec_lock = 1;
69716+#endif
69717+
69718+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
69719+ grsec_enable_log_rwxmaps = 1;
69720+#endif
69721+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
69722+ grsec_enable_group = 1;
69723+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
69724+#endif
69725+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
69726+ grsec_enable_ptrace_readexec = 1;
69727+#endif
69728+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
69729+ grsec_enable_chdir = 1;
69730+#endif
69731+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
69732+ grsec_enable_harden_ptrace = 1;
69733+#endif
69734+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
69735+ grsec_enable_mount = 1;
69736+#endif
69737+#ifdef CONFIG_GRKERNSEC_LINK
69738+ grsec_enable_link = 1;
69739+#endif
69740+#ifdef CONFIG_GRKERNSEC_BRUTE
69741+ grsec_enable_brute = 1;
69742+#endif
69743+#ifdef CONFIG_GRKERNSEC_DMESG
69744+ grsec_enable_dmesg = 1;
69745+#endif
69746+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
69747+ grsec_enable_blackhole = 1;
69748+ grsec_lastack_retries = 4;
69749+#endif
69750+#ifdef CONFIG_GRKERNSEC_FIFO
69751+ grsec_enable_fifo = 1;
69752+#endif
69753+#ifdef CONFIG_GRKERNSEC_EXECLOG
69754+ grsec_enable_execlog = 1;
69755+#endif
69756+#ifdef CONFIG_GRKERNSEC_SETXID
69757+ grsec_enable_setxid = 1;
69758+#endif
69759+#ifdef CONFIG_GRKERNSEC_SIGNAL
69760+ grsec_enable_signal = 1;
69761+#endif
69762+#ifdef CONFIG_GRKERNSEC_FORKFAIL
69763+ grsec_enable_forkfail = 1;
69764+#endif
69765+#ifdef CONFIG_GRKERNSEC_TIME
69766+ grsec_enable_time = 1;
69767+#endif
69768+#ifdef CONFIG_GRKERNSEC_RESLOG
69769+ grsec_resource_logging = 1;
69770+#endif
69771+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
69772+ grsec_enable_chroot_findtask = 1;
69773+#endif
69774+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
69775+ grsec_enable_chroot_unix = 1;
69776+#endif
69777+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
69778+ grsec_enable_chroot_mount = 1;
69779+#endif
69780+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
69781+ grsec_enable_chroot_fchdir = 1;
69782+#endif
69783+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
69784+ grsec_enable_chroot_shmat = 1;
69785+#endif
69786+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
69787+ grsec_enable_audit_ptrace = 1;
69788+#endif
69789+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
69790+ grsec_enable_chroot_double = 1;
69791+#endif
69792+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
69793+ grsec_enable_chroot_pivot = 1;
69794+#endif
69795+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
69796+ grsec_enable_chroot_chdir = 1;
69797+#endif
69798+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
69799+ grsec_enable_chroot_chmod = 1;
69800+#endif
69801+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
69802+ grsec_enable_chroot_mknod = 1;
69803+#endif
69804+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
69805+ grsec_enable_chroot_nice = 1;
69806+#endif
69807+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
69808+ grsec_enable_chroot_execlog = 1;
69809+#endif
69810+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
69811+ grsec_enable_chroot_caps = 1;
69812+#endif
69813+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
69814+ grsec_enable_chroot_sysctl = 1;
69815+#endif
69816+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
69817+ grsec_enable_symlinkown = 1;
69818+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
69819+#endif
69820+#ifdef CONFIG_GRKERNSEC_TPE
69821+ grsec_enable_tpe = 1;
69822+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
69823+#ifdef CONFIG_GRKERNSEC_TPE_ALL
69824+ grsec_enable_tpe_all = 1;
69825+#endif
69826+#endif
69827+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
69828+ grsec_enable_socket_all = 1;
69829+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
69830+#endif
69831+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
69832+ grsec_enable_socket_client = 1;
69833+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
69834+#endif
69835+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
69836+ grsec_enable_socket_server = 1;
69837+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
69838+#endif
69839+#endif
69840+#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
69841+ grsec_deny_new_usb = 1;
69842+#endif
69843+
69844+ return;
69845+}
69846diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
69847new file mode 100644
69848index 0000000..5e05e20
69849--- /dev/null
69850+++ b/grsecurity/grsec_link.c
69851@@ -0,0 +1,58 @@
69852+#include <linux/kernel.h>
69853+#include <linux/sched.h>
69854+#include <linux/fs.h>
69855+#include <linux/file.h>
69856+#include <linux/grinternal.h>
69857+
69858+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
69859+{
69860+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
69861+ const struct inode *link_inode = link->dentry->d_inode;
69862+
69863+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
69864+ /* ignore root-owned links, e.g. /proc/self */
69865+ gr_is_global_nonroot(link_inode->i_uid) && target &&
69866+ !uid_eq(link_inode->i_uid, target->i_uid)) {
69867+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
69868+ return 1;
69869+ }
69870+#endif
69871+ return 0;
69872+}
69873+
69874+int
69875+gr_handle_follow_link(const struct inode *parent,
69876+ const struct inode *inode,
69877+ const struct dentry *dentry, const struct vfsmount *mnt)
69878+{
69879+#ifdef CONFIG_GRKERNSEC_LINK
69880+ const struct cred *cred = current_cred();
69881+
69882+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
69883+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
69884+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
69885+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
69886+ return -EACCES;
69887+ }
69888+#endif
69889+ return 0;
69890+}
69891+
69892+int
69893+gr_handle_hardlink(const struct dentry *dentry,
69894+ const struct vfsmount *mnt,
69895+ struct inode *inode, const int mode, const struct filename *to)
69896+{
69897+#ifdef CONFIG_GRKERNSEC_LINK
69898+ const struct cred *cred = current_cred();
69899+
69900+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
69901+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
69902+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
69903+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
69904+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
69905+ return -EPERM;
69906+ }
69907+#endif
69908+ return 0;
69909+}
69910diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
69911new file mode 100644
69912index 0000000..dbe0a6b
69913--- /dev/null
69914+++ b/grsecurity/grsec_log.c
69915@@ -0,0 +1,341 @@
69916+#include <linux/kernel.h>
69917+#include <linux/sched.h>
69918+#include <linux/file.h>
69919+#include <linux/tty.h>
69920+#include <linux/fs.h>
69921+#include <linux/mm.h>
69922+#include <linux/grinternal.h>
69923+
69924+#ifdef CONFIG_TREE_PREEMPT_RCU
69925+#define DISABLE_PREEMPT() preempt_disable()
69926+#define ENABLE_PREEMPT() preempt_enable()
69927+#else
69928+#define DISABLE_PREEMPT()
69929+#define ENABLE_PREEMPT()
69930+#endif
69931+
69932+#define BEGIN_LOCKS(x) \
69933+ DISABLE_PREEMPT(); \
69934+ rcu_read_lock(); \
69935+ read_lock(&tasklist_lock); \
69936+ read_lock(&grsec_exec_file_lock); \
69937+ if (x != GR_DO_AUDIT) \
69938+ spin_lock(&grsec_alert_lock); \
69939+ else \
69940+ spin_lock(&grsec_audit_lock)
69941+
69942+#define END_LOCKS(x) \
69943+ if (x != GR_DO_AUDIT) \
69944+ spin_unlock(&grsec_alert_lock); \
69945+ else \
69946+ spin_unlock(&grsec_audit_lock); \
69947+ read_unlock(&grsec_exec_file_lock); \
69948+ read_unlock(&tasklist_lock); \
69949+ rcu_read_unlock(); \
69950+ ENABLE_PREEMPT(); \
69951+ if (x == GR_DONT_AUDIT) \
69952+ gr_handle_alertkill(current)
69953+
69954+enum {
69955+ FLOODING,
69956+ NO_FLOODING
69957+};
69958+
69959+extern char *gr_alert_log_fmt;
69960+extern char *gr_audit_log_fmt;
69961+extern char *gr_alert_log_buf;
69962+extern char *gr_audit_log_buf;
69963+
69964+static int gr_log_start(int audit)
69965+{
69966+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
69967+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
69968+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
69969+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
69970+ unsigned long curr_secs = get_seconds();
69971+
69972+ if (audit == GR_DO_AUDIT)
69973+ goto set_fmt;
69974+
69975+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
69976+ grsec_alert_wtime = curr_secs;
69977+ grsec_alert_fyet = 0;
69978+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
69979+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
69980+ grsec_alert_fyet++;
69981+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
69982+ grsec_alert_wtime = curr_secs;
69983+ grsec_alert_fyet++;
69984+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
69985+ return FLOODING;
69986+ }
69987+ else return FLOODING;
69988+
69989+set_fmt:
69990+#endif
69991+ memset(buf, 0, PAGE_SIZE);
69992+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
69993+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
69994+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
69995+ } else if (current->signal->curr_ip) {
69996+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
69997+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
69998+ } else if (gr_acl_is_enabled()) {
69999+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
70000+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
70001+ } else {
70002+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
70003+ strcpy(buf, fmt);
70004+ }
70005+
70006+ return NO_FLOODING;
70007+}
70008+
70009+static void gr_log_middle(int audit, const char *msg, va_list ap)
70010+ __attribute__ ((format (printf, 2, 0)));
70011+
70012+static void gr_log_middle(int audit, const char *msg, va_list ap)
70013+{
70014+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
70015+ unsigned int len = strlen(buf);
70016+
70017+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
70018+
70019+ return;
70020+}
70021+
70022+static void gr_log_middle_varargs(int audit, const char *msg, ...)
70023+ __attribute__ ((format (printf, 2, 3)));
70024+
70025+static void gr_log_middle_varargs(int audit, const char *msg, ...)
70026+{
70027+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
70028+ unsigned int len = strlen(buf);
70029+ va_list ap;
70030+
70031+ va_start(ap, msg);
70032+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
70033+ va_end(ap);
70034+
70035+ return;
70036+}
70037+
70038+static void gr_log_end(int audit, int append_default)
70039+{
70040+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
70041+ if (append_default) {
70042+ struct task_struct *task = current;
70043+ struct task_struct *parent = task->real_parent;
70044+ const struct cred *cred = __task_cred(task);
70045+ const struct cred *pcred = __task_cred(parent);
70046+ unsigned int len = strlen(buf);
70047+
70048+ 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));
70049+ }
70050+
70051+ printk("%s\n", buf);
70052+
70053+ return;
70054+}
70055+
70056+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
70057+{
70058+ int logtype;
70059+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
70060+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
70061+ void *voidptr = NULL;
70062+ int num1 = 0, num2 = 0;
70063+ unsigned long ulong1 = 0, ulong2 = 0;
70064+ struct dentry *dentry = NULL;
70065+ struct vfsmount *mnt = NULL;
70066+ struct file *file = NULL;
70067+ struct task_struct *task = NULL;
70068+ struct vm_area_struct *vma = NULL;
70069+ const struct cred *cred, *pcred;
70070+ va_list ap;
70071+
70072+ BEGIN_LOCKS(audit);
70073+ logtype = gr_log_start(audit);
70074+ if (logtype == FLOODING) {
70075+ END_LOCKS(audit);
70076+ return;
70077+ }
70078+ va_start(ap, argtypes);
70079+ switch (argtypes) {
70080+ case GR_TTYSNIFF:
70081+ task = va_arg(ap, struct task_struct *);
70082+ 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));
70083+ break;
70084+ case GR_SYSCTL_HIDDEN:
70085+ str1 = va_arg(ap, char *);
70086+ gr_log_middle_varargs(audit, msg, result, str1);
70087+ break;
70088+ case GR_RBAC:
70089+ dentry = va_arg(ap, struct dentry *);
70090+ mnt = va_arg(ap, struct vfsmount *);
70091+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
70092+ break;
70093+ case GR_RBAC_STR:
70094+ dentry = va_arg(ap, struct dentry *);
70095+ mnt = va_arg(ap, struct vfsmount *);
70096+ str1 = va_arg(ap, char *);
70097+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
70098+ break;
70099+ case GR_STR_RBAC:
70100+ str1 = va_arg(ap, char *);
70101+ dentry = va_arg(ap, struct dentry *);
70102+ mnt = va_arg(ap, struct vfsmount *);
70103+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
70104+ break;
70105+ case GR_RBAC_MODE2:
70106+ dentry = va_arg(ap, struct dentry *);
70107+ mnt = va_arg(ap, struct vfsmount *);
70108+ str1 = va_arg(ap, char *);
70109+ str2 = va_arg(ap, char *);
70110+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
70111+ break;
70112+ case GR_RBAC_MODE3:
70113+ dentry = va_arg(ap, struct dentry *);
70114+ mnt = va_arg(ap, struct vfsmount *);
70115+ str1 = va_arg(ap, char *);
70116+ str2 = va_arg(ap, char *);
70117+ str3 = va_arg(ap, char *);
70118+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
70119+ break;
70120+ case GR_FILENAME:
70121+ dentry = va_arg(ap, struct dentry *);
70122+ mnt = va_arg(ap, struct vfsmount *);
70123+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
70124+ break;
70125+ case GR_STR_FILENAME:
70126+ str1 = va_arg(ap, char *);
70127+ dentry = va_arg(ap, struct dentry *);
70128+ mnt = va_arg(ap, struct vfsmount *);
70129+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
70130+ break;
70131+ case GR_FILENAME_STR:
70132+ dentry = va_arg(ap, struct dentry *);
70133+ mnt = va_arg(ap, struct vfsmount *);
70134+ str1 = va_arg(ap, char *);
70135+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
70136+ break;
70137+ case GR_FILENAME_TWO_INT:
70138+ dentry = va_arg(ap, struct dentry *);
70139+ mnt = va_arg(ap, struct vfsmount *);
70140+ num1 = va_arg(ap, int);
70141+ num2 = va_arg(ap, int);
70142+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
70143+ break;
70144+ case GR_FILENAME_TWO_INT_STR:
70145+ dentry = va_arg(ap, struct dentry *);
70146+ mnt = va_arg(ap, struct vfsmount *);
70147+ num1 = va_arg(ap, int);
70148+ num2 = va_arg(ap, int);
70149+ str1 = va_arg(ap, char *);
70150+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
70151+ break;
70152+ case GR_TEXTREL:
70153+ file = va_arg(ap, struct file *);
70154+ ulong1 = va_arg(ap, unsigned long);
70155+ ulong2 = va_arg(ap, unsigned long);
70156+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
70157+ break;
70158+ case GR_PTRACE:
70159+ task = va_arg(ap, struct task_struct *);
70160+ 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));
70161+ break;
70162+ case GR_RESOURCE:
70163+ task = va_arg(ap, struct task_struct *);
70164+ cred = __task_cred(task);
70165+ pcred = __task_cred(task->real_parent);
70166+ ulong1 = va_arg(ap, unsigned long);
70167+ str1 = va_arg(ap, char *);
70168+ ulong2 = va_arg(ap, unsigned long);
70169+ 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));
70170+ break;
70171+ case GR_CAP:
70172+ task = va_arg(ap, struct task_struct *);
70173+ cred = __task_cred(task);
70174+ pcred = __task_cred(task->real_parent);
70175+ str1 = va_arg(ap, char *);
70176+ 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));
70177+ break;
70178+ case GR_SIG:
70179+ str1 = va_arg(ap, char *);
70180+ voidptr = va_arg(ap, void *);
70181+ gr_log_middle_varargs(audit, msg, str1, voidptr);
70182+ break;
70183+ case GR_SIG2:
70184+ task = va_arg(ap, struct task_struct *);
70185+ cred = __task_cred(task);
70186+ pcred = __task_cred(task->real_parent);
70187+ num1 = va_arg(ap, int);
70188+ 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));
70189+ break;
70190+ case GR_CRASH1:
70191+ task = va_arg(ap, struct task_struct *);
70192+ cred = __task_cred(task);
70193+ pcred = __task_cred(task->real_parent);
70194+ ulong1 = va_arg(ap, unsigned long);
70195+ 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);
70196+ break;
70197+ case GR_CRASH2:
70198+ task = va_arg(ap, struct task_struct *);
70199+ cred = __task_cred(task);
70200+ pcred = __task_cred(task->real_parent);
70201+ ulong1 = va_arg(ap, unsigned long);
70202+ 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);
70203+ break;
70204+ case GR_RWXMAP:
70205+ file = va_arg(ap, struct file *);
70206+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
70207+ break;
70208+ case GR_RWXMAPVMA:
70209+ vma = va_arg(ap, struct vm_area_struct *);
70210+ if (vma->vm_file)
70211+ str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
70212+ else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
70213+ str1 = "<stack>";
70214+ else if (vma->vm_start <= current->mm->brk &&
70215+ vma->vm_end >= current->mm->start_brk)
70216+ str1 = "<heap>";
70217+ else
70218+ str1 = "<anonymous mapping>";
70219+ gr_log_middle_varargs(audit, msg, str1);
70220+ break;
70221+ case GR_PSACCT:
70222+ {
70223+ unsigned int wday, cday;
70224+ __u8 whr, chr;
70225+ __u8 wmin, cmin;
70226+ __u8 wsec, csec;
70227+ char cur_tty[64] = { 0 };
70228+ char parent_tty[64] = { 0 };
70229+
70230+ task = va_arg(ap, struct task_struct *);
70231+ wday = va_arg(ap, unsigned int);
70232+ cday = va_arg(ap, unsigned int);
70233+ whr = va_arg(ap, int);
70234+ chr = va_arg(ap, int);
70235+ wmin = va_arg(ap, int);
70236+ cmin = va_arg(ap, int);
70237+ wsec = va_arg(ap, int);
70238+ csec = va_arg(ap, int);
70239+ ulong1 = va_arg(ap, unsigned long);
70240+ cred = __task_cred(task);
70241+ pcred = __task_cred(task->real_parent);
70242+
70243+ 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));
70244+ }
70245+ break;
70246+ default:
70247+ gr_log_middle(audit, msg, ap);
70248+ }
70249+ va_end(ap);
70250+ // these don't need DEFAULTSECARGS printed on the end
70251+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
70252+ gr_log_end(audit, 0);
70253+ else
70254+ gr_log_end(audit, 1);
70255+ END_LOCKS(audit);
70256+}
70257diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
70258new file mode 100644
70259index 0000000..f536303
70260--- /dev/null
70261+++ b/grsecurity/grsec_mem.c
70262@@ -0,0 +1,40 @@
70263+#include <linux/kernel.h>
70264+#include <linux/sched.h>
70265+#include <linux/mm.h>
70266+#include <linux/mman.h>
70267+#include <linux/grinternal.h>
70268+
70269+void
70270+gr_handle_ioperm(void)
70271+{
70272+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
70273+ return;
70274+}
70275+
70276+void
70277+gr_handle_iopl(void)
70278+{
70279+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
70280+ return;
70281+}
70282+
70283+void
70284+gr_handle_mem_readwrite(u64 from, u64 to)
70285+{
70286+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
70287+ return;
70288+}
70289+
70290+void
70291+gr_handle_vm86(void)
70292+{
70293+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
70294+ return;
70295+}
70296+
70297+void
70298+gr_log_badprocpid(const char *entry)
70299+{
70300+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
70301+ return;
70302+}
70303diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
70304new file mode 100644
70305index 0000000..2131422
70306--- /dev/null
70307+++ b/grsecurity/grsec_mount.c
70308@@ -0,0 +1,62 @@
70309+#include <linux/kernel.h>
70310+#include <linux/sched.h>
70311+#include <linux/mount.h>
70312+#include <linux/grsecurity.h>
70313+#include <linux/grinternal.h>
70314+
70315+void
70316+gr_log_remount(const char *devname, const int retval)
70317+{
70318+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
70319+ if (grsec_enable_mount && (retval >= 0))
70320+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
70321+#endif
70322+ return;
70323+}
70324+
70325+void
70326+gr_log_unmount(const char *devname, const int retval)
70327+{
70328+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
70329+ if (grsec_enable_mount && (retval >= 0))
70330+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
70331+#endif
70332+ return;
70333+}
70334+
70335+void
70336+gr_log_mount(const char *from, const char *to, const int retval)
70337+{
70338+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
70339+ if (grsec_enable_mount && (retval >= 0))
70340+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
70341+#endif
70342+ return;
70343+}
70344+
70345+int
70346+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
70347+{
70348+#ifdef CONFIG_GRKERNSEC_ROFS
70349+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
70350+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
70351+ return -EPERM;
70352+ } else
70353+ return 0;
70354+#endif
70355+ return 0;
70356+}
70357+
70358+int
70359+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
70360+{
70361+#ifdef CONFIG_GRKERNSEC_ROFS
70362+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
70363+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
70364+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
70365+ return -EPERM;
70366+ } else
70367+ return 0;
70368+#endif
70369+ return 0;
70370+}
70371diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
70372new file mode 100644
70373index 0000000..6ee9d50
70374--- /dev/null
70375+++ b/grsecurity/grsec_pax.c
70376@@ -0,0 +1,45 @@
70377+#include <linux/kernel.h>
70378+#include <linux/sched.h>
70379+#include <linux/mm.h>
70380+#include <linux/file.h>
70381+#include <linux/grinternal.h>
70382+#include <linux/grsecurity.h>
70383+
70384+void
70385+gr_log_textrel(struct vm_area_struct * vma)
70386+{
70387+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70388+ if (grsec_enable_log_rwxmaps)
70389+ gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
70390+#endif
70391+ return;
70392+}
70393+
70394+void gr_log_ptgnustack(struct file *file)
70395+{
70396+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70397+ if (grsec_enable_log_rwxmaps)
70398+ gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
70399+#endif
70400+ return;
70401+}
70402+
70403+void
70404+gr_log_rwxmmap(struct file *file)
70405+{
70406+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70407+ if (grsec_enable_log_rwxmaps)
70408+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
70409+#endif
70410+ return;
70411+}
70412+
70413+void
70414+gr_log_rwxmprotect(struct vm_area_struct *vma)
70415+{
70416+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
70417+ if (grsec_enable_log_rwxmaps)
70418+ gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
70419+#endif
70420+ return;
70421+}
70422diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
70423new file mode 100644
70424index 0000000..f7f29aa
70425--- /dev/null
70426+++ b/grsecurity/grsec_ptrace.c
70427@@ -0,0 +1,30 @@
70428+#include <linux/kernel.h>
70429+#include <linux/sched.h>
70430+#include <linux/grinternal.h>
70431+#include <linux/security.h>
70432+
70433+void
70434+gr_audit_ptrace(struct task_struct *task)
70435+{
70436+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
70437+ if (grsec_enable_audit_ptrace)
70438+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
70439+#endif
70440+ return;
70441+}
70442+
70443+int
70444+gr_ptrace_readexec(struct file *file, int unsafe_flags)
70445+{
70446+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
70447+ const struct dentry *dentry = file->f_path.dentry;
70448+ const struct vfsmount *mnt = file->f_path.mnt;
70449+
70450+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
70451+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
70452+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
70453+ return -EACCES;
70454+ }
70455+#endif
70456+ return 0;
70457+}
70458diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
70459new file mode 100644
70460index 0000000..4e29cc7
70461--- /dev/null
70462+++ b/grsecurity/grsec_sig.c
70463@@ -0,0 +1,246 @@
70464+#include <linux/kernel.h>
70465+#include <linux/sched.h>
70466+#include <linux/fs.h>
70467+#include <linux/delay.h>
70468+#include <linux/grsecurity.h>
70469+#include <linux/grinternal.h>
70470+#include <linux/hardirq.h>
70471+
70472+char *signames[] = {
70473+ [SIGSEGV] = "Segmentation fault",
70474+ [SIGILL] = "Illegal instruction",
70475+ [SIGABRT] = "Abort",
70476+ [SIGBUS] = "Invalid alignment/Bus error"
70477+};
70478+
70479+void
70480+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
70481+{
70482+#ifdef CONFIG_GRKERNSEC_SIGNAL
70483+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
70484+ (sig == SIGABRT) || (sig == SIGBUS))) {
70485+ if (task_pid_nr(t) == task_pid_nr(current)) {
70486+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
70487+ } else {
70488+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
70489+ }
70490+ }
70491+#endif
70492+ return;
70493+}
70494+
70495+int
70496+gr_handle_signal(const struct task_struct *p, const int sig)
70497+{
70498+#ifdef CONFIG_GRKERNSEC
70499+ /* ignore the 0 signal for protected task checks */
70500+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
70501+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
70502+ return -EPERM;
70503+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
70504+ return -EPERM;
70505+ }
70506+#endif
70507+ return 0;
70508+}
70509+
70510+#ifdef CONFIG_GRKERNSEC
70511+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
70512+
70513+int gr_fake_force_sig(int sig, struct task_struct *t)
70514+{
70515+ unsigned long int flags;
70516+ int ret, blocked, ignored;
70517+ struct k_sigaction *action;
70518+
70519+ spin_lock_irqsave(&t->sighand->siglock, flags);
70520+ action = &t->sighand->action[sig-1];
70521+ ignored = action->sa.sa_handler == SIG_IGN;
70522+ blocked = sigismember(&t->blocked, sig);
70523+ if (blocked || ignored) {
70524+ action->sa.sa_handler = SIG_DFL;
70525+ if (blocked) {
70526+ sigdelset(&t->blocked, sig);
70527+ recalc_sigpending_and_wake(t);
70528+ }
70529+ }
70530+ if (action->sa.sa_handler == SIG_DFL)
70531+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
70532+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
70533+
70534+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
70535+
70536+ return ret;
70537+}
70538+#endif
70539+
70540+#ifdef CONFIG_GRKERNSEC_BRUTE
70541+#define GR_USER_BAN_TIME (15 * 60)
70542+#define GR_DAEMON_BRUTE_TIME (30 * 60)
70543+
70544+static int __get_dumpable(unsigned long mm_flags)
70545+{
70546+ int ret;
70547+
70548+ ret = mm_flags & MMF_DUMPABLE_MASK;
70549+ return (ret >= 2) ? 2 : ret;
70550+}
70551+#endif
70552+
70553+void gr_handle_brute_attach(unsigned long mm_flags)
70554+{
70555+#ifdef CONFIG_GRKERNSEC_BRUTE
70556+ struct task_struct *p = current;
70557+ kuid_t uid = GLOBAL_ROOT_UID;
70558+ int daemon = 0;
70559+
70560+ if (!grsec_enable_brute)
70561+ return;
70562+
70563+ rcu_read_lock();
70564+ read_lock(&tasklist_lock);
70565+ read_lock(&grsec_exec_file_lock);
70566+ if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
70567+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
70568+ p->real_parent->brute = 1;
70569+ daemon = 1;
70570+ } else {
70571+ const struct cred *cred = __task_cred(p), *cred2;
70572+ struct task_struct *tsk, *tsk2;
70573+
70574+ if (!__get_dumpable(mm_flags) && gr_is_global_nonroot(cred->uid)) {
70575+ struct user_struct *user;
70576+
70577+ uid = cred->uid;
70578+
70579+ /* this is put upon execution past expiration */
70580+ user = find_user(uid);
70581+ if (user == NULL)
70582+ goto unlock;
70583+ user->suid_banned = 1;
70584+ user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
70585+ if (user->suid_ban_expires == ~0UL)
70586+ user->suid_ban_expires--;
70587+
70588+ /* only kill other threads of the same binary, from the same user */
70589+ do_each_thread(tsk2, tsk) {
70590+ cred2 = __task_cred(tsk);
70591+ if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
70592+ gr_fake_force_sig(SIGKILL, tsk);
70593+ } while_each_thread(tsk2, tsk);
70594+ }
70595+ }
70596+unlock:
70597+ read_unlock(&grsec_exec_file_lock);
70598+ read_unlock(&tasklist_lock);
70599+ rcu_read_unlock();
70600+
70601+ if (gr_is_global_nonroot(uid))
70602+ 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);
70603+ else if (daemon)
70604+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
70605+
70606+#endif
70607+ return;
70608+}
70609+
70610+void gr_handle_brute_check(void)
70611+{
70612+#ifdef CONFIG_GRKERNSEC_BRUTE
70613+ struct task_struct *p = current;
70614+
70615+ if (unlikely(p->brute)) {
70616+ if (!grsec_enable_brute)
70617+ p->brute = 0;
70618+ else if (time_before(get_seconds(), p->brute_expires))
70619+ msleep(30 * 1000);
70620+ }
70621+#endif
70622+ return;
70623+}
70624+
70625+void gr_handle_kernel_exploit(void)
70626+{
70627+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
70628+ const struct cred *cred;
70629+ struct task_struct *tsk, *tsk2;
70630+ struct user_struct *user;
70631+ kuid_t uid;
70632+
70633+ if (in_irq() || in_serving_softirq() || in_nmi())
70634+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
70635+
70636+ uid = current_uid();
70637+
70638+ if (gr_is_global_root(uid))
70639+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
70640+ else {
70641+ /* kill all the processes of this user, hold a reference
70642+ to their creds struct, and prevent them from creating
70643+ another process until system reset
70644+ */
70645+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
70646+ GR_GLOBAL_UID(uid));
70647+ /* we intentionally leak this ref */
70648+ user = get_uid(current->cred->user);
70649+ if (user)
70650+ user->kernel_banned = 1;
70651+
70652+ /* kill all processes of this user */
70653+ read_lock(&tasklist_lock);
70654+ do_each_thread(tsk2, tsk) {
70655+ cred = __task_cred(tsk);
70656+ if (uid_eq(cred->uid, uid))
70657+ gr_fake_force_sig(SIGKILL, tsk);
70658+ } while_each_thread(tsk2, tsk);
70659+ read_unlock(&tasklist_lock);
70660+ }
70661+#endif
70662+}
70663+
70664+#ifdef CONFIG_GRKERNSEC_BRUTE
70665+static bool suid_ban_expired(struct user_struct *user)
70666+{
70667+ if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
70668+ user->suid_banned = 0;
70669+ user->suid_ban_expires = 0;
70670+ free_uid(user);
70671+ return true;
70672+ }
70673+
70674+ return false;
70675+}
70676+#endif
70677+
70678+int gr_process_kernel_exec_ban(void)
70679+{
70680+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
70681+ if (unlikely(current->cred->user->kernel_banned))
70682+ return -EPERM;
70683+#endif
70684+ return 0;
70685+}
70686+
70687+int gr_process_kernel_setuid_ban(struct user_struct *user)
70688+{
70689+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
70690+ if (unlikely(user->kernel_banned))
70691+ gr_fake_force_sig(SIGKILL, current);
70692+#endif
70693+ return 0;
70694+}
70695+
70696+int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
70697+{
70698+#ifdef CONFIG_GRKERNSEC_BRUTE
70699+ struct user_struct *user = current->cred->user;
70700+ if (unlikely(user->suid_banned)) {
70701+ if (suid_ban_expired(user))
70702+ return 0;
70703+ /* disallow execution of suid binaries only */
70704+ else if (!uid_eq(bprm->cred->euid, current->cred->uid))
70705+ return -EPERM;
70706+ }
70707+#endif
70708+ return 0;
70709+}
70710diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
70711new file mode 100644
70712index 0000000..4030d57
70713--- /dev/null
70714+++ b/grsecurity/grsec_sock.c
70715@@ -0,0 +1,244 @@
70716+#include <linux/kernel.h>
70717+#include <linux/module.h>
70718+#include <linux/sched.h>
70719+#include <linux/file.h>
70720+#include <linux/net.h>
70721+#include <linux/in.h>
70722+#include <linux/ip.h>
70723+#include <net/sock.h>
70724+#include <net/inet_sock.h>
70725+#include <linux/grsecurity.h>
70726+#include <linux/grinternal.h>
70727+#include <linux/gracl.h>
70728+
70729+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
70730+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
70731+
70732+EXPORT_SYMBOL(gr_search_udp_recvmsg);
70733+EXPORT_SYMBOL(gr_search_udp_sendmsg);
70734+
70735+#ifdef CONFIG_UNIX_MODULE
70736+EXPORT_SYMBOL(gr_acl_handle_unix);
70737+EXPORT_SYMBOL(gr_acl_handle_mknod);
70738+EXPORT_SYMBOL(gr_handle_chroot_unix);
70739+EXPORT_SYMBOL(gr_handle_create);
70740+#endif
70741+
70742+#ifdef CONFIG_GRKERNSEC
70743+#define gr_conn_table_size 32749
70744+struct conn_table_entry {
70745+ struct conn_table_entry *next;
70746+ struct signal_struct *sig;
70747+};
70748+
70749+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
70750+DEFINE_SPINLOCK(gr_conn_table_lock);
70751+
70752+extern const char * gr_socktype_to_name(unsigned char type);
70753+extern const char * gr_proto_to_name(unsigned char proto);
70754+extern const char * gr_sockfamily_to_name(unsigned char family);
70755+
70756+static __inline__ int
70757+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
70758+{
70759+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
70760+}
70761+
70762+static __inline__ int
70763+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
70764+ __u16 sport, __u16 dport)
70765+{
70766+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
70767+ sig->gr_sport == sport && sig->gr_dport == dport))
70768+ return 1;
70769+ else
70770+ return 0;
70771+}
70772+
70773+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
70774+{
70775+ struct conn_table_entry **match;
70776+ unsigned int index;
70777+
70778+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
70779+ sig->gr_sport, sig->gr_dport,
70780+ gr_conn_table_size);
70781+
70782+ newent->sig = sig;
70783+
70784+ match = &gr_conn_table[index];
70785+ newent->next = *match;
70786+ *match = newent;
70787+
70788+ return;
70789+}
70790+
70791+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
70792+{
70793+ struct conn_table_entry *match, *last = NULL;
70794+ unsigned int index;
70795+
70796+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
70797+ sig->gr_sport, sig->gr_dport,
70798+ gr_conn_table_size);
70799+
70800+ match = gr_conn_table[index];
70801+ while (match && !conn_match(match->sig,
70802+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
70803+ sig->gr_dport)) {
70804+ last = match;
70805+ match = match->next;
70806+ }
70807+
70808+ if (match) {
70809+ if (last)
70810+ last->next = match->next;
70811+ else
70812+ gr_conn_table[index] = NULL;
70813+ kfree(match);
70814+ }
70815+
70816+ return;
70817+}
70818+
70819+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
70820+ __u16 sport, __u16 dport)
70821+{
70822+ struct conn_table_entry *match;
70823+ unsigned int index;
70824+
70825+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
70826+
70827+ match = gr_conn_table[index];
70828+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
70829+ match = match->next;
70830+
70831+ if (match)
70832+ return match->sig;
70833+ else
70834+ return NULL;
70835+}
70836+
70837+#endif
70838+
70839+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
70840+{
70841+#ifdef CONFIG_GRKERNSEC
70842+ struct signal_struct *sig = task->signal;
70843+ struct conn_table_entry *newent;
70844+
70845+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
70846+ if (newent == NULL)
70847+ return;
70848+ /* no bh lock needed since we are called with bh disabled */
70849+ spin_lock(&gr_conn_table_lock);
70850+ gr_del_task_from_ip_table_nolock(sig);
70851+ sig->gr_saddr = inet->inet_rcv_saddr;
70852+ sig->gr_daddr = inet->inet_daddr;
70853+ sig->gr_sport = inet->inet_sport;
70854+ sig->gr_dport = inet->inet_dport;
70855+ gr_add_to_task_ip_table_nolock(sig, newent);
70856+ spin_unlock(&gr_conn_table_lock);
70857+#endif
70858+ return;
70859+}
70860+
70861+void gr_del_task_from_ip_table(struct task_struct *task)
70862+{
70863+#ifdef CONFIG_GRKERNSEC
70864+ spin_lock_bh(&gr_conn_table_lock);
70865+ gr_del_task_from_ip_table_nolock(task->signal);
70866+ spin_unlock_bh(&gr_conn_table_lock);
70867+#endif
70868+ return;
70869+}
70870+
70871+void
70872+gr_attach_curr_ip(const struct sock *sk)
70873+{
70874+#ifdef CONFIG_GRKERNSEC
70875+ struct signal_struct *p, *set;
70876+ const struct inet_sock *inet = inet_sk(sk);
70877+
70878+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
70879+ return;
70880+
70881+ set = current->signal;
70882+
70883+ spin_lock_bh(&gr_conn_table_lock);
70884+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
70885+ inet->inet_dport, inet->inet_sport);
70886+ if (unlikely(p != NULL)) {
70887+ set->curr_ip = p->curr_ip;
70888+ set->used_accept = 1;
70889+ gr_del_task_from_ip_table_nolock(p);
70890+ spin_unlock_bh(&gr_conn_table_lock);
70891+ return;
70892+ }
70893+ spin_unlock_bh(&gr_conn_table_lock);
70894+
70895+ set->curr_ip = inet->inet_daddr;
70896+ set->used_accept = 1;
70897+#endif
70898+ return;
70899+}
70900+
70901+int
70902+gr_handle_sock_all(const int family, const int type, const int protocol)
70903+{
70904+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
70905+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
70906+ (family != AF_UNIX)) {
70907+ if (family == AF_INET)
70908+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
70909+ else
70910+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
70911+ return -EACCES;
70912+ }
70913+#endif
70914+ return 0;
70915+}
70916+
70917+int
70918+gr_handle_sock_server(const struct sockaddr *sck)
70919+{
70920+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
70921+ if (grsec_enable_socket_server &&
70922+ in_group_p(grsec_socket_server_gid) &&
70923+ sck && (sck->sa_family != AF_UNIX) &&
70924+ (sck->sa_family != AF_LOCAL)) {
70925+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
70926+ return -EACCES;
70927+ }
70928+#endif
70929+ return 0;
70930+}
70931+
70932+int
70933+gr_handle_sock_server_other(const struct sock *sck)
70934+{
70935+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
70936+ if (grsec_enable_socket_server &&
70937+ in_group_p(grsec_socket_server_gid) &&
70938+ sck && (sck->sk_family != AF_UNIX) &&
70939+ (sck->sk_family != AF_LOCAL)) {
70940+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
70941+ return -EACCES;
70942+ }
70943+#endif
70944+ return 0;
70945+}
70946+
70947+int
70948+gr_handle_sock_client(const struct sockaddr *sck)
70949+{
70950+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
70951+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
70952+ sck && (sck->sa_family != AF_UNIX) &&
70953+ (sck->sa_family != AF_LOCAL)) {
70954+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
70955+ return -EACCES;
70956+ }
70957+#endif
70958+ return 0;
70959+}
70960diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
70961new file mode 100644
70962index 0000000..a147ae7
70963--- /dev/null
70964+++ b/grsecurity/grsec_sysctl.c
70965@@ -0,0 +1,470 @@
70966+#include <linux/kernel.h>
70967+#include <linux/sched.h>
70968+#include <linux/sysctl.h>
70969+#include <linux/grsecurity.h>
70970+#include <linux/grinternal.h>
70971+
70972+int
70973+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
70974+{
70975+#ifdef CONFIG_GRKERNSEC_SYSCTL
70976+ if (dirname == NULL || name == NULL)
70977+ return 0;
70978+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
70979+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
70980+ return -EACCES;
70981+ }
70982+#endif
70983+ return 0;
70984+}
70985+
70986+#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
70987+static int __maybe_unused __read_only one = 1;
70988+#endif
70989+
70990+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
70991+ defined(CONFIG_GRKERNSEC_DENYUSB)
70992+struct ctl_table grsecurity_table[] = {
70993+#ifdef CONFIG_GRKERNSEC_SYSCTL
70994+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
70995+#ifdef CONFIG_GRKERNSEC_IO
70996+ {
70997+ .procname = "disable_priv_io",
70998+ .data = &grsec_disable_privio,
70999+ .maxlen = sizeof(int),
71000+ .mode = 0600,
71001+ .proc_handler = &proc_dointvec,
71002+ },
71003+#endif
71004+#endif
71005+#ifdef CONFIG_GRKERNSEC_LINK
71006+ {
71007+ .procname = "linking_restrictions",
71008+ .data = &grsec_enable_link,
71009+ .maxlen = sizeof(int),
71010+ .mode = 0600,
71011+ .proc_handler = &proc_dointvec,
71012+ },
71013+#endif
71014+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
71015+ {
71016+ .procname = "enforce_symlinksifowner",
71017+ .data = &grsec_enable_symlinkown,
71018+ .maxlen = sizeof(int),
71019+ .mode = 0600,
71020+ .proc_handler = &proc_dointvec,
71021+ },
71022+ {
71023+ .procname = "symlinkown_gid",
71024+ .data = &grsec_symlinkown_gid,
71025+ .maxlen = sizeof(int),
71026+ .mode = 0600,
71027+ .proc_handler = &proc_dointvec,
71028+ },
71029+#endif
71030+#ifdef CONFIG_GRKERNSEC_BRUTE
71031+ {
71032+ .procname = "deter_bruteforce",
71033+ .data = &grsec_enable_brute,
71034+ .maxlen = sizeof(int),
71035+ .mode = 0600,
71036+ .proc_handler = &proc_dointvec,
71037+ },
71038+#endif
71039+#ifdef CONFIG_GRKERNSEC_FIFO
71040+ {
71041+ .procname = "fifo_restrictions",
71042+ .data = &grsec_enable_fifo,
71043+ .maxlen = sizeof(int),
71044+ .mode = 0600,
71045+ .proc_handler = &proc_dointvec,
71046+ },
71047+#endif
71048+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
71049+ {
71050+ .procname = "ptrace_readexec",
71051+ .data = &grsec_enable_ptrace_readexec,
71052+ .maxlen = sizeof(int),
71053+ .mode = 0600,
71054+ .proc_handler = &proc_dointvec,
71055+ },
71056+#endif
71057+#ifdef CONFIG_GRKERNSEC_SETXID
71058+ {
71059+ .procname = "consistent_setxid",
71060+ .data = &grsec_enable_setxid,
71061+ .maxlen = sizeof(int),
71062+ .mode = 0600,
71063+ .proc_handler = &proc_dointvec,
71064+ },
71065+#endif
71066+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
71067+ {
71068+ .procname = "ip_blackhole",
71069+ .data = &grsec_enable_blackhole,
71070+ .maxlen = sizeof(int),
71071+ .mode = 0600,
71072+ .proc_handler = &proc_dointvec,
71073+ },
71074+ {
71075+ .procname = "lastack_retries",
71076+ .data = &grsec_lastack_retries,
71077+ .maxlen = sizeof(int),
71078+ .mode = 0600,
71079+ .proc_handler = &proc_dointvec,
71080+ },
71081+#endif
71082+#ifdef CONFIG_GRKERNSEC_EXECLOG
71083+ {
71084+ .procname = "exec_logging",
71085+ .data = &grsec_enable_execlog,
71086+ .maxlen = sizeof(int),
71087+ .mode = 0600,
71088+ .proc_handler = &proc_dointvec,
71089+ },
71090+#endif
71091+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
71092+ {
71093+ .procname = "rwxmap_logging",
71094+ .data = &grsec_enable_log_rwxmaps,
71095+ .maxlen = sizeof(int),
71096+ .mode = 0600,
71097+ .proc_handler = &proc_dointvec,
71098+ },
71099+#endif
71100+#ifdef CONFIG_GRKERNSEC_SIGNAL
71101+ {
71102+ .procname = "signal_logging",
71103+ .data = &grsec_enable_signal,
71104+ .maxlen = sizeof(int),
71105+ .mode = 0600,
71106+ .proc_handler = &proc_dointvec,
71107+ },
71108+#endif
71109+#ifdef CONFIG_GRKERNSEC_FORKFAIL
71110+ {
71111+ .procname = "forkfail_logging",
71112+ .data = &grsec_enable_forkfail,
71113+ .maxlen = sizeof(int),
71114+ .mode = 0600,
71115+ .proc_handler = &proc_dointvec,
71116+ },
71117+#endif
71118+#ifdef CONFIG_GRKERNSEC_TIME
71119+ {
71120+ .procname = "timechange_logging",
71121+ .data = &grsec_enable_time,
71122+ .maxlen = sizeof(int),
71123+ .mode = 0600,
71124+ .proc_handler = &proc_dointvec,
71125+ },
71126+#endif
71127+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
71128+ {
71129+ .procname = "chroot_deny_shmat",
71130+ .data = &grsec_enable_chroot_shmat,
71131+ .maxlen = sizeof(int),
71132+ .mode = 0600,
71133+ .proc_handler = &proc_dointvec,
71134+ },
71135+#endif
71136+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
71137+ {
71138+ .procname = "chroot_deny_unix",
71139+ .data = &grsec_enable_chroot_unix,
71140+ .maxlen = sizeof(int),
71141+ .mode = 0600,
71142+ .proc_handler = &proc_dointvec,
71143+ },
71144+#endif
71145+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
71146+ {
71147+ .procname = "chroot_deny_mount",
71148+ .data = &grsec_enable_chroot_mount,
71149+ .maxlen = sizeof(int),
71150+ .mode = 0600,
71151+ .proc_handler = &proc_dointvec,
71152+ },
71153+#endif
71154+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
71155+ {
71156+ .procname = "chroot_deny_fchdir",
71157+ .data = &grsec_enable_chroot_fchdir,
71158+ .maxlen = sizeof(int),
71159+ .mode = 0600,
71160+ .proc_handler = &proc_dointvec,
71161+ },
71162+#endif
71163+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
71164+ {
71165+ .procname = "chroot_deny_chroot",
71166+ .data = &grsec_enable_chroot_double,
71167+ .maxlen = sizeof(int),
71168+ .mode = 0600,
71169+ .proc_handler = &proc_dointvec,
71170+ },
71171+#endif
71172+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
71173+ {
71174+ .procname = "chroot_deny_pivot",
71175+ .data = &grsec_enable_chroot_pivot,
71176+ .maxlen = sizeof(int),
71177+ .mode = 0600,
71178+ .proc_handler = &proc_dointvec,
71179+ },
71180+#endif
71181+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
71182+ {
71183+ .procname = "chroot_enforce_chdir",
71184+ .data = &grsec_enable_chroot_chdir,
71185+ .maxlen = sizeof(int),
71186+ .mode = 0600,
71187+ .proc_handler = &proc_dointvec,
71188+ },
71189+#endif
71190+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
71191+ {
71192+ .procname = "chroot_deny_chmod",
71193+ .data = &grsec_enable_chroot_chmod,
71194+ .maxlen = sizeof(int),
71195+ .mode = 0600,
71196+ .proc_handler = &proc_dointvec,
71197+ },
71198+#endif
71199+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
71200+ {
71201+ .procname = "chroot_deny_mknod",
71202+ .data = &grsec_enable_chroot_mknod,
71203+ .maxlen = sizeof(int),
71204+ .mode = 0600,
71205+ .proc_handler = &proc_dointvec,
71206+ },
71207+#endif
71208+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
71209+ {
71210+ .procname = "chroot_restrict_nice",
71211+ .data = &grsec_enable_chroot_nice,
71212+ .maxlen = sizeof(int),
71213+ .mode = 0600,
71214+ .proc_handler = &proc_dointvec,
71215+ },
71216+#endif
71217+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
71218+ {
71219+ .procname = "chroot_execlog",
71220+ .data = &grsec_enable_chroot_execlog,
71221+ .maxlen = sizeof(int),
71222+ .mode = 0600,
71223+ .proc_handler = &proc_dointvec,
71224+ },
71225+#endif
71226+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
71227+ {
71228+ .procname = "chroot_caps",
71229+ .data = &grsec_enable_chroot_caps,
71230+ .maxlen = sizeof(int),
71231+ .mode = 0600,
71232+ .proc_handler = &proc_dointvec,
71233+ },
71234+#endif
71235+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
71236+ {
71237+ .procname = "chroot_deny_sysctl",
71238+ .data = &grsec_enable_chroot_sysctl,
71239+ .maxlen = sizeof(int),
71240+ .mode = 0600,
71241+ .proc_handler = &proc_dointvec,
71242+ },
71243+#endif
71244+#ifdef CONFIG_GRKERNSEC_TPE
71245+ {
71246+ .procname = "tpe",
71247+ .data = &grsec_enable_tpe,
71248+ .maxlen = sizeof(int),
71249+ .mode = 0600,
71250+ .proc_handler = &proc_dointvec,
71251+ },
71252+ {
71253+ .procname = "tpe_gid",
71254+ .data = &grsec_tpe_gid,
71255+ .maxlen = sizeof(int),
71256+ .mode = 0600,
71257+ .proc_handler = &proc_dointvec,
71258+ },
71259+#endif
71260+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
71261+ {
71262+ .procname = "tpe_invert",
71263+ .data = &grsec_enable_tpe_invert,
71264+ .maxlen = sizeof(int),
71265+ .mode = 0600,
71266+ .proc_handler = &proc_dointvec,
71267+ },
71268+#endif
71269+#ifdef CONFIG_GRKERNSEC_TPE_ALL
71270+ {
71271+ .procname = "tpe_restrict_all",
71272+ .data = &grsec_enable_tpe_all,
71273+ .maxlen = sizeof(int),
71274+ .mode = 0600,
71275+ .proc_handler = &proc_dointvec,
71276+ },
71277+#endif
71278+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
71279+ {
71280+ .procname = "socket_all",
71281+ .data = &grsec_enable_socket_all,
71282+ .maxlen = sizeof(int),
71283+ .mode = 0600,
71284+ .proc_handler = &proc_dointvec,
71285+ },
71286+ {
71287+ .procname = "socket_all_gid",
71288+ .data = &grsec_socket_all_gid,
71289+ .maxlen = sizeof(int),
71290+ .mode = 0600,
71291+ .proc_handler = &proc_dointvec,
71292+ },
71293+#endif
71294+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
71295+ {
71296+ .procname = "socket_client",
71297+ .data = &grsec_enable_socket_client,
71298+ .maxlen = sizeof(int),
71299+ .mode = 0600,
71300+ .proc_handler = &proc_dointvec,
71301+ },
71302+ {
71303+ .procname = "socket_client_gid",
71304+ .data = &grsec_socket_client_gid,
71305+ .maxlen = sizeof(int),
71306+ .mode = 0600,
71307+ .proc_handler = &proc_dointvec,
71308+ },
71309+#endif
71310+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
71311+ {
71312+ .procname = "socket_server",
71313+ .data = &grsec_enable_socket_server,
71314+ .maxlen = sizeof(int),
71315+ .mode = 0600,
71316+ .proc_handler = &proc_dointvec,
71317+ },
71318+ {
71319+ .procname = "socket_server_gid",
71320+ .data = &grsec_socket_server_gid,
71321+ .maxlen = sizeof(int),
71322+ .mode = 0600,
71323+ .proc_handler = &proc_dointvec,
71324+ },
71325+#endif
71326+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
71327+ {
71328+ .procname = "audit_group",
71329+ .data = &grsec_enable_group,
71330+ .maxlen = sizeof(int),
71331+ .mode = 0600,
71332+ .proc_handler = &proc_dointvec,
71333+ },
71334+ {
71335+ .procname = "audit_gid",
71336+ .data = &grsec_audit_gid,
71337+ .maxlen = sizeof(int),
71338+ .mode = 0600,
71339+ .proc_handler = &proc_dointvec,
71340+ },
71341+#endif
71342+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
71343+ {
71344+ .procname = "audit_chdir",
71345+ .data = &grsec_enable_chdir,
71346+ .maxlen = sizeof(int),
71347+ .mode = 0600,
71348+ .proc_handler = &proc_dointvec,
71349+ },
71350+#endif
71351+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
71352+ {
71353+ .procname = "audit_mount",
71354+ .data = &grsec_enable_mount,
71355+ .maxlen = sizeof(int),
71356+ .mode = 0600,
71357+ .proc_handler = &proc_dointvec,
71358+ },
71359+#endif
71360+#ifdef CONFIG_GRKERNSEC_DMESG
71361+ {
71362+ .procname = "dmesg",
71363+ .data = &grsec_enable_dmesg,
71364+ .maxlen = sizeof(int),
71365+ .mode = 0600,
71366+ .proc_handler = &proc_dointvec,
71367+ },
71368+#endif
71369+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
71370+ {
71371+ .procname = "chroot_findtask",
71372+ .data = &grsec_enable_chroot_findtask,
71373+ .maxlen = sizeof(int),
71374+ .mode = 0600,
71375+ .proc_handler = &proc_dointvec,
71376+ },
71377+#endif
71378+#ifdef CONFIG_GRKERNSEC_RESLOG
71379+ {
71380+ .procname = "resource_logging",
71381+ .data = &grsec_resource_logging,
71382+ .maxlen = sizeof(int),
71383+ .mode = 0600,
71384+ .proc_handler = &proc_dointvec,
71385+ },
71386+#endif
71387+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
71388+ {
71389+ .procname = "audit_ptrace",
71390+ .data = &grsec_enable_audit_ptrace,
71391+ .maxlen = sizeof(int),
71392+ .mode = 0600,
71393+ .proc_handler = &proc_dointvec,
71394+ },
71395+#endif
71396+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
71397+ {
71398+ .procname = "harden_ptrace",
71399+ .data = &grsec_enable_harden_ptrace,
71400+ .maxlen = sizeof(int),
71401+ .mode = 0600,
71402+ .proc_handler = &proc_dointvec,
71403+ },
71404+#endif
71405+ {
71406+ .procname = "grsec_lock",
71407+ .data = &grsec_lock,
71408+ .maxlen = sizeof(int),
71409+ .mode = 0600,
71410+ .proc_handler = &proc_dointvec,
71411+ },
71412+#endif
71413+#ifdef CONFIG_GRKERNSEC_ROFS
71414+ {
71415+ .procname = "romount_protect",
71416+ .data = &grsec_enable_rofs,
71417+ .maxlen = sizeof(int),
71418+ .mode = 0600,
71419+ .proc_handler = &proc_dointvec_minmax,
71420+ .extra1 = &one,
71421+ .extra2 = &one,
71422+ },
71423+#endif
71424+#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
71425+ {
71426+ .procname = "deny_new_usb",
71427+ .data = &grsec_deny_new_usb,
71428+ .maxlen = sizeof(int),
71429+ .mode = 0600,
71430+ .proc_handler = &proc_dointvec,
71431+ },
71432+#endif
71433+ { }
71434+};
71435+#endif
71436diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
71437new file mode 100644
71438index 0000000..0dc13c3
71439--- /dev/null
71440+++ b/grsecurity/grsec_time.c
71441@@ -0,0 +1,16 @@
71442+#include <linux/kernel.h>
71443+#include <linux/sched.h>
71444+#include <linux/grinternal.h>
71445+#include <linux/module.h>
71446+
71447+void
71448+gr_log_timechange(void)
71449+{
71450+#ifdef CONFIG_GRKERNSEC_TIME
71451+ if (grsec_enable_time)
71452+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
71453+#endif
71454+ return;
71455+}
71456+
71457+EXPORT_SYMBOL(gr_log_timechange);
71458diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
71459new file mode 100644
71460index 0000000..ee57dcf
71461--- /dev/null
71462+++ b/grsecurity/grsec_tpe.c
71463@@ -0,0 +1,73 @@
71464+#include <linux/kernel.h>
71465+#include <linux/sched.h>
71466+#include <linux/file.h>
71467+#include <linux/fs.h>
71468+#include <linux/grinternal.h>
71469+
71470+extern int gr_acl_tpe_check(void);
71471+
71472+int
71473+gr_tpe_allow(const struct file *file)
71474+{
71475+#ifdef CONFIG_GRKERNSEC
71476+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
71477+ const struct cred *cred = current_cred();
71478+ char *msg = NULL;
71479+ char *msg2 = NULL;
71480+
71481+ // never restrict root
71482+ if (gr_is_global_root(cred->uid))
71483+ return 1;
71484+
71485+ if (grsec_enable_tpe) {
71486+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
71487+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
71488+ msg = "not being in trusted group";
71489+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
71490+ msg = "being in untrusted group";
71491+#else
71492+ if (in_group_p(grsec_tpe_gid))
71493+ msg = "being in untrusted group";
71494+#endif
71495+ }
71496+ if (!msg && gr_acl_tpe_check())
71497+ msg = "being in untrusted role";
71498+
71499+ // not in any affected group/role
71500+ if (!msg)
71501+ goto next_check;
71502+
71503+ if (gr_is_global_nonroot(inode->i_uid))
71504+ msg2 = "file in non-root-owned directory";
71505+ else if (inode->i_mode & S_IWOTH)
71506+ msg2 = "file in world-writable directory";
71507+ else if (inode->i_mode & S_IWGRP)
71508+ msg2 = "file in group-writable directory";
71509+
71510+ if (msg && msg2) {
71511+ char fullmsg[70] = {0};
71512+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
71513+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
71514+ return 0;
71515+ }
71516+ msg = NULL;
71517+next_check:
71518+#ifdef CONFIG_GRKERNSEC_TPE_ALL
71519+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
71520+ return 1;
71521+
71522+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
71523+ msg = "directory not owned by user";
71524+ else if (inode->i_mode & S_IWOTH)
71525+ msg = "file in world-writable directory";
71526+ else if (inode->i_mode & S_IWGRP)
71527+ msg = "file in group-writable directory";
71528+
71529+ if (msg) {
71530+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
71531+ return 0;
71532+ }
71533+#endif
71534+#endif
71535+ return 1;
71536+}
71537diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
71538new file mode 100644
71539index 0000000..ae02d8e
71540--- /dev/null
71541+++ b/grsecurity/grsec_usb.c
71542@@ -0,0 +1,15 @@
71543+#include <linux/kernel.h>
71544+#include <linux/grinternal.h>
71545+#include <linux/module.h>
71546+
71547+int gr_handle_new_usb(void)
71548+{
71549+#ifdef CONFIG_GRKERNSEC_DENYUSB
71550+ if (grsec_deny_new_usb) {
71551+ printk(KERN_ALERT "grsec: denied insert of new USB device\n");
71552+ return 1;
71553+ }
71554+#endif
71555+ return 0;
71556+}
71557+EXPORT_SYMBOL_GPL(gr_handle_new_usb);
71558diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
71559new file mode 100644
71560index 0000000..9f7b1ac
71561--- /dev/null
71562+++ b/grsecurity/grsum.c
71563@@ -0,0 +1,61 @@
71564+#include <linux/err.h>
71565+#include <linux/kernel.h>
71566+#include <linux/sched.h>
71567+#include <linux/mm.h>
71568+#include <linux/scatterlist.h>
71569+#include <linux/crypto.h>
71570+#include <linux/gracl.h>
71571+
71572+
71573+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
71574+#error "crypto and sha256 must be built into the kernel"
71575+#endif
71576+
71577+int
71578+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
71579+{
71580+ char *p;
71581+ struct crypto_hash *tfm;
71582+ struct hash_desc desc;
71583+ struct scatterlist sg;
71584+ unsigned char temp_sum[GR_SHA_LEN];
71585+ volatile int retval = 0;
71586+ volatile int dummy = 0;
71587+ unsigned int i;
71588+
71589+ sg_init_table(&sg, 1);
71590+
71591+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
71592+ if (IS_ERR(tfm)) {
71593+ /* should never happen, since sha256 should be built in */
71594+ return 1;
71595+ }
71596+
71597+ desc.tfm = tfm;
71598+ desc.flags = 0;
71599+
71600+ crypto_hash_init(&desc);
71601+
71602+ p = salt;
71603+ sg_set_buf(&sg, p, GR_SALT_LEN);
71604+ crypto_hash_update(&desc, &sg, sg.length);
71605+
71606+ p = entry->pw;
71607+ sg_set_buf(&sg, p, strlen(p));
71608+
71609+ crypto_hash_update(&desc, &sg, sg.length);
71610+
71611+ crypto_hash_final(&desc, temp_sum);
71612+
71613+ memset(entry->pw, 0, GR_PW_LEN);
71614+
71615+ for (i = 0; i < GR_SHA_LEN; i++)
71616+ if (sum[i] != temp_sum[i])
71617+ retval = 1;
71618+ else
71619+ dummy = 1; // waste a cycle
71620+
71621+ crypto_free_hash(tfm);
71622+
71623+ return retval;
71624+}
71625diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
71626index 77ff547..181834f 100644
71627--- a/include/asm-generic/4level-fixup.h
71628+++ b/include/asm-generic/4level-fixup.h
71629@@ -13,8 +13,10 @@
71630 #define pmd_alloc(mm, pud, address) \
71631 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
71632 NULL: pmd_offset(pud, address))
71633+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
71634
71635 #define pud_alloc(mm, pgd, address) (pgd)
71636+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
71637 #define pud_offset(pgd, start) (pgd)
71638 #define pud_none(pud) 0
71639 #define pud_bad(pud) 0
71640diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
71641index b7babf0..04ad282 100644
71642--- a/include/asm-generic/atomic-long.h
71643+++ b/include/asm-generic/atomic-long.h
71644@@ -22,6 +22,12 @@
71645
71646 typedef atomic64_t atomic_long_t;
71647
71648+#ifdef CONFIG_PAX_REFCOUNT
71649+typedef atomic64_unchecked_t atomic_long_unchecked_t;
71650+#else
71651+typedef atomic64_t atomic_long_unchecked_t;
71652+#endif
71653+
71654 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
71655
71656 static inline long atomic_long_read(atomic_long_t *l)
71657@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
71658 return (long)atomic64_read(v);
71659 }
71660
71661+#ifdef CONFIG_PAX_REFCOUNT
71662+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
71663+{
71664+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71665+
71666+ return (long)atomic64_read_unchecked(v);
71667+}
71668+#endif
71669+
71670 static inline void atomic_long_set(atomic_long_t *l, long i)
71671 {
71672 atomic64_t *v = (atomic64_t *)l;
71673@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
71674 atomic64_set(v, i);
71675 }
71676
71677+#ifdef CONFIG_PAX_REFCOUNT
71678+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
71679+{
71680+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71681+
71682+ atomic64_set_unchecked(v, i);
71683+}
71684+#endif
71685+
71686 static inline void atomic_long_inc(atomic_long_t *l)
71687 {
71688 atomic64_t *v = (atomic64_t *)l;
71689@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
71690 atomic64_inc(v);
71691 }
71692
71693+#ifdef CONFIG_PAX_REFCOUNT
71694+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
71695+{
71696+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71697+
71698+ atomic64_inc_unchecked(v);
71699+}
71700+#endif
71701+
71702 static inline void atomic_long_dec(atomic_long_t *l)
71703 {
71704 atomic64_t *v = (atomic64_t *)l;
71705@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
71706 atomic64_dec(v);
71707 }
71708
71709+#ifdef CONFIG_PAX_REFCOUNT
71710+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
71711+{
71712+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71713+
71714+ atomic64_dec_unchecked(v);
71715+}
71716+#endif
71717+
71718 static inline void atomic_long_add(long i, atomic_long_t *l)
71719 {
71720 atomic64_t *v = (atomic64_t *)l;
71721@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
71722 atomic64_add(i, v);
71723 }
71724
71725+#ifdef CONFIG_PAX_REFCOUNT
71726+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
71727+{
71728+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71729+
71730+ atomic64_add_unchecked(i, v);
71731+}
71732+#endif
71733+
71734 static inline void atomic_long_sub(long i, atomic_long_t *l)
71735 {
71736 atomic64_t *v = (atomic64_t *)l;
71737@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
71738 atomic64_sub(i, v);
71739 }
71740
71741+#ifdef CONFIG_PAX_REFCOUNT
71742+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
71743+{
71744+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71745+
71746+ atomic64_sub_unchecked(i, v);
71747+}
71748+#endif
71749+
71750 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
71751 {
71752 atomic64_t *v = (atomic64_t *)l;
71753@@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
71754 return (long)atomic64_add_return(i, v);
71755 }
71756
71757+#ifdef CONFIG_PAX_REFCOUNT
71758+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
71759+{
71760+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71761+
71762+ return (long)atomic64_add_return_unchecked(i, v);
71763+}
71764+#endif
71765+
71766 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
71767 {
71768 atomic64_t *v = (atomic64_t *)l;
71769@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
71770 return (long)atomic64_inc_return(v);
71771 }
71772
71773+#ifdef CONFIG_PAX_REFCOUNT
71774+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
71775+{
71776+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
71777+
71778+ return (long)atomic64_inc_return_unchecked(v);
71779+}
71780+#endif
71781+
71782 static inline long atomic_long_dec_return(atomic_long_t *l)
71783 {
71784 atomic64_t *v = (atomic64_t *)l;
71785@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
71786
71787 typedef atomic_t atomic_long_t;
71788
71789+#ifdef CONFIG_PAX_REFCOUNT
71790+typedef atomic_unchecked_t atomic_long_unchecked_t;
71791+#else
71792+typedef atomic_t atomic_long_unchecked_t;
71793+#endif
71794+
71795 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
71796 static inline long atomic_long_read(atomic_long_t *l)
71797 {
71798@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
71799 return (long)atomic_read(v);
71800 }
71801
71802+#ifdef CONFIG_PAX_REFCOUNT
71803+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
71804+{
71805+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71806+
71807+ return (long)atomic_read_unchecked(v);
71808+}
71809+#endif
71810+
71811 static inline void atomic_long_set(atomic_long_t *l, long i)
71812 {
71813 atomic_t *v = (atomic_t *)l;
71814@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
71815 atomic_set(v, i);
71816 }
71817
71818+#ifdef CONFIG_PAX_REFCOUNT
71819+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
71820+{
71821+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71822+
71823+ atomic_set_unchecked(v, i);
71824+}
71825+#endif
71826+
71827 static inline void atomic_long_inc(atomic_long_t *l)
71828 {
71829 atomic_t *v = (atomic_t *)l;
71830@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
71831 atomic_inc(v);
71832 }
71833
71834+#ifdef CONFIG_PAX_REFCOUNT
71835+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
71836+{
71837+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71838+
71839+ atomic_inc_unchecked(v);
71840+}
71841+#endif
71842+
71843 static inline void atomic_long_dec(atomic_long_t *l)
71844 {
71845 atomic_t *v = (atomic_t *)l;
71846@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
71847 atomic_dec(v);
71848 }
71849
71850+#ifdef CONFIG_PAX_REFCOUNT
71851+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
71852+{
71853+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71854+
71855+ atomic_dec_unchecked(v);
71856+}
71857+#endif
71858+
71859 static inline void atomic_long_add(long i, atomic_long_t *l)
71860 {
71861 atomic_t *v = (atomic_t *)l;
71862@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
71863 atomic_add(i, v);
71864 }
71865
71866+#ifdef CONFIG_PAX_REFCOUNT
71867+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
71868+{
71869+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71870+
71871+ atomic_add_unchecked(i, v);
71872+}
71873+#endif
71874+
71875 static inline void atomic_long_sub(long i, atomic_long_t *l)
71876 {
71877 atomic_t *v = (atomic_t *)l;
71878@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
71879 atomic_sub(i, v);
71880 }
71881
71882+#ifdef CONFIG_PAX_REFCOUNT
71883+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
71884+{
71885+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71886+
71887+ atomic_sub_unchecked(i, v);
71888+}
71889+#endif
71890+
71891 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
71892 {
71893 atomic_t *v = (atomic_t *)l;
71894@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
71895 return (long)atomic_add_return(i, v);
71896 }
71897
71898+#ifdef CONFIG_PAX_REFCOUNT
71899+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
71900+{
71901+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71902+
71903+ return (long)atomic_add_return_unchecked(i, v);
71904+}
71905+
71906+#endif
71907+
71908 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
71909 {
71910 atomic_t *v = (atomic_t *)l;
71911@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
71912 return (long)atomic_inc_return(v);
71913 }
71914
71915+#ifdef CONFIG_PAX_REFCOUNT
71916+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
71917+{
71918+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
71919+
71920+ return (long)atomic_inc_return_unchecked(v);
71921+}
71922+#endif
71923+
71924 static inline long atomic_long_dec_return(atomic_long_t *l)
71925 {
71926 atomic_t *v = (atomic_t *)l;
71927@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
71928
71929 #endif /* BITS_PER_LONG == 64 */
71930
71931+#ifdef CONFIG_PAX_REFCOUNT
71932+static inline void pax_refcount_needs_these_functions(void)
71933+{
71934+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
71935+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
71936+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
71937+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
71938+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
71939+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
71940+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
71941+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
71942+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
71943+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
71944+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
71945+#ifdef CONFIG_X86
71946+ atomic_clear_mask_unchecked(0, NULL);
71947+ atomic_set_mask_unchecked(0, NULL);
71948+#endif
71949+
71950+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
71951+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
71952+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
71953+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
71954+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
71955+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
71956+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
71957+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
71958+}
71959+#else
71960+#define atomic_read_unchecked(v) atomic_read(v)
71961+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
71962+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
71963+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
71964+#define atomic_inc_unchecked(v) atomic_inc(v)
71965+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
71966+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
71967+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
71968+#define atomic_dec_unchecked(v) atomic_dec(v)
71969+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
71970+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
71971+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
71972+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
71973+
71974+#define atomic_long_read_unchecked(v) atomic_long_read(v)
71975+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
71976+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
71977+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
71978+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
71979+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
71980+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
71981+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
71982+#endif
71983+
71984 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
71985diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
71986index 33bd2de..f31bff97 100644
71987--- a/include/asm-generic/atomic.h
71988+++ b/include/asm-generic/atomic.h
71989@@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
71990 * Atomically clears the bits set in @mask from @v
71991 */
71992 #ifndef atomic_clear_mask
71993-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
71994+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
71995 {
71996 unsigned long flags;
71997
71998diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
71999index b18ce4f..2ee2843 100644
72000--- a/include/asm-generic/atomic64.h
72001+++ b/include/asm-generic/atomic64.h
72002@@ -16,6 +16,8 @@ typedef struct {
72003 long long counter;
72004 } atomic64_t;
72005
72006+typedef atomic64_t atomic64_unchecked_t;
72007+
72008 #define ATOMIC64_INIT(i) { (i) }
72009
72010 extern long long atomic64_read(const atomic64_t *v);
72011@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
72012 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
72013 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
72014
72015+#define atomic64_read_unchecked(v) atomic64_read(v)
72016+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
72017+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
72018+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
72019+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
72020+#define atomic64_inc_unchecked(v) atomic64_inc(v)
72021+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
72022+#define atomic64_dec_unchecked(v) atomic64_dec(v)
72023+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
72024+
72025 #endif /* _ASM_GENERIC_ATOMIC64_H */
72026diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
72027index 1bfcfe5..e04c5c9 100644
72028--- a/include/asm-generic/cache.h
72029+++ b/include/asm-generic/cache.h
72030@@ -6,7 +6,7 @@
72031 * cache lines need to provide their own cache.h.
72032 */
72033
72034-#define L1_CACHE_SHIFT 5
72035-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
72036+#define L1_CACHE_SHIFT 5UL
72037+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
72038
72039 #endif /* __ASM_GENERIC_CACHE_H */
72040diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
72041index 0d68a1e..b74a761 100644
72042--- a/include/asm-generic/emergency-restart.h
72043+++ b/include/asm-generic/emergency-restart.h
72044@@ -1,7 +1,7 @@
72045 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
72046 #define _ASM_GENERIC_EMERGENCY_RESTART_H
72047
72048-static inline void machine_emergency_restart(void)
72049+static inline __noreturn void machine_emergency_restart(void)
72050 {
72051 machine_restart(NULL);
72052 }
72053diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
72054index 90f99c7..00ce236 100644
72055--- a/include/asm-generic/kmap_types.h
72056+++ b/include/asm-generic/kmap_types.h
72057@@ -2,9 +2,9 @@
72058 #define _ASM_GENERIC_KMAP_TYPES_H
72059
72060 #ifdef __WITH_KM_FENCE
72061-# define KM_TYPE_NR 41
72062+# define KM_TYPE_NR 42
72063 #else
72064-# define KM_TYPE_NR 20
72065+# define KM_TYPE_NR 21
72066 #endif
72067
72068 #endif
72069diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
72070index 9ceb03b..62b0b8f 100644
72071--- a/include/asm-generic/local.h
72072+++ b/include/asm-generic/local.h
72073@@ -23,24 +23,37 @@ typedef struct
72074 atomic_long_t a;
72075 } local_t;
72076
72077+typedef struct {
72078+ atomic_long_unchecked_t a;
72079+} local_unchecked_t;
72080+
72081 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
72082
72083 #define local_read(l) atomic_long_read(&(l)->a)
72084+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
72085 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
72086+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
72087 #define local_inc(l) atomic_long_inc(&(l)->a)
72088+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
72089 #define local_dec(l) atomic_long_dec(&(l)->a)
72090+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
72091 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
72092+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
72093 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
72094+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
72095
72096 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
72097 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
72098 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
72099 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
72100 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
72101+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
72102 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
72103 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
72104+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
72105
72106 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
72107+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
72108 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
72109 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
72110 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
72111diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
72112index 725612b..9cc513a 100644
72113--- a/include/asm-generic/pgtable-nopmd.h
72114+++ b/include/asm-generic/pgtable-nopmd.h
72115@@ -1,14 +1,19 @@
72116 #ifndef _PGTABLE_NOPMD_H
72117 #define _PGTABLE_NOPMD_H
72118
72119-#ifndef __ASSEMBLY__
72120-
72121 #include <asm-generic/pgtable-nopud.h>
72122
72123-struct mm_struct;
72124-
72125 #define __PAGETABLE_PMD_FOLDED
72126
72127+#define PMD_SHIFT PUD_SHIFT
72128+#define PTRS_PER_PMD 1
72129+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
72130+#define PMD_MASK (~(PMD_SIZE-1))
72131+
72132+#ifndef __ASSEMBLY__
72133+
72134+struct mm_struct;
72135+
72136 /*
72137 * Having the pmd type consist of a pud gets the size right, and allows
72138 * us to conceptually access the pud entry that this pmd is folded into
72139@@ -16,11 +21,6 @@ struct mm_struct;
72140 */
72141 typedef struct { pud_t pud; } pmd_t;
72142
72143-#define PMD_SHIFT PUD_SHIFT
72144-#define PTRS_PER_PMD 1
72145-#define PMD_SIZE (1UL << PMD_SHIFT)
72146-#define PMD_MASK (~(PMD_SIZE-1))
72147-
72148 /*
72149 * The "pud_xxx()" functions here are trivial for a folded two-level
72150 * setup: the pmd is never bad, and a pmd always exists (as it's folded
72151diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
72152index 810431d..0ec4804f 100644
72153--- a/include/asm-generic/pgtable-nopud.h
72154+++ b/include/asm-generic/pgtable-nopud.h
72155@@ -1,10 +1,15 @@
72156 #ifndef _PGTABLE_NOPUD_H
72157 #define _PGTABLE_NOPUD_H
72158
72159-#ifndef __ASSEMBLY__
72160-
72161 #define __PAGETABLE_PUD_FOLDED
72162
72163+#define PUD_SHIFT PGDIR_SHIFT
72164+#define PTRS_PER_PUD 1
72165+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
72166+#define PUD_MASK (~(PUD_SIZE-1))
72167+
72168+#ifndef __ASSEMBLY__
72169+
72170 /*
72171 * Having the pud type consist of a pgd gets the size right, and allows
72172 * us to conceptually access the pgd entry that this pud is folded into
72173@@ -12,11 +17,6 @@
72174 */
72175 typedef struct { pgd_t pgd; } pud_t;
72176
72177-#define PUD_SHIFT PGDIR_SHIFT
72178-#define PTRS_PER_PUD 1
72179-#define PUD_SIZE (1UL << PUD_SHIFT)
72180-#define PUD_MASK (~(PUD_SIZE-1))
72181-
72182 /*
72183 * The "pgd_xxx()" functions here are trivial for a folded two-level
72184 * setup: the pud is never bad, and a pud always exists (as it's folded
72185@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
72186 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
72187
72188 #define pgd_populate(mm, pgd, pud) do { } while (0)
72189+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
72190 /*
72191 * (puds are folded into pgds so this doesn't get actually called,
72192 * but the define is needed for a generic inline function.)
72193diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
72194index 0807ddf..cd67747 100644
72195--- a/include/asm-generic/pgtable.h
72196+++ b/include/asm-generic/pgtable.h
72197@@ -741,6 +741,22 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
72198 }
72199 #endif /* CONFIG_NUMA_BALANCING */
72200
72201+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
72202+#ifdef CONFIG_PAX_KERNEXEC
72203+#error KERNEXEC requires pax_open_kernel
72204+#else
72205+static inline unsigned long pax_open_kernel(void) { return 0; }
72206+#endif
72207+#endif
72208+
72209+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
72210+#ifdef CONFIG_PAX_KERNEXEC
72211+#error KERNEXEC requires pax_close_kernel
72212+#else
72213+static inline unsigned long pax_close_kernel(void) { return 0; }
72214+#endif
72215+#endif
72216+
72217 #endif /* CONFIG_MMU */
72218
72219 #endif /* !__ASSEMBLY__ */
72220diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
72221index dc1269c..48a4f51 100644
72222--- a/include/asm-generic/uaccess.h
72223+++ b/include/asm-generic/uaccess.h
72224@@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
72225 return __clear_user(to, n);
72226 }
72227
72228+#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
72229+#ifdef CONFIG_PAX_MEMORY_UDEREF
72230+#error UDEREF requires pax_open_userland
72231+#else
72232+static inline unsigned long pax_open_userland(void) { return 0; }
72233+#endif
72234+#endif
72235+
72236+#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
72237+#ifdef CONFIG_PAX_MEMORY_UDEREF
72238+#error UDEREF requires pax_close_userland
72239+#else
72240+static inline unsigned long pax_close_userland(void) { return 0; }
72241+#endif
72242+#endif
72243+
72244 #endif /* __ASM_GENERIC_UACCESS_H */
72245diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
72246index 69732d2..cbe16d9 100644
72247--- a/include/asm-generic/vmlinux.lds.h
72248+++ b/include/asm-generic/vmlinux.lds.h
72249@@ -227,6 +227,7 @@
72250 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
72251 VMLINUX_SYMBOL(__start_rodata) = .; \
72252 *(.rodata) *(.rodata.*) \
72253+ *(.data..read_only) \
72254 *(__vermagic) /* Kernel version magic */ \
72255 . = ALIGN(8); \
72256 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
72257@@ -710,17 +711,18 @@
72258 * section in the linker script will go there too. @phdr should have
72259 * a leading colon.
72260 *
72261- * Note that this macros defines __per_cpu_load as an absolute symbol.
72262+ * Note that this macros defines per_cpu_load as an absolute symbol.
72263 * If there is no need to put the percpu section at a predetermined
72264 * address, use PERCPU_SECTION.
72265 */
72266 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
72267- VMLINUX_SYMBOL(__per_cpu_load) = .; \
72268- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
72269+ per_cpu_load = .; \
72270+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
72271 - LOAD_OFFSET) { \
72272+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
72273 PERCPU_INPUT(cacheline) \
72274 } phdr \
72275- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
72276+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
72277
72278 /**
72279 * PERCPU_SECTION - define output section for percpu area, simple version
72280diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
72281index 418d270..bfd2794 100644
72282--- a/include/crypto/algapi.h
72283+++ b/include/crypto/algapi.h
72284@@ -34,7 +34,7 @@ struct crypto_type {
72285 unsigned int maskclear;
72286 unsigned int maskset;
72287 unsigned int tfmsize;
72288-};
72289+} __do_const;
72290
72291 struct crypto_instance {
72292 struct crypto_alg alg;
72293diff --git a/include/drm/drmP.h b/include/drm/drmP.h
72294index 12083dc..39740ec 100644
72295--- a/include/drm/drmP.h
72296+++ b/include/drm/drmP.h
72297@@ -69,6 +69,7 @@
72298 #include <linux/workqueue.h>
72299 #include <linux/poll.h>
72300 #include <asm/pgalloc.h>
72301+#include <asm/local.h>
72302 #include <drm/drm.h>
72303 #include <drm/drm_sarea.h>
72304
72305@@ -293,10 +294,12 @@ do { \
72306 * \param cmd command.
72307 * \param arg argument.
72308 */
72309-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
72310+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
72311+ struct drm_file *file_priv);
72312+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
72313 struct drm_file *file_priv);
72314
72315-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
72316+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
72317 unsigned long arg);
72318
72319 #define DRM_IOCTL_NR(n) _IOC_NR(n)
72320@@ -311,10 +314,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
72321 struct drm_ioctl_desc {
72322 unsigned int cmd;
72323 int flags;
72324- drm_ioctl_t *func;
72325+ drm_ioctl_t func;
72326 unsigned int cmd_drv;
72327 const char *name;
72328-};
72329+} __do_const;
72330
72331 /**
72332 * Creates a driver or general drm_ioctl_desc array entry for the given
72333@@ -1015,7 +1018,7 @@ struct drm_info_list {
72334 int (*show)(struct seq_file*, void*); /** show callback */
72335 u32 driver_features; /**< Required driver features for this entry */
72336 void *data;
72337-};
72338+} __do_const;
72339
72340 /**
72341 * debugfs node structure. This structure represents a debugfs file.
72342@@ -1088,7 +1091,7 @@ struct drm_device {
72343
72344 /** \name Usage Counters */
72345 /*@{ */
72346- int open_count; /**< Outstanding files open */
72347+ local_t open_count; /**< Outstanding files open */
72348 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
72349 atomic_t vma_count; /**< Outstanding vma areas open */
72350 int buf_use; /**< Buffers in use -- cannot alloc */
72351@@ -1099,7 +1102,7 @@ struct drm_device {
72352 /*@{ */
72353 unsigned long counters;
72354 enum drm_stat_type types[15];
72355- atomic_t counts[15];
72356+ atomic_unchecked_t counts[15];
72357 /*@} */
72358
72359 struct list_head filelist;
72360diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
72361index f43d556..94d9343 100644
72362--- a/include/drm/drm_crtc_helper.h
72363+++ b/include/drm/drm_crtc_helper.h
72364@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
72365 struct drm_connector *connector);
72366 /* disable encoder when not in use - more explicit than dpms off */
72367 void (*disable)(struct drm_encoder *encoder);
72368-};
72369+} __no_const;
72370
72371 /**
72372 * drm_connector_helper_funcs - helper operations for connectors
72373diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
72374index 72dcbe8..8db58d7 100644
72375--- a/include/drm/ttm/ttm_memory.h
72376+++ b/include/drm/ttm/ttm_memory.h
72377@@ -48,7 +48,7 @@
72378
72379 struct ttm_mem_shrink {
72380 int (*do_shrink) (struct ttm_mem_shrink *);
72381-};
72382+} __no_const;
72383
72384 /**
72385 * struct ttm_mem_global - Global memory accounting structure.
72386diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
72387index 4b840e8..155d235 100644
72388--- a/include/keys/asymmetric-subtype.h
72389+++ b/include/keys/asymmetric-subtype.h
72390@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
72391 /* Verify the signature on a key of this subtype (optional) */
72392 int (*verify_signature)(const struct key *key,
72393 const struct public_key_signature *sig);
72394-};
72395+} __do_const;
72396
72397 /**
72398 * asymmetric_key_subtype - Get the subtype from an asymmetric key
72399diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
72400index c1da539..1dcec55 100644
72401--- a/include/linux/atmdev.h
72402+++ b/include/linux/atmdev.h
72403@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
72404 #endif
72405
72406 struct k_atm_aal_stats {
72407-#define __HANDLE_ITEM(i) atomic_t i
72408+#define __HANDLE_ITEM(i) atomic_unchecked_t i
72409 __AAL_STAT_ITEMS
72410 #undef __HANDLE_ITEM
72411 };
72412@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
72413 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
72414 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
72415 struct module *owner;
72416-};
72417+} __do_const ;
72418
72419 struct atmphy_ops {
72420 int (*start)(struct atm_dev *dev);
72421diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
72422index 70cf138..0418ee2 100644
72423--- a/include/linux/binfmts.h
72424+++ b/include/linux/binfmts.h
72425@@ -73,8 +73,10 @@ struct linux_binfmt {
72426 int (*load_binary)(struct linux_binprm *);
72427 int (*load_shlib)(struct file *);
72428 int (*core_dump)(struct coredump_params *cprm);
72429+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
72430+ void (*handle_mmap)(struct file *);
72431 unsigned long min_coredump; /* minimal dump size */
72432-};
72433+} __do_const;
72434
72435 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
72436
72437diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
72438index 2fdb4a4..54aad7e 100644
72439--- a/include/linux/blkdev.h
72440+++ b/include/linux/blkdev.h
72441@@ -1526,7 +1526,7 @@ struct block_device_operations {
72442 /* this callback is with swap_lock and sometimes page table lock held */
72443 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
72444 struct module *owner;
72445-};
72446+} __do_const;
72447
72448 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
72449 unsigned long);
72450diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
72451index 7c2e030..b72475d 100644
72452--- a/include/linux/blktrace_api.h
72453+++ b/include/linux/blktrace_api.h
72454@@ -23,7 +23,7 @@ struct blk_trace {
72455 struct dentry *dir;
72456 struct dentry *dropped_file;
72457 struct dentry *msg_file;
72458- atomic_t dropped;
72459+ atomic_unchecked_t dropped;
72460 };
72461
72462 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
72463diff --git a/include/linux/cache.h b/include/linux/cache.h
72464index 4c57065..40346da 100644
72465--- a/include/linux/cache.h
72466+++ b/include/linux/cache.h
72467@@ -16,6 +16,14 @@
72468 #define __read_mostly
72469 #endif
72470
72471+#ifndef __read_only
72472+#ifdef CONFIG_PAX_KERNEXEC
72473+#error KERNEXEC requires __read_only
72474+#else
72475+#define __read_only __read_mostly
72476+#endif
72477+#endif
72478+
72479 #ifndef ____cacheline_aligned
72480 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
72481 #endif
72482diff --git a/include/linux/capability.h b/include/linux/capability.h
72483index d9a4f7f4..19f77d6 100644
72484--- a/include/linux/capability.h
72485+++ b/include/linux/capability.h
72486@@ -213,8 +213,13 @@ extern bool ns_capable(struct user_namespace *ns, int cap);
72487 extern bool nsown_capable(int cap);
72488 extern bool inode_capable(const struct inode *inode, int cap);
72489 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
72490+extern bool capable_nolog(int cap);
72491+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
72492+extern bool inode_capable_nolog(const struct inode *inode, int cap);
72493
72494 /* audit system wants to get cap info from files as well */
72495 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
72496
72497+extern int is_privileged_binary(const struct dentry *dentry);
72498+
72499 #endif /* !_LINUX_CAPABILITY_H */
72500diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
72501index 8609d57..86e4d79 100644
72502--- a/include/linux/cdrom.h
72503+++ b/include/linux/cdrom.h
72504@@ -87,7 +87,6 @@ struct cdrom_device_ops {
72505
72506 /* driver specifications */
72507 const int capability; /* capability flags */
72508- int n_minors; /* number of active minor devices */
72509 /* handle uniform packets for scsi type devices (scsi,atapi) */
72510 int (*generic_packet) (struct cdrom_device_info *,
72511 struct packet_command *);
72512diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
72513index 4ce9056..86caac6 100644
72514--- a/include/linux/cleancache.h
72515+++ b/include/linux/cleancache.h
72516@@ -31,7 +31,7 @@ struct cleancache_ops {
72517 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
72518 void (*invalidate_inode)(int, struct cleancache_filekey);
72519 void (*invalidate_fs)(int);
72520-};
72521+} __no_const;
72522
72523 extern struct cleancache_ops *
72524 cleancache_register_ops(struct cleancache_ops *ops);
72525diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
72526index 1ec14a7..d0654a2 100644
72527--- a/include/linux/clk-provider.h
72528+++ b/include/linux/clk-provider.h
72529@@ -132,6 +132,7 @@ struct clk_ops {
72530 unsigned long);
72531 void (*init)(struct clk_hw *hw);
72532 };
72533+typedef struct clk_ops __no_const clk_ops_no_const;
72534
72535 /**
72536 * struct clk_init_data - holds init data that's common to all clocks and is
72537diff --git a/include/linux/compat.h b/include/linux/compat.h
72538index 7f0c1dd..206ac34 100644
72539--- a/include/linux/compat.h
72540+++ b/include/linux/compat.h
72541@@ -312,7 +312,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
72542 compat_size_t __user *len_ptr);
72543
72544 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
72545-asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
72546+asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
72547 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
72548 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
72549 compat_ssize_t msgsz, int msgflg);
72550@@ -419,7 +419,7 @@ extern int compat_ptrace_request(struct task_struct *child,
72551 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
72552 compat_ulong_t addr, compat_ulong_t data);
72553 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
72554- compat_long_t addr, compat_long_t data);
72555+ compat_ulong_t addr, compat_ulong_t data);
72556
72557 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, size_t);
72558 /*
72559@@ -669,6 +669,7 @@ asmlinkage long compat_sys_sigaltstack(const compat_stack_t __user *uss_ptr,
72560
72561 int compat_restore_altstack(const compat_stack_t __user *uss);
72562 int __compat_save_altstack(compat_stack_t __user *, unsigned long);
72563+void __compat_save_altstack_ex(compat_stack_t __user *, unsigned long);
72564
72565 asmlinkage long compat_sys_sched_rr_get_interval(compat_pid_t pid,
72566 struct compat_timespec __user *interval);
72567diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
72568index 842de22..7f3a41f 100644
72569--- a/include/linux/compiler-gcc4.h
72570+++ b/include/linux/compiler-gcc4.h
72571@@ -39,9 +39,29 @@
72572 # define __compiletime_warning(message) __attribute__((warning(message)))
72573 # define __compiletime_error(message) __attribute__((error(message)))
72574 #endif /* __CHECKER__ */
72575+
72576+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
72577+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
72578+#define __bos0(ptr) __bos((ptr), 0)
72579+#define __bos1(ptr) __bos((ptr), 1)
72580 #endif /* GCC_VERSION >= 40300 */
72581
72582 #if GCC_VERSION >= 40500
72583+
72584+#ifdef CONSTIFY_PLUGIN
72585+#define __no_const __attribute__((no_const))
72586+#define __do_const __attribute__((do_const))
72587+#endif
72588+
72589+#ifdef SIZE_OVERFLOW_PLUGIN
72590+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
72591+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
72592+#endif
72593+
72594+#ifdef LATENT_ENTROPY_PLUGIN
72595+#define __latent_entropy __attribute__((latent_entropy))
72596+#endif
72597+
72598 /*
72599 * Mark a position in code as unreachable. This can be used to
72600 * suppress control flow warnings after asm blocks that transfer
72601diff --git a/include/linux/compiler.h b/include/linux/compiler.h
72602index 92669cd..1771a15 100644
72603--- a/include/linux/compiler.h
72604+++ b/include/linux/compiler.h
72605@@ -5,11 +5,14 @@
72606
72607 #ifdef __CHECKER__
72608 # define __user __attribute__((noderef, address_space(1)))
72609+# define __force_user __force __user
72610 # define __kernel __attribute__((address_space(0)))
72611+# define __force_kernel __force __kernel
72612 # define __safe __attribute__((safe))
72613 # define __force __attribute__((force))
72614 # define __nocast __attribute__((nocast))
72615 # define __iomem __attribute__((noderef, address_space(2)))
72616+# define __force_iomem __force __iomem
72617 # define __must_hold(x) __attribute__((context(x,1,1)))
72618 # define __acquires(x) __attribute__((context(x,0,1)))
72619 # define __releases(x) __attribute__((context(x,1,0)))
72620@@ -17,20 +20,37 @@
72621 # define __release(x) __context__(x,-1)
72622 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
72623 # define __percpu __attribute__((noderef, address_space(3)))
72624+# define __force_percpu __force __percpu
72625 #ifdef CONFIG_SPARSE_RCU_POINTER
72626 # define __rcu __attribute__((noderef, address_space(4)))
72627+# define __force_rcu __force __rcu
72628 #else
72629 # define __rcu
72630+# define __force_rcu
72631 #endif
72632 extern void __chk_user_ptr(const volatile void __user *);
72633 extern void __chk_io_ptr(const volatile void __iomem *);
72634 #else
72635-# define __user
72636-# define __kernel
72637+# ifdef CHECKER_PLUGIN
72638+//# define __user
72639+//# define __force_user
72640+//# define __kernel
72641+//# define __force_kernel
72642+# else
72643+# ifdef STRUCTLEAK_PLUGIN
72644+# define __user __attribute__((user))
72645+# else
72646+# define __user
72647+# endif
72648+# define __force_user
72649+# define __kernel
72650+# define __force_kernel
72651+# endif
72652 # define __safe
72653 # define __force
72654 # define __nocast
72655 # define __iomem
72656+# define __force_iomem
72657 # define __chk_user_ptr(x) (void)0
72658 # define __chk_io_ptr(x) (void)0
72659 # define __builtin_warning(x, y...) (1)
72660@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
72661 # define __release(x) (void)0
72662 # define __cond_lock(x,c) (c)
72663 # define __percpu
72664+# define __force_percpu
72665 # define __rcu
72666+# define __force_rcu
72667 #endif
72668
72669 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
72670@@ -275,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
72671 # define __attribute_const__ /* unimplemented */
72672 #endif
72673
72674+#ifndef __no_const
72675+# define __no_const
72676+#endif
72677+
72678+#ifndef __do_const
72679+# define __do_const
72680+#endif
72681+
72682+#ifndef __size_overflow
72683+# define __size_overflow(...)
72684+#endif
72685+
72686+#ifndef __intentional_overflow
72687+# define __intentional_overflow(...)
72688+#endif
72689+
72690+#ifndef __latent_entropy
72691+# define __latent_entropy
72692+#endif
72693+
72694 /*
72695 * Tell gcc if a function is cold. The compiler will assume any path
72696 * directly leading to the call is unlikely.
72697@@ -284,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
72698 #define __cold
72699 #endif
72700
72701+#ifndef __alloc_size
72702+#define __alloc_size(...)
72703+#endif
72704+
72705+#ifndef __bos
72706+#define __bos(ptr, arg)
72707+#endif
72708+
72709+#ifndef __bos0
72710+#define __bos0(ptr)
72711+#endif
72712+
72713+#ifndef __bos1
72714+#define __bos1(ptr)
72715+#endif
72716+
72717 /* Simple shorthand for a section definition */
72718 #ifndef __section
72719 # define __section(S) __attribute__ ((__section__(#S)))
72720@@ -349,7 +407,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
72721 * use is to mediate communication between process-level code and irq/NMI
72722 * handlers, all running on the same CPU.
72723 */
72724-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
72725+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
72726+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
72727
72728 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
72729 #ifdef CONFIG_KPROBES
72730diff --git a/include/linux/completion.h b/include/linux/completion.h
72731index 3cd574d..adce5fa 100644
72732--- a/include/linux/completion.h
72733+++ b/include/linux/completion.h
72734@@ -79,15 +79,15 @@ static inline void init_completion(struct completion *x)
72735 extern void wait_for_completion(struct completion *);
72736 extern void wait_for_completion_io(struct completion *);
72737 extern int wait_for_completion_interruptible(struct completion *x);
72738-extern int wait_for_completion_killable(struct completion *x);
72739+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
72740 extern unsigned long wait_for_completion_timeout(struct completion *x,
72741 unsigned long timeout);
72742 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
72743 unsigned long timeout);
72744 extern long wait_for_completion_interruptible_timeout(
72745- struct completion *x, unsigned long timeout);
72746+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
72747 extern long wait_for_completion_killable_timeout(
72748- struct completion *x, unsigned long timeout);
72749+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
72750 extern bool try_wait_for_completion(struct completion *x);
72751 extern bool completion_done(struct completion *x);
72752
72753diff --git a/include/linux/configfs.h b/include/linux/configfs.h
72754index 34025df..d94bbbc 100644
72755--- a/include/linux/configfs.h
72756+++ b/include/linux/configfs.h
72757@@ -125,7 +125,7 @@ struct configfs_attribute {
72758 const char *ca_name;
72759 struct module *ca_owner;
72760 umode_t ca_mode;
72761-};
72762+} __do_const;
72763
72764 /*
72765 * Users often need to create attribute structures for their configurable
72766diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
72767index 90d5a15..950cb80 100644
72768--- a/include/linux/cpufreq.h
72769+++ b/include/linux/cpufreq.h
72770@@ -266,7 +266,7 @@ struct cpufreq_driver {
72771 int (*suspend) (struct cpufreq_policy *policy);
72772 int (*resume) (struct cpufreq_policy *policy);
72773 struct freq_attr **attr;
72774-};
72775+} __do_const;
72776
72777 /* flags */
72778
72779@@ -325,6 +325,7 @@ struct global_attr {
72780 ssize_t (*store)(struct kobject *a, struct attribute *b,
72781 const char *c, size_t count);
72782 };
72783+typedef struct global_attr __no_const global_attr_no_const;
72784
72785 #define define_one_global_ro(_name) \
72786 static struct global_attr _name = \
72787diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
72788index 0bc4b74..973b368 100644
72789--- a/include/linux/cpuidle.h
72790+++ b/include/linux/cpuidle.h
72791@@ -52,7 +52,8 @@ struct cpuidle_state {
72792 int index);
72793
72794 int (*enter_dead) (struct cpuidle_device *dev, int index);
72795-};
72796+} __do_const;
72797+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
72798
72799 /* Idle State Flags */
72800 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
72801@@ -191,7 +192,7 @@ struct cpuidle_governor {
72802 void (*reflect) (struct cpuidle_device *dev, int index);
72803
72804 struct module *owner;
72805-};
72806+} __do_const;
72807
72808 #ifdef CONFIG_CPU_IDLE
72809
72810diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
72811index d08e4d2..95fad61 100644
72812--- a/include/linux/cpumask.h
72813+++ b/include/linux/cpumask.h
72814@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
72815 }
72816
72817 /* Valid inputs for n are -1 and 0. */
72818-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
72819+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
72820 {
72821 return n+1;
72822 }
72823
72824-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
72825+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
72826 {
72827 return n+1;
72828 }
72829
72830-static inline unsigned int cpumask_next_and(int n,
72831+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
72832 const struct cpumask *srcp,
72833 const struct cpumask *andp)
72834 {
72835@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
72836 *
72837 * Returns >= nr_cpu_ids if no further cpus set.
72838 */
72839-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
72840+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
72841 {
72842 /* -1 is a legal arg here. */
72843 if (n != -1)
72844@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
72845 *
72846 * Returns >= nr_cpu_ids if no further cpus unset.
72847 */
72848-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
72849+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
72850 {
72851 /* -1 is a legal arg here. */
72852 if (n != -1)
72853@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
72854 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
72855 }
72856
72857-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
72858+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
72859 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
72860
72861 /**
72862diff --git a/include/linux/cred.h b/include/linux/cred.h
72863index 04421e8..6bce4ef 100644
72864--- a/include/linux/cred.h
72865+++ b/include/linux/cred.h
72866@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
72867 static inline void validate_process_creds(void)
72868 {
72869 }
72870+static inline void validate_task_creds(struct task_struct *task)
72871+{
72872+}
72873 #endif
72874
72875 /**
72876diff --git a/include/linux/crypto.h b/include/linux/crypto.h
72877index b92eadf..b4ecdc1 100644
72878--- a/include/linux/crypto.h
72879+++ b/include/linux/crypto.h
72880@@ -373,7 +373,7 @@ struct cipher_tfm {
72881 const u8 *key, unsigned int keylen);
72882 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
72883 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
72884-};
72885+} __no_const;
72886
72887 struct hash_tfm {
72888 int (*init)(struct hash_desc *desc);
72889@@ -394,13 +394,13 @@ struct compress_tfm {
72890 int (*cot_decompress)(struct crypto_tfm *tfm,
72891 const u8 *src, unsigned int slen,
72892 u8 *dst, unsigned int *dlen);
72893-};
72894+} __no_const;
72895
72896 struct rng_tfm {
72897 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
72898 unsigned int dlen);
72899 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
72900-};
72901+} __no_const;
72902
72903 #define crt_ablkcipher crt_u.ablkcipher
72904 #define crt_aead crt_u.aead
72905diff --git a/include/linux/ctype.h b/include/linux/ctype.h
72906index 653589e..4ef254a 100644
72907--- a/include/linux/ctype.h
72908+++ b/include/linux/ctype.h
72909@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
72910 * Fast implementation of tolower() for internal usage. Do not use in your
72911 * code.
72912 */
72913-static inline char _tolower(const char c)
72914+static inline unsigned char _tolower(const unsigned char c)
72915 {
72916 return c | 0x20;
72917 }
72918diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
72919index 7925bf0..d5143d2 100644
72920--- a/include/linux/decompress/mm.h
72921+++ b/include/linux/decompress/mm.h
72922@@ -77,7 +77,7 @@ static void free(void *where)
72923 * warnings when not needed (indeed large_malloc / large_free are not
72924 * needed by inflate */
72925
72926-#define malloc(a) kmalloc(a, GFP_KERNEL)
72927+#define malloc(a) kmalloc((a), GFP_KERNEL)
72928 #define free(a) kfree(a)
72929
72930 #define large_malloc(a) vmalloc(a)
72931diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
72932index 5f1ab92..39c35ae 100644
72933--- a/include/linux/devfreq.h
72934+++ b/include/linux/devfreq.h
72935@@ -114,7 +114,7 @@ struct devfreq_governor {
72936 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
72937 int (*event_handler)(struct devfreq *devfreq,
72938 unsigned int event, void *data);
72939-};
72940+} __do_const;
72941
72942 /**
72943 * struct devfreq - Device devfreq structure
72944diff --git a/include/linux/device.h b/include/linux/device.h
72945index 22b546a..a573dc9 100644
72946--- a/include/linux/device.h
72947+++ b/include/linux/device.h
72948@@ -305,7 +305,7 @@ struct subsys_interface {
72949 struct list_head node;
72950 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
72951 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
72952-};
72953+} __do_const;
72954
72955 int subsys_interface_register(struct subsys_interface *sif);
72956 void subsys_interface_unregister(struct subsys_interface *sif);
72957@@ -493,7 +493,7 @@ struct device_type {
72958 void (*release)(struct device *dev);
72959
72960 const struct dev_pm_ops *pm;
72961-};
72962+} __do_const;
72963
72964 /* interface for exporting device attributes */
72965 struct device_attribute {
72966@@ -503,11 +503,12 @@ struct device_attribute {
72967 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
72968 const char *buf, size_t count);
72969 };
72970+typedef struct device_attribute __no_const device_attribute_no_const;
72971
72972 struct dev_ext_attribute {
72973 struct device_attribute attr;
72974 void *var;
72975-};
72976+} __do_const;
72977
72978 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
72979 char *buf);
72980diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
72981index 94af418..b1ca7a2 100644
72982--- a/include/linux/dma-mapping.h
72983+++ b/include/linux/dma-mapping.h
72984@@ -54,7 +54,7 @@ struct dma_map_ops {
72985 u64 (*get_required_mask)(struct device *dev);
72986 #endif
72987 int is_phys;
72988-};
72989+} __do_const;
72990
72991 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
72992
72993diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
72994index cb286b1..923d066 100644
72995--- a/include/linux/dmaengine.h
72996+++ b/include/linux/dmaengine.h
72997@@ -1030,9 +1030,9 @@ struct dma_pinned_list {
72998 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
72999 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
73000
73001-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
73002+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
73003 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
73004-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
73005+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
73006 struct dma_pinned_list *pinned_list, struct page *page,
73007 unsigned int offset, size_t len);
73008
73009diff --git a/include/linux/efi.h b/include/linux/efi.h
73010index 5f8f176..62a0556 100644
73011--- a/include/linux/efi.h
73012+++ b/include/linux/efi.h
73013@@ -745,6 +745,7 @@ struct efivar_operations {
73014 efi_set_variable_t *set_variable;
73015 efi_query_variable_store_t *query_variable_store;
73016 };
73017+typedef struct efivar_operations __no_const efivar_operations_no_const;
73018
73019 struct efivars {
73020 /*
73021diff --git a/include/linux/elf.h b/include/linux/elf.h
73022index 40a3c0e..4c45a38 100644
73023--- a/include/linux/elf.h
73024+++ b/include/linux/elf.h
73025@@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
73026 #define elf_note elf32_note
73027 #define elf_addr_t Elf32_Off
73028 #define Elf_Half Elf32_Half
73029+#define elf_dyn Elf32_Dyn
73030
73031 #else
73032
73033@@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
73034 #define elf_note elf64_note
73035 #define elf_addr_t Elf64_Off
73036 #define Elf_Half Elf64_Half
73037+#define elf_dyn Elf64_Dyn
73038
73039 #endif
73040
73041diff --git a/include/linux/err.h b/include/linux/err.h
73042index 221fcfb..f29e5e2 100644
73043--- a/include/linux/err.h
73044+++ b/include/linux/err.h
73045@@ -19,12 +19,12 @@
73046
73047 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
73048
73049-static inline void * __must_check ERR_PTR(long error)
73050+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
73051 {
73052 return (void *) error;
73053 }
73054
73055-static inline long __must_check PTR_ERR(__force const void *ptr)
73056+static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
73057 {
73058 return (long) ptr;
73059 }
73060diff --git a/include/linux/extcon.h b/include/linux/extcon.h
73061index fcb51c8..bdafcf6 100644
73062--- a/include/linux/extcon.h
73063+++ b/include/linux/extcon.h
73064@@ -134,7 +134,7 @@ struct extcon_dev {
73065 /* /sys/class/extcon/.../mutually_exclusive/... */
73066 struct attribute_group attr_g_muex;
73067 struct attribute **attrs_muex;
73068- struct device_attribute *d_attrs_muex;
73069+ device_attribute_no_const *d_attrs_muex;
73070 };
73071
73072 /**
73073diff --git a/include/linux/fb.h b/include/linux/fb.h
73074index ffac70a..ca3e711 100644
73075--- a/include/linux/fb.h
73076+++ b/include/linux/fb.h
73077@@ -304,7 +304,7 @@ struct fb_ops {
73078 /* called at KDB enter and leave time to prepare the console */
73079 int (*fb_debug_enter)(struct fb_info *info);
73080 int (*fb_debug_leave)(struct fb_info *info);
73081-};
73082+} __do_const;
73083
73084 #ifdef CONFIG_FB_TILEBLITTING
73085 #define FB_TILE_CURSOR_NONE 0
73086diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
73087index 085197b..0fa6f0b 100644
73088--- a/include/linux/fdtable.h
73089+++ b/include/linux/fdtable.h
73090@@ -95,7 +95,7 @@ struct files_struct *get_files_struct(struct task_struct *);
73091 void put_files_struct(struct files_struct *fs);
73092 void reset_files_struct(struct files_struct *);
73093 int unshare_files(struct files_struct **);
73094-struct files_struct *dup_fd(struct files_struct *, int *);
73095+struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
73096 void do_close_on_exec(struct files_struct *);
73097 int iterate_fd(struct files_struct *, unsigned,
73098 int (*)(const void *, struct file *, unsigned),
73099diff --git a/include/linux/filter.h b/include/linux/filter.h
73100index a6ac848..a104a76 100644
73101--- a/include/linux/filter.h
73102+++ b/include/linux/filter.h
73103@@ -20,6 +20,7 @@ struct compat_sock_fprog {
73104
73105 struct sk_buff;
73106 struct sock;
73107+struct bpf_jit_work;
73108
73109 struct sk_filter
73110 {
73111@@ -27,6 +28,9 @@ struct sk_filter
73112 unsigned int len; /* Number of filter blocks */
73113 unsigned int (*bpf_func)(const struct sk_buff *skb,
73114 const struct sock_filter *filter);
73115+#ifdef CONFIG_BPF_JIT
73116+ struct bpf_jit_work *work;
73117+#endif
73118 struct rcu_head rcu;
73119 struct sock_filter insns[0];
73120 };
73121diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
73122index 8293262..2b3b8bd 100644
73123--- a/include/linux/frontswap.h
73124+++ b/include/linux/frontswap.h
73125@@ -11,7 +11,7 @@ struct frontswap_ops {
73126 int (*load)(unsigned, pgoff_t, struct page *);
73127 void (*invalidate_page)(unsigned, pgoff_t);
73128 void (*invalidate_area)(unsigned);
73129-};
73130+} __no_const;
73131
73132 extern bool frontswap_enabled;
73133 extern struct frontswap_ops *
73134diff --git a/include/linux/fs.h b/include/linux/fs.h
73135index 9818747..788bfbd 100644
73136--- a/include/linux/fs.h
73137+++ b/include/linux/fs.h
73138@@ -1554,7 +1554,8 @@ struct file_operations {
73139 long (*fallocate)(struct file *file, int mode, loff_t offset,
73140 loff_t len);
73141 int (*show_fdinfo)(struct seq_file *m, struct file *f);
73142-};
73143+} __do_const;
73144+typedef struct file_operations __no_const file_operations_no_const;
73145
73146 struct inode_operations {
73147 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
73148@@ -2740,4 +2741,14 @@ static inline bool dir_relax(struct inode *inode)
73149 return !IS_DEADDIR(inode);
73150 }
73151
73152+static inline bool is_sidechannel_device(const struct inode *inode)
73153+{
73154+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
73155+ umode_t mode = inode->i_mode;
73156+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
73157+#else
73158+ return false;
73159+#endif
73160+}
73161+
73162 #endif /* _LINUX_FS_H */
73163diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
73164index 2b93a9a..855d94a 100644
73165--- a/include/linux/fs_struct.h
73166+++ b/include/linux/fs_struct.h
73167@@ -6,7 +6,7 @@
73168 #include <linux/seqlock.h>
73169
73170 struct fs_struct {
73171- int users;
73172+ atomic_t users;
73173 spinlock_t lock;
73174 seqcount_t seq;
73175 int umask;
73176diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
73177index a9ff9a3..1ba1788 100644
73178--- a/include/linux/fscache-cache.h
73179+++ b/include/linux/fscache-cache.h
73180@@ -113,7 +113,7 @@ struct fscache_operation {
73181 fscache_operation_release_t release;
73182 };
73183
73184-extern atomic_t fscache_op_debug_id;
73185+extern atomic_unchecked_t fscache_op_debug_id;
73186 extern void fscache_op_work_func(struct work_struct *work);
73187
73188 extern void fscache_enqueue_operation(struct fscache_operation *);
73189@@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
73190 INIT_WORK(&op->work, fscache_op_work_func);
73191 atomic_set(&op->usage, 1);
73192 op->state = FSCACHE_OP_ST_INITIALISED;
73193- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
73194+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
73195 op->processor = processor;
73196 op->release = release;
73197 INIT_LIST_HEAD(&op->pend_link);
73198diff --git a/include/linux/fscache.h b/include/linux/fscache.h
73199index 7a08623..4c07b0f 100644
73200--- a/include/linux/fscache.h
73201+++ b/include/linux/fscache.h
73202@@ -152,7 +152,7 @@ struct fscache_cookie_def {
73203 * - this is mandatory for any object that may have data
73204 */
73205 void (*now_uncached)(void *cookie_netfs_data);
73206-};
73207+} __do_const;
73208
73209 /*
73210 * fscache cached network filesystem type
73211diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
73212index 1c804b0..1432c2b 100644
73213--- a/include/linux/fsnotify.h
73214+++ b/include/linux/fsnotify.h
73215@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
73216 struct inode *inode = file_inode(file);
73217 __u32 mask = FS_ACCESS;
73218
73219+ if (is_sidechannel_device(inode))
73220+ return;
73221+
73222 if (S_ISDIR(inode->i_mode))
73223 mask |= FS_ISDIR;
73224
73225@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
73226 struct inode *inode = file_inode(file);
73227 __u32 mask = FS_MODIFY;
73228
73229+ if (is_sidechannel_device(inode))
73230+ return;
73231+
73232 if (S_ISDIR(inode->i_mode))
73233 mask |= FS_ISDIR;
73234
73235@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
73236 */
73237 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
73238 {
73239- return kstrdup(name, GFP_KERNEL);
73240+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
73241 }
73242
73243 /*
73244diff --git a/include/linux/genhd.h b/include/linux/genhd.h
73245index 9f3c275..911b591 100644
73246--- a/include/linux/genhd.h
73247+++ b/include/linux/genhd.h
73248@@ -194,7 +194,7 @@ struct gendisk {
73249 struct kobject *slave_dir;
73250
73251 struct timer_rand_state *random;
73252- atomic_t sync_io; /* RAID */
73253+ atomic_unchecked_t sync_io; /* RAID */
73254 struct disk_events *ev;
73255 #ifdef CONFIG_BLK_DEV_INTEGRITY
73256 struct blk_integrity *integrity;
73257diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
73258index 023bc34..b02b46a 100644
73259--- a/include/linux/genl_magic_func.h
73260+++ b/include/linux/genl_magic_func.h
73261@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
73262 },
73263
73264 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
73265-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
73266+static struct genl_ops ZZZ_genl_ops[] = {
73267 #include GENL_MAGIC_INCLUDE_FILE
73268 };
73269
73270diff --git a/include/linux/gfp.h b/include/linux/gfp.h
73271index 9b4dd49..61fd41d 100644
73272--- a/include/linux/gfp.h
73273+++ b/include/linux/gfp.h
73274@@ -35,6 +35,13 @@ struct vm_area_struct;
73275 #define ___GFP_NO_KSWAPD 0x400000u
73276 #define ___GFP_OTHER_NODE 0x800000u
73277 #define ___GFP_WRITE 0x1000000u
73278+
73279+#ifdef CONFIG_PAX_USERCOPY_SLABS
73280+#define ___GFP_USERCOPY 0x2000000u
73281+#else
73282+#define ___GFP_USERCOPY 0
73283+#endif
73284+
73285 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
73286
73287 /*
73288@@ -92,6 +99,7 @@ struct vm_area_struct;
73289 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
73290 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
73291 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
73292+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
73293
73294 /*
73295 * This may seem redundant, but it's a way of annotating false positives vs.
73296@@ -99,7 +107,7 @@ struct vm_area_struct;
73297 */
73298 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
73299
73300-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
73301+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
73302 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
73303
73304 /* This equals 0, but use constants in case they ever change */
73305@@ -153,6 +161,8 @@ struct vm_area_struct;
73306 /* 4GB DMA on some platforms */
73307 #define GFP_DMA32 __GFP_DMA32
73308
73309+#define GFP_USERCOPY __GFP_USERCOPY
73310+
73311 /* Convert GFP flags to their corresponding migrate type */
73312 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
73313 {
73314diff --git a/include/linux/gracl.h b/include/linux/gracl.h
73315new file mode 100644
73316index 0000000..ebe6d72
73317--- /dev/null
73318+++ b/include/linux/gracl.h
73319@@ -0,0 +1,319 @@
73320+#ifndef GR_ACL_H
73321+#define GR_ACL_H
73322+
73323+#include <linux/grdefs.h>
73324+#include <linux/resource.h>
73325+#include <linux/capability.h>
73326+#include <linux/dcache.h>
73327+#include <asm/resource.h>
73328+
73329+/* Major status information */
73330+
73331+#define GR_VERSION "grsecurity 2.9.1"
73332+#define GRSECURITY_VERSION 0x2901
73333+
73334+enum {
73335+ GR_SHUTDOWN = 0,
73336+ GR_ENABLE = 1,
73337+ GR_SPROLE = 2,
73338+ GR_RELOAD = 3,
73339+ GR_SEGVMOD = 4,
73340+ GR_STATUS = 5,
73341+ GR_UNSPROLE = 6,
73342+ GR_PASSSET = 7,
73343+ GR_SPROLEPAM = 8,
73344+};
73345+
73346+/* Password setup definitions
73347+ * kernel/grhash.c */
73348+enum {
73349+ GR_PW_LEN = 128,
73350+ GR_SALT_LEN = 16,
73351+ GR_SHA_LEN = 32,
73352+};
73353+
73354+enum {
73355+ GR_SPROLE_LEN = 64,
73356+};
73357+
73358+enum {
73359+ GR_NO_GLOB = 0,
73360+ GR_REG_GLOB,
73361+ GR_CREATE_GLOB
73362+};
73363+
73364+#define GR_NLIMITS 32
73365+
73366+/* Begin Data Structures */
73367+
73368+struct sprole_pw {
73369+ unsigned char *rolename;
73370+ unsigned char salt[GR_SALT_LEN];
73371+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
73372+};
73373+
73374+struct name_entry {
73375+ __u32 key;
73376+ ino_t inode;
73377+ dev_t device;
73378+ char *name;
73379+ __u16 len;
73380+ __u8 deleted;
73381+ struct name_entry *prev;
73382+ struct name_entry *next;
73383+};
73384+
73385+struct inodev_entry {
73386+ struct name_entry *nentry;
73387+ struct inodev_entry *prev;
73388+ struct inodev_entry *next;
73389+};
73390+
73391+struct acl_role_db {
73392+ struct acl_role_label **r_hash;
73393+ __u32 r_size;
73394+};
73395+
73396+struct inodev_db {
73397+ struct inodev_entry **i_hash;
73398+ __u32 i_size;
73399+};
73400+
73401+struct name_db {
73402+ struct name_entry **n_hash;
73403+ __u32 n_size;
73404+};
73405+
73406+struct crash_uid {
73407+ uid_t uid;
73408+ unsigned long expires;
73409+};
73410+
73411+struct gr_hash_struct {
73412+ void **table;
73413+ void **nametable;
73414+ void *first;
73415+ __u32 table_size;
73416+ __u32 used_size;
73417+ int type;
73418+};
73419+
73420+/* Userspace Grsecurity ACL data structures */
73421+
73422+struct acl_subject_label {
73423+ char *filename;
73424+ ino_t inode;
73425+ dev_t device;
73426+ __u32 mode;
73427+ kernel_cap_t cap_mask;
73428+ kernel_cap_t cap_lower;
73429+ kernel_cap_t cap_invert_audit;
73430+
73431+ struct rlimit res[GR_NLIMITS];
73432+ __u32 resmask;
73433+
73434+ __u8 user_trans_type;
73435+ __u8 group_trans_type;
73436+ uid_t *user_transitions;
73437+ gid_t *group_transitions;
73438+ __u16 user_trans_num;
73439+ __u16 group_trans_num;
73440+
73441+ __u32 sock_families[2];
73442+ __u32 ip_proto[8];
73443+ __u32 ip_type;
73444+ struct acl_ip_label **ips;
73445+ __u32 ip_num;
73446+ __u32 inaddr_any_override;
73447+
73448+ __u32 crashes;
73449+ unsigned long expires;
73450+
73451+ struct acl_subject_label *parent_subject;
73452+ struct gr_hash_struct *hash;
73453+ struct acl_subject_label *prev;
73454+ struct acl_subject_label *next;
73455+
73456+ struct acl_object_label **obj_hash;
73457+ __u32 obj_hash_size;
73458+ __u16 pax_flags;
73459+};
73460+
73461+struct role_allowed_ip {
73462+ __u32 addr;
73463+ __u32 netmask;
73464+
73465+ struct role_allowed_ip *prev;
73466+ struct role_allowed_ip *next;
73467+};
73468+
73469+struct role_transition {
73470+ char *rolename;
73471+
73472+ struct role_transition *prev;
73473+ struct role_transition *next;
73474+};
73475+
73476+struct acl_role_label {
73477+ char *rolename;
73478+ uid_t uidgid;
73479+ __u16 roletype;
73480+
73481+ __u16 auth_attempts;
73482+ unsigned long expires;
73483+
73484+ struct acl_subject_label *root_label;
73485+ struct gr_hash_struct *hash;
73486+
73487+ struct acl_role_label *prev;
73488+ struct acl_role_label *next;
73489+
73490+ struct role_transition *transitions;
73491+ struct role_allowed_ip *allowed_ips;
73492+ uid_t *domain_children;
73493+ __u16 domain_child_num;
73494+
73495+ umode_t umask;
73496+
73497+ struct acl_subject_label **subj_hash;
73498+ __u32 subj_hash_size;
73499+};
73500+
73501+struct user_acl_role_db {
73502+ struct acl_role_label **r_table;
73503+ __u32 num_pointers; /* Number of allocations to track */
73504+ __u32 num_roles; /* Number of roles */
73505+ __u32 num_domain_children; /* Number of domain children */
73506+ __u32 num_subjects; /* Number of subjects */
73507+ __u32 num_objects; /* Number of objects */
73508+};
73509+
73510+struct acl_object_label {
73511+ char *filename;
73512+ ino_t inode;
73513+ dev_t device;
73514+ __u32 mode;
73515+
73516+ struct acl_subject_label *nested;
73517+ struct acl_object_label *globbed;
73518+
73519+ /* next two structures not used */
73520+
73521+ struct acl_object_label *prev;
73522+ struct acl_object_label *next;
73523+};
73524+
73525+struct acl_ip_label {
73526+ char *iface;
73527+ __u32 addr;
73528+ __u32 netmask;
73529+ __u16 low, high;
73530+ __u8 mode;
73531+ __u32 type;
73532+ __u32 proto[8];
73533+
73534+ /* next two structures not used */
73535+
73536+ struct acl_ip_label *prev;
73537+ struct acl_ip_label *next;
73538+};
73539+
73540+struct gr_arg {
73541+ struct user_acl_role_db role_db;
73542+ unsigned char pw[GR_PW_LEN];
73543+ unsigned char salt[GR_SALT_LEN];
73544+ unsigned char sum[GR_SHA_LEN];
73545+ unsigned char sp_role[GR_SPROLE_LEN];
73546+ struct sprole_pw *sprole_pws;
73547+ dev_t segv_device;
73548+ ino_t segv_inode;
73549+ uid_t segv_uid;
73550+ __u16 num_sprole_pws;
73551+ __u16 mode;
73552+};
73553+
73554+struct gr_arg_wrapper {
73555+ struct gr_arg *arg;
73556+ __u32 version;
73557+ __u32 size;
73558+};
73559+
73560+struct subject_map {
73561+ struct acl_subject_label *user;
73562+ struct acl_subject_label *kernel;
73563+ struct subject_map *prev;
73564+ struct subject_map *next;
73565+};
73566+
73567+struct acl_subj_map_db {
73568+ struct subject_map **s_hash;
73569+ __u32 s_size;
73570+};
73571+
73572+/* End Data Structures Section */
73573+
73574+/* Hash functions generated by empirical testing by Brad Spengler
73575+ Makes good use of the low bits of the inode. Generally 0-1 times
73576+ in loop for successful match. 0-3 for unsuccessful match.
73577+ Shift/add algorithm with modulus of table size and an XOR*/
73578+
73579+static __inline__ unsigned int
73580+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
73581+{
73582+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
73583+}
73584+
73585+ static __inline__ unsigned int
73586+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
73587+{
73588+ return ((const unsigned long)userp % sz);
73589+}
73590+
73591+static __inline__ unsigned int
73592+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
73593+{
73594+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
73595+}
73596+
73597+static __inline__ unsigned int
73598+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
73599+{
73600+ return full_name_hash((const unsigned char *)name, len) % sz;
73601+}
73602+
73603+#define FOR_EACH_ROLE_START(role) \
73604+ role = role_list; \
73605+ while (role) {
73606+
73607+#define FOR_EACH_ROLE_END(role) \
73608+ role = role->prev; \
73609+ }
73610+
73611+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
73612+ subj = NULL; \
73613+ iter = 0; \
73614+ while (iter < role->subj_hash_size) { \
73615+ if (subj == NULL) \
73616+ subj = role->subj_hash[iter]; \
73617+ if (subj == NULL) { \
73618+ iter++; \
73619+ continue; \
73620+ }
73621+
73622+#define FOR_EACH_SUBJECT_END(subj,iter) \
73623+ subj = subj->next; \
73624+ if (subj == NULL) \
73625+ iter++; \
73626+ }
73627+
73628+
73629+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
73630+ subj = role->hash->first; \
73631+ while (subj != NULL) {
73632+
73633+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
73634+ subj = subj->next; \
73635+ }
73636+
73637+#endif
73638+
73639diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
73640new file mode 100644
73641index 0000000..33ebd1f
73642--- /dev/null
73643+++ b/include/linux/gracl_compat.h
73644@@ -0,0 +1,156 @@
73645+#ifndef GR_ACL_COMPAT_H
73646+#define GR_ACL_COMPAT_H
73647+
73648+#include <linux/resource.h>
73649+#include <asm/resource.h>
73650+
73651+struct sprole_pw_compat {
73652+ compat_uptr_t rolename;
73653+ unsigned char salt[GR_SALT_LEN];
73654+ unsigned char sum[GR_SHA_LEN];
73655+};
73656+
73657+struct gr_hash_struct_compat {
73658+ compat_uptr_t table;
73659+ compat_uptr_t nametable;
73660+ compat_uptr_t first;
73661+ __u32 table_size;
73662+ __u32 used_size;
73663+ int type;
73664+};
73665+
73666+struct acl_subject_label_compat {
73667+ compat_uptr_t filename;
73668+ compat_ino_t inode;
73669+ __u32 device;
73670+ __u32 mode;
73671+ kernel_cap_t cap_mask;
73672+ kernel_cap_t cap_lower;
73673+ kernel_cap_t cap_invert_audit;
73674+
73675+ struct compat_rlimit res[GR_NLIMITS];
73676+ __u32 resmask;
73677+
73678+ __u8 user_trans_type;
73679+ __u8 group_trans_type;
73680+ compat_uptr_t user_transitions;
73681+ compat_uptr_t group_transitions;
73682+ __u16 user_trans_num;
73683+ __u16 group_trans_num;
73684+
73685+ __u32 sock_families[2];
73686+ __u32 ip_proto[8];
73687+ __u32 ip_type;
73688+ compat_uptr_t ips;
73689+ __u32 ip_num;
73690+ __u32 inaddr_any_override;
73691+
73692+ __u32 crashes;
73693+ compat_ulong_t expires;
73694+
73695+ compat_uptr_t parent_subject;
73696+ compat_uptr_t hash;
73697+ compat_uptr_t prev;
73698+ compat_uptr_t next;
73699+
73700+ compat_uptr_t obj_hash;
73701+ __u32 obj_hash_size;
73702+ __u16 pax_flags;
73703+};
73704+
73705+struct role_allowed_ip_compat {
73706+ __u32 addr;
73707+ __u32 netmask;
73708+
73709+ compat_uptr_t prev;
73710+ compat_uptr_t next;
73711+};
73712+
73713+struct role_transition_compat {
73714+ compat_uptr_t rolename;
73715+
73716+ compat_uptr_t prev;
73717+ compat_uptr_t next;
73718+};
73719+
73720+struct acl_role_label_compat {
73721+ compat_uptr_t rolename;
73722+ uid_t uidgid;
73723+ __u16 roletype;
73724+
73725+ __u16 auth_attempts;
73726+ compat_ulong_t expires;
73727+
73728+ compat_uptr_t root_label;
73729+ compat_uptr_t hash;
73730+
73731+ compat_uptr_t prev;
73732+ compat_uptr_t next;
73733+
73734+ compat_uptr_t transitions;
73735+ compat_uptr_t allowed_ips;
73736+ compat_uptr_t domain_children;
73737+ __u16 domain_child_num;
73738+
73739+ umode_t umask;
73740+
73741+ compat_uptr_t subj_hash;
73742+ __u32 subj_hash_size;
73743+};
73744+
73745+struct user_acl_role_db_compat {
73746+ compat_uptr_t r_table;
73747+ __u32 num_pointers;
73748+ __u32 num_roles;
73749+ __u32 num_domain_children;
73750+ __u32 num_subjects;
73751+ __u32 num_objects;
73752+};
73753+
73754+struct acl_object_label_compat {
73755+ compat_uptr_t filename;
73756+ compat_ino_t inode;
73757+ __u32 device;
73758+ __u32 mode;
73759+
73760+ compat_uptr_t nested;
73761+ compat_uptr_t globbed;
73762+
73763+ compat_uptr_t prev;
73764+ compat_uptr_t next;
73765+};
73766+
73767+struct acl_ip_label_compat {
73768+ compat_uptr_t iface;
73769+ __u32 addr;
73770+ __u32 netmask;
73771+ __u16 low, high;
73772+ __u8 mode;
73773+ __u32 type;
73774+ __u32 proto[8];
73775+
73776+ compat_uptr_t prev;
73777+ compat_uptr_t next;
73778+};
73779+
73780+struct gr_arg_compat {
73781+ struct user_acl_role_db_compat role_db;
73782+ unsigned char pw[GR_PW_LEN];
73783+ unsigned char salt[GR_SALT_LEN];
73784+ unsigned char sum[GR_SHA_LEN];
73785+ unsigned char sp_role[GR_SPROLE_LEN];
73786+ compat_uptr_t sprole_pws;
73787+ __u32 segv_device;
73788+ compat_ino_t segv_inode;
73789+ uid_t segv_uid;
73790+ __u16 num_sprole_pws;
73791+ __u16 mode;
73792+};
73793+
73794+struct gr_arg_wrapper_compat {
73795+ compat_uptr_t arg;
73796+ __u32 version;
73797+ __u32 size;
73798+};
73799+
73800+#endif
73801diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
73802new file mode 100644
73803index 0000000..323ecf2
73804--- /dev/null
73805+++ b/include/linux/gralloc.h
73806@@ -0,0 +1,9 @@
73807+#ifndef __GRALLOC_H
73808+#define __GRALLOC_H
73809+
73810+void acl_free_all(void);
73811+int acl_alloc_stack_init(unsigned long size);
73812+void *acl_alloc(unsigned long len);
73813+void *acl_alloc_num(unsigned long num, unsigned long len);
73814+
73815+#endif
73816diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
73817new file mode 100644
73818index 0000000..be66033
73819--- /dev/null
73820+++ b/include/linux/grdefs.h
73821@@ -0,0 +1,140 @@
73822+#ifndef GRDEFS_H
73823+#define GRDEFS_H
73824+
73825+/* Begin grsecurity status declarations */
73826+
73827+enum {
73828+ GR_READY = 0x01,
73829+ GR_STATUS_INIT = 0x00 // disabled state
73830+};
73831+
73832+/* Begin ACL declarations */
73833+
73834+/* Role flags */
73835+
73836+enum {
73837+ GR_ROLE_USER = 0x0001,
73838+ GR_ROLE_GROUP = 0x0002,
73839+ GR_ROLE_DEFAULT = 0x0004,
73840+ GR_ROLE_SPECIAL = 0x0008,
73841+ GR_ROLE_AUTH = 0x0010,
73842+ GR_ROLE_NOPW = 0x0020,
73843+ GR_ROLE_GOD = 0x0040,
73844+ GR_ROLE_LEARN = 0x0080,
73845+ GR_ROLE_TPE = 0x0100,
73846+ GR_ROLE_DOMAIN = 0x0200,
73847+ GR_ROLE_PAM = 0x0400,
73848+ GR_ROLE_PERSIST = 0x0800
73849+};
73850+
73851+/* ACL Subject and Object mode flags */
73852+enum {
73853+ GR_DELETED = 0x80000000
73854+};
73855+
73856+/* ACL Object-only mode flags */
73857+enum {
73858+ GR_READ = 0x00000001,
73859+ GR_APPEND = 0x00000002,
73860+ GR_WRITE = 0x00000004,
73861+ GR_EXEC = 0x00000008,
73862+ GR_FIND = 0x00000010,
73863+ GR_INHERIT = 0x00000020,
73864+ GR_SETID = 0x00000040,
73865+ GR_CREATE = 0x00000080,
73866+ GR_DELETE = 0x00000100,
73867+ GR_LINK = 0x00000200,
73868+ GR_AUDIT_READ = 0x00000400,
73869+ GR_AUDIT_APPEND = 0x00000800,
73870+ GR_AUDIT_WRITE = 0x00001000,
73871+ GR_AUDIT_EXEC = 0x00002000,
73872+ GR_AUDIT_FIND = 0x00004000,
73873+ GR_AUDIT_INHERIT= 0x00008000,
73874+ GR_AUDIT_SETID = 0x00010000,
73875+ GR_AUDIT_CREATE = 0x00020000,
73876+ GR_AUDIT_DELETE = 0x00040000,
73877+ GR_AUDIT_LINK = 0x00080000,
73878+ GR_PTRACERD = 0x00100000,
73879+ GR_NOPTRACE = 0x00200000,
73880+ GR_SUPPRESS = 0x00400000,
73881+ GR_NOLEARN = 0x00800000,
73882+ GR_INIT_TRANSFER= 0x01000000
73883+};
73884+
73885+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
73886+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
73887+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
73888+
73889+/* ACL subject-only mode flags */
73890+enum {
73891+ GR_KILL = 0x00000001,
73892+ GR_VIEW = 0x00000002,
73893+ GR_PROTECTED = 0x00000004,
73894+ GR_LEARN = 0x00000008,
73895+ GR_OVERRIDE = 0x00000010,
73896+ /* just a placeholder, this mode is only used in userspace */
73897+ GR_DUMMY = 0x00000020,
73898+ GR_PROTSHM = 0x00000040,
73899+ GR_KILLPROC = 0x00000080,
73900+ GR_KILLIPPROC = 0x00000100,
73901+ /* just a placeholder, this mode is only used in userspace */
73902+ GR_NOTROJAN = 0x00000200,
73903+ GR_PROTPROCFD = 0x00000400,
73904+ GR_PROCACCT = 0x00000800,
73905+ GR_RELAXPTRACE = 0x00001000,
73906+ //GR_NESTED = 0x00002000,
73907+ GR_INHERITLEARN = 0x00004000,
73908+ GR_PROCFIND = 0x00008000,
73909+ GR_POVERRIDE = 0x00010000,
73910+ GR_KERNELAUTH = 0x00020000,
73911+ GR_ATSECURE = 0x00040000,
73912+ GR_SHMEXEC = 0x00080000
73913+};
73914+
73915+enum {
73916+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
73917+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
73918+ GR_PAX_ENABLE_MPROTECT = 0x0004,
73919+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
73920+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
73921+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
73922+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
73923+ GR_PAX_DISABLE_MPROTECT = 0x0400,
73924+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
73925+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
73926+};
73927+
73928+enum {
73929+ GR_ID_USER = 0x01,
73930+ GR_ID_GROUP = 0x02,
73931+};
73932+
73933+enum {
73934+ GR_ID_ALLOW = 0x01,
73935+ GR_ID_DENY = 0x02,
73936+};
73937+
73938+#define GR_CRASH_RES 31
73939+#define GR_UIDTABLE_MAX 500
73940+
73941+/* begin resource learning section */
73942+enum {
73943+ GR_RLIM_CPU_BUMP = 60,
73944+ GR_RLIM_FSIZE_BUMP = 50000,
73945+ GR_RLIM_DATA_BUMP = 10000,
73946+ GR_RLIM_STACK_BUMP = 1000,
73947+ GR_RLIM_CORE_BUMP = 10000,
73948+ GR_RLIM_RSS_BUMP = 500000,
73949+ GR_RLIM_NPROC_BUMP = 1,
73950+ GR_RLIM_NOFILE_BUMP = 5,
73951+ GR_RLIM_MEMLOCK_BUMP = 50000,
73952+ GR_RLIM_AS_BUMP = 500000,
73953+ GR_RLIM_LOCKS_BUMP = 2,
73954+ GR_RLIM_SIGPENDING_BUMP = 5,
73955+ GR_RLIM_MSGQUEUE_BUMP = 10000,
73956+ GR_RLIM_NICE_BUMP = 1,
73957+ GR_RLIM_RTPRIO_BUMP = 1,
73958+ GR_RLIM_RTTIME_BUMP = 1000000
73959+};
73960+
73961+#endif
73962diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
73963new file mode 100644
73964index 0000000..e337683
73965--- /dev/null
73966+++ b/include/linux/grinternal.h
73967@@ -0,0 +1,229 @@
73968+#ifndef __GRINTERNAL_H
73969+#define __GRINTERNAL_H
73970+
73971+#ifdef CONFIG_GRKERNSEC
73972+
73973+#include <linux/fs.h>
73974+#include <linux/mnt_namespace.h>
73975+#include <linux/nsproxy.h>
73976+#include <linux/gracl.h>
73977+#include <linux/grdefs.h>
73978+#include <linux/grmsg.h>
73979+
73980+void gr_add_learn_entry(const char *fmt, ...)
73981+ __attribute__ ((format (printf, 1, 2)));
73982+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
73983+ const struct vfsmount *mnt);
73984+__u32 gr_check_create(const struct dentry *new_dentry,
73985+ const struct dentry *parent,
73986+ const struct vfsmount *mnt, const __u32 mode);
73987+int gr_check_protected_task(const struct task_struct *task);
73988+__u32 to_gr_audit(const __u32 reqmode);
73989+int gr_set_acls(const int type);
73990+int gr_apply_subject_to_task(struct task_struct *task);
73991+int gr_acl_is_enabled(void);
73992+char gr_roletype_to_char(void);
73993+
73994+void gr_handle_alertkill(struct task_struct *task);
73995+char *gr_to_filename(const struct dentry *dentry,
73996+ const struct vfsmount *mnt);
73997+char *gr_to_filename1(const struct dentry *dentry,
73998+ const struct vfsmount *mnt);
73999+char *gr_to_filename2(const struct dentry *dentry,
74000+ const struct vfsmount *mnt);
74001+char *gr_to_filename3(const struct dentry *dentry,
74002+ const struct vfsmount *mnt);
74003+
74004+extern int grsec_enable_ptrace_readexec;
74005+extern int grsec_enable_harden_ptrace;
74006+extern int grsec_enable_link;
74007+extern int grsec_enable_fifo;
74008+extern int grsec_enable_execve;
74009+extern int grsec_enable_shm;
74010+extern int grsec_enable_execlog;
74011+extern int grsec_enable_signal;
74012+extern int grsec_enable_audit_ptrace;
74013+extern int grsec_enable_forkfail;
74014+extern int grsec_enable_time;
74015+extern int grsec_enable_rofs;
74016+extern int grsec_deny_new_usb;
74017+extern int grsec_enable_chroot_shmat;
74018+extern int grsec_enable_chroot_mount;
74019+extern int grsec_enable_chroot_double;
74020+extern int grsec_enable_chroot_pivot;
74021+extern int grsec_enable_chroot_chdir;
74022+extern int grsec_enable_chroot_chmod;
74023+extern int grsec_enable_chroot_mknod;
74024+extern int grsec_enable_chroot_fchdir;
74025+extern int grsec_enable_chroot_nice;
74026+extern int grsec_enable_chroot_execlog;
74027+extern int grsec_enable_chroot_caps;
74028+extern int grsec_enable_chroot_sysctl;
74029+extern int grsec_enable_chroot_unix;
74030+extern int grsec_enable_symlinkown;
74031+extern kgid_t grsec_symlinkown_gid;
74032+extern int grsec_enable_tpe;
74033+extern kgid_t grsec_tpe_gid;
74034+extern int grsec_enable_tpe_all;
74035+extern int grsec_enable_tpe_invert;
74036+extern int grsec_enable_socket_all;
74037+extern kgid_t grsec_socket_all_gid;
74038+extern int grsec_enable_socket_client;
74039+extern kgid_t grsec_socket_client_gid;
74040+extern int grsec_enable_socket_server;
74041+extern kgid_t grsec_socket_server_gid;
74042+extern kgid_t grsec_audit_gid;
74043+extern int grsec_enable_group;
74044+extern int grsec_enable_log_rwxmaps;
74045+extern int grsec_enable_mount;
74046+extern int grsec_enable_chdir;
74047+extern int grsec_resource_logging;
74048+extern int grsec_enable_blackhole;
74049+extern int grsec_lastack_retries;
74050+extern int grsec_enable_brute;
74051+extern int grsec_lock;
74052+
74053+extern spinlock_t grsec_alert_lock;
74054+extern unsigned long grsec_alert_wtime;
74055+extern unsigned long grsec_alert_fyet;
74056+
74057+extern spinlock_t grsec_audit_lock;
74058+
74059+extern rwlock_t grsec_exec_file_lock;
74060+
74061+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
74062+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
74063+ (tsk)->exec_file->f_path.mnt) : "/")
74064+
74065+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
74066+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
74067+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
74068+
74069+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
74070+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
74071+ (tsk)->exec_file->f_path.mnt) : "/")
74072+
74073+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
74074+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
74075+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
74076+
74077+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
74078+
74079+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
74080+
74081+static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
74082+{
74083+ if (file1 && file2) {
74084+ const struct inode *inode1 = file1->f_path.dentry->d_inode;
74085+ const struct inode *inode2 = file2->f_path.dentry->d_inode;
74086+ if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
74087+ return true;
74088+ }
74089+
74090+ return false;
74091+}
74092+
74093+#define GR_CHROOT_CAPS {{ \
74094+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
74095+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
74096+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
74097+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
74098+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
74099+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
74100+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
74101+
74102+#define security_learn(normal_msg,args...) \
74103+({ \
74104+ read_lock(&grsec_exec_file_lock); \
74105+ gr_add_learn_entry(normal_msg "\n", ## args); \
74106+ read_unlock(&grsec_exec_file_lock); \
74107+})
74108+
74109+enum {
74110+ GR_DO_AUDIT,
74111+ GR_DONT_AUDIT,
74112+ /* used for non-audit messages that we shouldn't kill the task on */
74113+ GR_DONT_AUDIT_GOOD
74114+};
74115+
74116+enum {
74117+ GR_TTYSNIFF,
74118+ GR_RBAC,
74119+ GR_RBAC_STR,
74120+ GR_STR_RBAC,
74121+ GR_RBAC_MODE2,
74122+ GR_RBAC_MODE3,
74123+ GR_FILENAME,
74124+ GR_SYSCTL_HIDDEN,
74125+ GR_NOARGS,
74126+ GR_ONE_INT,
74127+ GR_ONE_INT_TWO_STR,
74128+ GR_ONE_STR,
74129+ GR_STR_INT,
74130+ GR_TWO_STR_INT,
74131+ GR_TWO_INT,
74132+ GR_TWO_U64,
74133+ GR_THREE_INT,
74134+ GR_FIVE_INT_TWO_STR,
74135+ GR_TWO_STR,
74136+ GR_THREE_STR,
74137+ GR_FOUR_STR,
74138+ GR_STR_FILENAME,
74139+ GR_FILENAME_STR,
74140+ GR_FILENAME_TWO_INT,
74141+ GR_FILENAME_TWO_INT_STR,
74142+ GR_TEXTREL,
74143+ GR_PTRACE,
74144+ GR_RESOURCE,
74145+ GR_CAP,
74146+ GR_SIG,
74147+ GR_SIG2,
74148+ GR_CRASH1,
74149+ GR_CRASH2,
74150+ GR_PSACCT,
74151+ GR_RWXMAP,
74152+ GR_RWXMAPVMA
74153+};
74154+
74155+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
74156+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
74157+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
74158+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
74159+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
74160+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
74161+#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)
74162+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
74163+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
74164+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
74165+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
74166+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
74167+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
74168+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
74169+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
74170+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
74171+#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)
74172+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
74173+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
74174+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
74175+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
74176+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
74177+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
74178+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
74179+#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)
74180+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
74181+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
74182+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
74183+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
74184+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
74185+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
74186+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
74187+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
74188+#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)
74189+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
74190+#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
74191+
74192+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
74193+
74194+#endif
74195+
74196+#endif
74197diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
74198new file mode 100644
74199index 0000000..a4396b5
74200--- /dev/null
74201+++ b/include/linux/grmsg.h
74202@@ -0,0 +1,113 @@
74203+#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"
74204+#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"
74205+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
74206+#define GR_STOPMOD_MSG "denied modification of module state by "
74207+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
74208+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
74209+#define GR_IOPERM_MSG "denied use of ioperm() by "
74210+#define GR_IOPL_MSG "denied use of iopl() by "
74211+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
74212+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
74213+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
74214+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
74215+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
74216+#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"
74217+#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"
74218+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
74219+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
74220+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
74221+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
74222+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
74223+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
74224+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
74225+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
74226+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
74227+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
74228+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
74229+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
74230+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
74231+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
74232+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
74233+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
74234+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
74235+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
74236+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
74237+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
74238+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
74239+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
74240+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
74241+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
74242+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
74243+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
74244+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
74245+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
74246+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
74247+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
74248+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
74249+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
74250+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
74251+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
74252+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
74253+#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"
74254+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
74255+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
74256+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
74257+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
74258+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
74259+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
74260+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
74261+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
74262+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
74263+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
74264+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
74265+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
74266+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
74267+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
74268+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
74269+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
74270+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
74271+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
74272+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
74273+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
74274+#define GR_FAILFORK_MSG "failed fork with errno %s by "
74275+#define GR_NICE_CHROOT_MSG "denied priority change by "
74276+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
74277+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
74278+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
74279+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
74280+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
74281+#define GR_TIME_MSG "time set by "
74282+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
74283+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
74284+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
74285+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
74286+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
74287+#define GR_BIND_MSG "denied bind() by "
74288+#define GR_CONNECT_MSG "denied connect() by "
74289+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
74290+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
74291+#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"
74292+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
74293+#define GR_CAP_ACL_MSG "use of %s denied for "
74294+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
74295+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
74296+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
74297+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
74298+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
74299+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
74300+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
74301+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
74302+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
74303+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
74304+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
74305+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
74306+#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
74307+#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
74308+#define GR_VM86_MSG "denied use of vm86 by "
74309+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
74310+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
74311+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
74312+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
74313+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
74314+#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 "
74315+#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 "
74316diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
74317new file mode 100644
74318index 0000000..d6f5a21
74319--- /dev/null
74320+++ b/include/linux/grsecurity.h
74321@@ -0,0 +1,244 @@
74322+#ifndef GR_SECURITY_H
74323+#define GR_SECURITY_H
74324+#include <linux/fs.h>
74325+#include <linux/fs_struct.h>
74326+#include <linux/binfmts.h>
74327+#include <linux/gracl.h>
74328+
74329+/* notify of brain-dead configs */
74330+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
74331+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
74332+#endif
74333+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
74334+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
74335+#endif
74336+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
74337+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
74338+#endif
74339+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
74340+#error "CONFIG_PAX enabled, but no PaX options are enabled."
74341+#endif
74342+
74343+int gr_handle_new_usb(void);
74344+
74345+void gr_handle_brute_attach(unsigned long mm_flags);
74346+void gr_handle_brute_check(void);
74347+void gr_handle_kernel_exploit(void);
74348+
74349+char gr_roletype_to_char(void);
74350+
74351+int gr_acl_enable_at_secure(void);
74352+
74353+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
74354+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
74355+
74356+void gr_del_task_from_ip_table(struct task_struct *p);
74357+
74358+int gr_pid_is_chrooted(struct task_struct *p);
74359+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
74360+int gr_handle_chroot_nice(void);
74361+int gr_handle_chroot_sysctl(const int op);
74362+int gr_handle_chroot_setpriority(struct task_struct *p,
74363+ const int niceval);
74364+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
74365+int gr_handle_chroot_chroot(const struct dentry *dentry,
74366+ const struct vfsmount *mnt);
74367+void gr_handle_chroot_chdir(const struct path *path);
74368+int gr_handle_chroot_chmod(const struct dentry *dentry,
74369+ const struct vfsmount *mnt, const int mode);
74370+int gr_handle_chroot_mknod(const struct dentry *dentry,
74371+ const struct vfsmount *mnt, const int mode);
74372+int gr_handle_chroot_mount(const struct dentry *dentry,
74373+ const struct vfsmount *mnt,
74374+ const char *dev_name);
74375+int gr_handle_chroot_pivot(void);
74376+int gr_handle_chroot_unix(const pid_t pid);
74377+
74378+int gr_handle_rawio(const struct inode *inode);
74379+
74380+void gr_handle_ioperm(void);
74381+void gr_handle_iopl(void);
74382+
74383+umode_t gr_acl_umask(void);
74384+
74385+int gr_tpe_allow(const struct file *file);
74386+
74387+void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
74388+void gr_clear_chroot_entries(struct task_struct *task);
74389+
74390+void gr_log_forkfail(const int retval);
74391+void gr_log_timechange(void);
74392+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
74393+void gr_log_chdir(const struct dentry *dentry,
74394+ const struct vfsmount *mnt);
74395+void gr_log_chroot_exec(const struct dentry *dentry,
74396+ const struct vfsmount *mnt);
74397+void gr_log_remount(const char *devname, const int retval);
74398+void gr_log_unmount(const char *devname, const int retval);
74399+void gr_log_mount(const char *from, const char *to, const int retval);
74400+void gr_log_textrel(struct vm_area_struct *vma);
74401+void gr_log_ptgnustack(struct file *file);
74402+void gr_log_rwxmmap(struct file *file);
74403+void gr_log_rwxmprotect(struct vm_area_struct *vma);
74404+
74405+int gr_handle_follow_link(const struct inode *parent,
74406+ const struct inode *inode,
74407+ const struct dentry *dentry,
74408+ const struct vfsmount *mnt);
74409+int gr_handle_fifo(const struct dentry *dentry,
74410+ const struct vfsmount *mnt,
74411+ const struct dentry *dir, const int flag,
74412+ const int acc_mode);
74413+int gr_handle_hardlink(const struct dentry *dentry,
74414+ const struct vfsmount *mnt,
74415+ struct inode *inode,
74416+ const int mode, const struct filename *to);
74417+
74418+int gr_is_capable(const int cap);
74419+int gr_is_capable_nolog(const int cap);
74420+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
74421+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
74422+
74423+void gr_copy_label(struct task_struct *tsk);
74424+void gr_handle_crash(struct task_struct *task, const int sig);
74425+int gr_handle_signal(const struct task_struct *p, const int sig);
74426+int gr_check_crash_uid(const kuid_t uid);
74427+int gr_check_protected_task(const struct task_struct *task);
74428+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
74429+int gr_acl_handle_mmap(const struct file *file,
74430+ const unsigned long prot);
74431+int gr_acl_handle_mprotect(const struct file *file,
74432+ const unsigned long prot);
74433+int gr_check_hidden_task(const struct task_struct *tsk);
74434+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
74435+ const struct vfsmount *mnt);
74436+__u32 gr_acl_handle_utime(const struct dentry *dentry,
74437+ const struct vfsmount *mnt);
74438+__u32 gr_acl_handle_access(const struct dentry *dentry,
74439+ const struct vfsmount *mnt, const int fmode);
74440+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
74441+ const struct vfsmount *mnt, umode_t *mode);
74442+__u32 gr_acl_handle_chown(const struct dentry *dentry,
74443+ const struct vfsmount *mnt);
74444+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
74445+ const struct vfsmount *mnt);
74446+int gr_handle_ptrace(struct task_struct *task, const long request);
74447+int gr_handle_proc_ptrace(struct task_struct *task);
74448+__u32 gr_acl_handle_execve(const struct dentry *dentry,
74449+ const struct vfsmount *mnt);
74450+int gr_check_crash_exec(const struct file *filp);
74451+int gr_acl_is_enabled(void);
74452+void gr_set_kernel_label(struct task_struct *task);
74453+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
74454+ const kgid_t gid);
74455+int gr_set_proc_label(const struct dentry *dentry,
74456+ const struct vfsmount *mnt,
74457+ const int unsafe_flags);
74458+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
74459+ const struct vfsmount *mnt);
74460+__u32 gr_acl_handle_open(const struct dentry *dentry,
74461+ const struct vfsmount *mnt, int acc_mode);
74462+__u32 gr_acl_handle_creat(const struct dentry *dentry,
74463+ const struct dentry *p_dentry,
74464+ const struct vfsmount *p_mnt,
74465+ int open_flags, int acc_mode, const int imode);
74466+void gr_handle_create(const struct dentry *dentry,
74467+ const struct vfsmount *mnt);
74468+void gr_handle_proc_create(const struct dentry *dentry,
74469+ const struct inode *inode);
74470+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
74471+ const struct dentry *parent_dentry,
74472+ const struct vfsmount *parent_mnt,
74473+ const int mode);
74474+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
74475+ const struct dentry *parent_dentry,
74476+ const struct vfsmount *parent_mnt);
74477+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
74478+ const struct vfsmount *mnt);
74479+void gr_handle_delete(const ino_t ino, const dev_t dev);
74480+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
74481+ const struct vfsmount *mnt);
74482+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
74483+ const struct dentry *parent_dentry,
74484+ const struct vfsmount *parent_mnt,
74485+ const struct filename *from);
74486+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
74487+ const struct dentry *parent_dentry,
74488+ const struct vfsmount *parent_mnt,
74489+ const struct dentry *old_dentry,
74490+ const struct vfsmount *old_mnt, const struct filename *to);
74491+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
74492+int gr_acl_handle_rename(struct dentry *new_dentry,
74493+ struct dentry *parent_dentry,
74494+ const struct vfsmount *parent_mnt,
74495+ struct dentry *old_dentry,
74496+ struct inode *old_parent_inode,
74497+ struct vfsmount *old_mnt, const struct filename *newname);
74498+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
74499+ struct dentry *old_dentry,
74500+ struct dentry *new_dentry,
74501+ struct vfsmount *mnt, const __u8 replace);
74502+__u32 gr_check_link(const struct dentry *new_dentry,
74503+ const struct dentry *parent_dentry,
74504+ const struct vfsmount *parent_mnt,
74505+ const struct dentry *old_dentry,
74506+ const struct vfsmount *old_mnt);
74507+int gr_acl_handle_filldir(const struct file *file, const char *name,
74508+ const unsigned int namelen, const ino_t ino);
74509+
74510+__u32 gr_acl_handle_unix(const struct dentry *dentry,
74511+ const struct vfsmount *mnt);
74512+void gr_acl_handle_exit(void);
74513+void gr_acl_handle_psacct(struct task_struct *task, const long code);
74514+int gr_acl_handle_procpidmem(const struct task_struct *task);
74515+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
74516+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
74517+void gr_audit_ptrace(struct task_struct *task);
74518+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
74519+void gr_put_exec_file(struct task_struct *task);
74520+
74521+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
74522+
74523+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
74524+extern void gr_learn_resource(const struct task_struct *task, const int res,
74525+ const unsigned long wanted, const int gt);
74526+#else
74527+static inline void gr_learn_resource(const struct task_struct *task, const int res,
74528+ const unsigned long wanted, const int gt)
74529+{
74530+}
74531+#endif
74532+
74533+#ifdef CONFIG_GRKERNSEC_RESLOG
74534+extern void gr_log_resource(const struct task_struct *task, const int res,
74535+ const unsigned long wanted, const int gt);
74536+#else
74537+static inline void gr_log_resource(const struct task_struct *task, const int res,
74538+ const unsigned long wanted, const int gt)
74539+{
74540+}
74541+#endif
74542+
74543+#ifdef CONFIG_GRKERNSEC
74544+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
74545+void gr_handle_vm86(void);
74546+void gr_handle_mem_readwrite(u64 from, u64 to);
74547+
74548+void gr_log_badprocpid(const char *entry);
74549+
74550+extern int grsec_enable_dmesg;
74551+extern int grsec_disable_privio;
74552+
74553+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
74554+extern kgid_t grsec_proc_gid;
74555+#endif
74556+
74557+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
74558+extern int grsec_enable_chroot_findtask;
74559+#endif
74560+#ifdef CONFIG_GRKERNSEC_SETXID
74561+extern int grsec_enable_setxid;
74562+#endif
74563+#endif
74564+
74565+#endif
74566diff --git a/include/linux/grsock.h b/include/linux/grsock.h
74567new file mode 100644
74568index 0000000..e7ffaaf
74569--- /dev/null
74570+++ b/include/linux/grsock.h
74571@@ -0,0 +1,19 @@
74572+#ifndef __GRSOCK_H
74573+#define __GRSOCK_H
74574+
74575+extern void gr_attach_curr_ip(const struct sock *sk);
74576+extern int gr_handle_sock_all(const int family, const int type,
74577+ const int protocol);
74578+extern int gr_handle_sock_server(const struct sockaddr *sck);
74579+extern int gr_handle_sock_server_other(const struct sock *sck);
74580+extern int gr_handle_sock_client(const struct sockaddr *sck);
74581+extern int gr_search_connect(struct socket * sock,
74582+ struct sockaddr_in * addr);
74583+extern int gr_search_bind(struct socket * sock,
74584+ struct sockaddr_in * addr);
74585+extern int gr_search_listen(struct socket * sock);
74586+extern int gr_search_accept(struct socket * sock);
74587+extern int gr_search_socket(const int domain, const int type,
74588+ const int protocol);
74589+
74590+#endif
74591diff --git a/include/linux/hid.h b/include/linux/hid.h
74592index 0c48991..76e41d8 100644
74593--- a/include/linux/hid.h
74594+++ b/include/linux/hid.h
74595@@ -393,10 +393,12 @@ struct hid_report {
74596 struct hid_device *device; /* associated device */
74597 };
74598
74599+#define HID_MAX_IDS 256
74600+
74601 struct hid_report_enum {
74602 unsigned numbered;
74603 struct list_head report_list;
74604- struct hid_report *report_id_hash[256];
74605+ struct hid_report *report_id_hash[HID_MAX_IDS];
74606 };
74607
74608 #define HID_REPORT_TYPES 3
74609@@ -747,6 +749,10 @@ void hid_output_report(struct hid_report *report, __u8 *data);
74610 struct hid_device *hid_allocate_device(void);
74611 struct hid_report *hid_register_report(struct hid_device *device, unsigned type, unsigned id);
74612 int hid_parse_report(struct hid_device *hid, __u8 *start, unsigned size);
74613+struct hid_report *hid_validate_report(struct hid_device *hid,
74614+ unsigned int type, unsigned int id,
74615+ unsigned int fields,
74616+ unsigned int report_counts);
74617 int hid_open_report(struct hid_device *device);
74618 int hid_check_keys_pressed(struct hid_device *hid);
74619 int hid_connect(struct hid_device *hid, unsigned int connect_mask);
74620diff --git a/include/linux/highmem.h b/include/linux/highmem.h
74621index 7fb31da..08b5114 100644
74622--- a/include/linux/highmem.h
74623+++ b/include/linux/highmem.h
74624@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
74625 kunmap_atomic(kaddr);
74626 }
74627
74628+static inline void sanitize_highpage(struct page *page)
74629+{
74630+ void *kaddr;
74631+ unsigned long flags;
74632+
74633+ local_irq_save(flags);
74634+ kaddr = kmap_atomic(page);
74635+ clear_page(kaddr);
74636+ kunmap_atomic(kaddr);
74637+ local_irq_restore(flags);
74638+}
74639+
74640 static inline void zero_user_segments(struct page *page,
74641 unsigned start1, unsigned end1,
74642 unsigned start2, unsigned end2)
74643diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
74644index 1c7b89a..7f52502 100644
74645--- a/include/linux/hwmon-sysfs.h
74646+++ b/include/linux/hwmon-sysfs.h
74647@@ -25,7 +25,8 @@
74648 struct sensor_device_attribute{
74649 struct device_attribute dev_attr;
74650 int index;
74651-};
74652+} __do_const;
74653+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
74654 #define to_sensor_dev_attr(_dev_attr) \
74655 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
74656
74657@@ -41,7 +42,7 @@ struct sensor_device_attribute_2 {
74658 struct device_attribute dev_attr;
74659 u8 index;
74660 u8 nr;
74661-};
74662+} __do_const;
74663 #define to_sensor_dev_attr_2(_dev_attr) \
74664 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
74665
74666diff --git a/include/linux/i2c.h b/include/linux/i2c.h
74667index e988fa9..ff9f17e 100644
74668--- a/include/linux/i2c.h
74669+++ b/include/linux/i2c.h
74670@@ -366,6 +366,7 @@ struct i2c_algorithm {
74671 /* To determine what the adapter supports */
74672 u32 (*functionality) (struct i2c_adapter *);
74673 };
74674+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
74675
74676 /**
74677 * struct i2c_bus_recovery_info - I2C bus recovery information
74678diff --git a/include/linux/i2o.h b/include/linux/i2o.h
74679index d23c3c2..eb63c81 100644
74680--- a/include/linux/i2o.h
74681+++ b/include/linux/i2o.h
74682@@ -565,7 +565,7 @@ struct i2o_controller {
74683 struct i2o_device *exec; /* Executive */
74684 #if BITS_PER_LONG == 64
74685 spinlock_t context_list_lock; /* lock for context_list */
74686- atomic_t context_list_counter; /* needed for unique contexts */
74687+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
74688 struct list_head context_list; /* list of context id's
74689 and pointers */
74690 #endif
74691diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
74692index aff7ad8..3942bbd 100644
74693--- a/include/linux/if_pppox.h
74694+++ b/include/linux/if_pppox.h
74695@@ -76,7 +76,7 @@ struct pppox_proto {
74696 int (*ioctl)(struct socket *sock, unsigned int cmd,
74697 unsigned long arg);
74698 struct module *owner;
74699-};
74700+} __do_const;
74701
74702 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
74703 extern void unregister_pppox_proto(int proto_num);
74704diff --git a/include/linux/init.h b/include/linux/init.h
74705index e73f2b7..cc996e0 100644
74706--- a/include/linux/init.h
74707+++ b/include/linux/init.h
74708@@ -39,9 +39,17 @@
74709 * Also note, that this data cannot be "const".
74710 */
74711
74712+#define add_init_latent_entropy __latent_entropy
74713+
74714+#ifdef CONFIG_MEMORY_HOTPLUG
74715+#define add_meminit_latent_entropy
74716+#else
74717+#define add_meminit_latent_entropy __latent_entropy
74718+#endif
74719+
74720 /* These are for everybody (although not all archs will actually
74721 discard it in modules) */
74722-#define __init __section(.init.text) __cold notrace
74723+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
74724 #define __initdata __section(.init.data)
74725 #define __initconst __constsection(.init.rodata)
74726 #define __exitdata __section(.exit.data)
74727@@ -102,7 +110,7 @@
74728 #define __cpuexitconst
74729
74730 /* Used for MEMORY_HOTPLUG */
74731-#define __meminit __section(.meminit.text) __cold notrace
74732+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
74733 #define __meminitdata __section(.meminit.data)
74734 #define __meminitconst __constsection(.meminit.rodata)
74735 #define __memexit __section(.memexit.text) __exitused __cold notrace
74736diff --git a/include/linux/init_task.h b/include/linux/init_task.h
74737index 5cd0f09..c9f67cc 100644
74738--- a/include/linux/init_task.h
74739+++ b/include/linux/init_task.h
74740@@ -154,6 +154,12 @@ extern struct task_group root_task_group;
74741
74742 #define INIT_TASK_COMM "swapper"
74743
74744+#ifdef CONFIG_X86
74745+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
74746+#else
74747+#define INIT_TASK_THREAD_INFO
74748+#endif
74749+
74750 /*
74751 * INIT_TASK is used to set up the first task table, touch at
74752 * your own risk!. Base=0, limit=0x1fffff (=2MB)
74753@@ -193,6 +199,7 @@ extern struct task_group root_task_group;
74754 RCU_POINTER_INITIALIZER(cred, &init_cred), \
74755 .comm = INIT_TASK_COMM, \
74756 .thread = INIT_THREAD, \
74757+ INIT_TASK_THREAD_INFO \
74758 .fs = &init_fs, \
74759 .files = &init_files, \
74760 .signal = &init_signals, \
74761diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
74762index 5fa5afe..ac55b25 100644
74763--- a/include/linux/interrupt.h
74764+++ b/include/linux/interrupt.h
74765@@ -430,7 +430,7 @@ enum
74766 /* map softirq index to softirq name. update 'softirq_to_name' in
74767 * kernel/softirq.c when adding a new softirq.
74768 */
74769-extern char *softirq_to_name[NR_SOFTIRQS];
74770+extern const char * const softirq_to_name[NR_SOFTIRQS];
74771
74772 /* softirq mask and active fields moved to irq_cpustat_t in
74773 * asm/hardirq.h to get better cache usage. KAO
74774@@ -438,12 +438,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
74775
74776 struct softirq_action
74777 {
74778- void (*action)(struct softirq_action *);
74779-};
74780+ void (*action)(void);
74781+} __no_const;
74782
74783 asmlinkage void do_softirq(void);
74784 asmlinkage void __do_softirq(void);
74785-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
74786+extern void open_softirq(int nr, void (*action)(void));
74787 extern void softirq_init(void);
74788 extern void __raise_softirq_irqoff(unsigned int nr);
74789
74790diff --git a/include/linux/iommu.h b/include/linux/iommu.h
74791index 3aeb730..2177f39 100644
74792--- a/include/linux/iommu.h
74793+++ b/include/linux/iommu.h
74794@@ -113,7 +113,7 @@ struct iommu_ops {
74795 u32 (*domain_get_windows)(struct iommu_domain *domain);
74796
74797 unsigned long pgsize_bitmap;
74798-};
74799+} __do_const;
74800
74801 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
74802 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
74803diff --git a/include/linux/ioport.h b/include/linux/ioport.h
74804index 89b7c24..382af74 100644
74805--- a/include/linux/ioport.h
74806+++ b/include/linux/ioport.h
74807@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
74808 int adjust_resource(struct resource *res, resource_size_t start,
74809 resource_size_t size);
74810 resource_size_t resource_alignment(struct resource *res);
74811-static inline resource_size_t resource_size(const struct resource *res)
74812+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
74813 {
74814 return res->end - res->start + 1;
74815 }
74816diff --git a/include/linux/irq.h b/include/linux/irq.h
74817index f04d3ba..bcf2cfb 100644
74818--- a/include/linux/irq.h
74819+++ b/include/linux/irq.h
74820@@ -333,7 +333,8 @@ struct irq_chip {
74821 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
74822
74823 unsigned long flags;
74824-};
74825+} __do_const;
74826+typedef struct irq_chip __no_const irq_chip_no_const;
74827
74828 /*
74829 * irq_chip specific flags
74830diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
74831index 3e203eb..3fe68d0 100644
74832--- a/include/linux/irqchip/arm-gic.h
74833+++ b/include/linux/irqchip/arm-gic.h
74834@@ -59,9 +59,11 @@
74835
74836 #ifndef __ASSEMBLY__
74837
74838+#include <linux/irq.h>
74839+
74840 struct device_node;
74841
74842-extern struct irq_chip gic_arch_extn;
74843+extern irq_chip_no_const gic_arch_extn;
74844
74845 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
74846 u32 offset, struct device_node *);
74847diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
74848index 6883e19..e854fcb 100644
74849--- a/include/linux/kallsyms.h
74850+++ b/include/linux/kallsyms.h
74851@@ -15,7 +15,8 @@
74852
74853 struct module;
74854
74855-#ifdef CONFIG_KALLSYMS
74856+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
74857+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
74858 /* Lookup the address for a symbol. Returns 0 if not found. */
74859 unsigned long kallsyms_lookup_name(const char *name);
74860
74861@@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
74862 /* Stupid that this does nothing, but I didn't create this mess. */
74863 #define __print_symbol(fmt, addr)
74864 #endif /*CONFIG_KALLSYMS*/
74865+#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
74866+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
74867+extern unsigned long kallsyms_lookup_name(const char *name);
74868+extern void __print_symbol(const char *fmt, unsigned long address);
74869+extern int sprint_backtrace(char *buffer, unsigned long address);
74870+extern int sprint_symbol(char *buffer, unsigned long address);
74871+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
74872+const char *kallsyms_lookup(unsigned long addr,
74873+ unsigned long *symbolsize,
74874+ unsigned long *offset,
74875+ char **modname, char *namebuf);
74876+extern int kallsyms_lookup_size_offset(unsigned long addr,
74877+ unsigned long *symbolsize,
74878+ unsigned long *offset);
74879+#endif
74880
74881 /* This macro allows us to keep printk typechecking */
74882 static __printf(1, 2)
74883diff --git a/include/linux/key-type.h b/include/linux/key-type.h
74884index 518a53a..5e28358 100644
74885--- a/include/linux/key-type.h
74886+++ b/include/linux/key-type.h
74887@@ -125,7 +125,7 @@ struct key_type {
74888 /* internal fields */
74889 struct list_head link; /* link in types list */
74890 struct lock_class_key lock_class; /* key->sem lock class */
74891-};
74892+} __do_const;
74893
74894 extern struct key_type key_type_keyring;
74895
74896diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
74897index c6e091b..a940adf 100644
74898--- a/include/linux/kgdb.h
74899+++ b/include/linux/kgdb.h
74900@@ -52,7 +52,7 @@ extern int kgdb_connected;
74901 extern int kgdb_io_module_registered;
74902
74903 extern atomic_t kgdb_setting_breakpoint;
74904-extern atomic_t kgdb_cpu_doing_single_step;
74905+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
74906
74907 extern struct task_struct *kgdb_usethread;
74908 extern struct task_struct *kgdb_contthread;
74909@@ -254,7 +254,7 @@ struct kgdb_arch {
74910 void (*correct_hw_break)(void);
74911
74912 void (*enable_nmi)(bool on);
74913-};
74914+} __do_const;
74915
74916 /**
74917 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
74918@@ -279,7 +279,7 @@ struct kgdb_io {
74919 void (*pre_exception) (void);
74920 void (*post_exception) (void);
74921 int is_console;
74922-};
74923+} __do_const;
74924
74925 extern struct kgdb_arch arch_kgdb_ops;
74926
74927diff --git a/include/linux/kmod.h b/include/linux/kmod.h
74928index 0555cc6..b16a7a4 100644
74929--- a/include/linux/kmod.h
74930+++ b/include/linux/kmod.h
74931@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
74932 * usually useless though. */
74933 extern __printf(2, 3)
74934 int __request_module(bool wait, const char *name, ...);
74935+extern __printf(3, 4)
74936+int ___request_module(bool wait, char *param_name, const char *name, ...);
74937 #define request_module(mod...) __request_module(true, mod)
74938 #define request_module_nowait(mod...) __request_module(false, mod)
74939 #define try_then_request_module(x, mod...) \
74940diff --git a/include/linux/kobject.h b/include/linux/kobject.h
74941index 939b112..ed6ed51 100644
74942--- a/include/linux/kobject.h
74943+++ b/include/linux/kobject.h
74944@@ -111,7 +111,7 @@ struct kobj_type {
74945 struct attribute **default_attrs;
74946 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
74947 const void *(*namespace)(struct kobject *kobj);
74948-};
74949+} __do_const;
74950
74951 struct kobj_uevent_env {
74952 char *envp[UEVENT_NUM_ENVP];
74953@@ -134,6 +134,7 @@ struct kobj_attribute {
74954 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
74955 const char *buf, size_t count);
74956 };
74957+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
74958
74959 extern const struct sysfs_ops kobj_sysfs_ops;
74960
74961diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
74962index f66b065..c2c29b4 100644
74963--- a/include/linux/kobject_ns.h
74964+++ b/include/linux/kobject_ns.h
74965@@ -43,7 +43,7 @@ struct kobj_ns_type_operations {
74966 const void *(*netlink_ns)(struct sock *sk);
74967 const void *(*initial_ns)(void);
74968 void (*drop_ns)(void *);
74969-};
74970+} __do_const;
74971
74972 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
74973 int kobj_ns_type_registered(enum kobj_ns_type type);
74974diff --git a/include/linux/kref.h b/include/linux/kref.h
74975index 484604d..0f6c5b6 100644
74976--- a/include/linux/kref.h
74977+++ b/include/linux/kref.h
74978@@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
74979 static inline int kref_sub(struct kref *kref, unsigned int count,
74980 void (*release)(struct kref *kref))
74981 {
74982- WARN_ON(release == NULL);
74983+ BUG_ON(release == NULL);
74984
74985 if (atomic_sub_and_test((int) count, &kref->refcount)) {
74986 release(kref);
74987diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
74988index a63d83e..77fd685 100644
74989--- a/include/linux/kvm_host.h
74990+++ b/include/linux/kvm_host.h
74991@@ -446,7 +446,7 @@ static inline void kvm_irqfd_exit(void)
74992 {
74993 }
74994 #endif
74995-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
74996+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
74997 struct module *module);
74998 void kvm_exit(void);
74999
75000@@ -618,7 +618,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
75001 struct kvm_guest_debug *dbg);
75002 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
75003
75004-int kvm_arch_init(void *opaque);
75005+int kvm_arch_init(const void *opaque);
75006 void kvm_arch_exit(void);
75007
75008 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
75009diff --git a/include/linux/libata.h b/include/linux/libata.h
75010index 4ea55bb..dcd2601 100644
75011--- a/include/linux/libata.h
75012+++ b/include/linux/libata.h
75013@@ -924,7 +924,7 @@ struct ata_port_operations {
75014 * fields must be pointers.
75015 */
75016 const struct ata_port_operations *inherits;
75017-};
75018+} __do_const;
75019
75020 struct ata_port_info {
75021 unsigned long flags;
75022diff --git a/include/linux/linkage.h b/include/linux/linkage.h
75023index d3e8ad2..a949f68 100644
75024--- a/include/linux/linkage.h
75025+++ b/include/linux/linkage.h
75026@@ -31,6 +31,7 @@
75027 #endif
75028
75029 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
75030+#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
75031 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
75032
75033 /*
75034diff --git a/include/linux/list.h b/include/linux/list.h
75035index f4d8a2f..38e6e46 100644
75036--- a/include/linux/list.h
75037+++ b/include/linux/list.h
75038@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
75039 extern void list_del(struct list_head *entry);
75040 #endif
75041
75042+extern void __pax_list_add(struct list_head *new,
75043+ struct list_head *prev,
75044+ struct list_head *next);
75045+static inline void pax_list_add(struct list_head *new, struct list_head *head)
75046+{
75047+ __pax_list_add(new, head, head->next);
75048+}
75049+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
75050+{
75051+ __pax_list_add(new, head->prev, head);
75052+}
75053+extern void pax_list_del(struct list_head *entry);
75054+
75055 /**
75056 * list_replace - replace old entry by new one
75057 * @old : the element to be replaced
75058@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
75059 INIT_LIST_HEAD(entry);
75060 }
75061
75062+extern void pax_list_del_init(struct list_head *entry);
75063+
75064 /**
75065 * list_move - delete from one list and add as another's head
75066 * @list: the entry to move
75067diff --git a/include/linux/math64.h b/include/linux/math64.h
75068index 2913b86..8dcbb1e 100644
75069--- a/include/linux/math64.h
75070+++ b/include/linux/math64.h
75071@@ -15,7 +15,7 @@
75072 * This is commonly provided by 32bit archs to provide an optimized 64bit
75073 * divide.
75074 */
75075-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
75076+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
75077 {
75078 *remainder = dividend % divisor;
75079 return dividend / divisor;
75080@@ -33,7 +33,7 @@ static inline s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
75081 /**
75082 * div64_u64 - unsigned 64bit divide with 64bit divisor
75083 */
75084-static inline u64 div64_u64(u64 dividend, u64 divisor)
75085+static inline u64 __intentional_overflow(0) div64_u64(u64 dividend, u64 divisor)
75086 {
75087 return dividend / divisor;
75088 }
75089@@ -52,7 +52,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
75090 #define div64_ul(x, y) div_u64((x), (y))
75091
75092 #ifndef div_u64_rem
75093-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
75094+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
75095 {
75096 *remainder = do_div(dividend, divisor);
75097 return dividend;
75098@@ -81,7 +81,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
75099 * divide.
75100 */
75101 #ifndef div_u64
75102-static inline u64 div_u64(u64 dividend, u32 divisor)
75103+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
75104 {
75105 u32 remainder;
75106 return div_u64_rem(dividend, divisor, &remainder);
75107diff --git a/include/linux/mm.h b/include/linux/mm.h
75108index f022460..6ecf4f9 100644
75109--- a/include/linux/mm.h
75110+++ b/include/linux/mm.h
75111@@ -113,6 +113,11 @@ extern unsigned int kobjsize(const void *objp);
75112 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
75113 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
75114 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
75115+
75116+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
75117+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
75118+#endif
75119+
75120 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
75121
75122 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
75123@@ -208,8 +213,8 @@ struct vm_operations_struct {
75124 /* called by access_process_vm when get_user_pages() fails, typically
75125 * for use by special VMAs that can switch between memory and hardware
75126 */
75127- int (*access)(struct vm_area_struct *vma, unsigned long addr,
75128- void *buf, int len, int write);
75129+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
75130+ void *buf, size_t len, int write);
75131 #ifdef CONFIG_NUMA
75132 /*
75133 * set_policy() op must add a reference to any non-NULL @new mempolicy
75134@@ -239,6 +244,7 @@ struct vm_operations_struct {
75135 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
75136 unsigned long size, pgoff_t pgoff);
75137 };
75138+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
75139
75140 struct mmu_gather;
75141 struct inode;
75142@@ -983,8 +989,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
75143 unsigned long *pfn);
75144 int follow_phys(struct vm_area_struct *vma, unsigned long address,
75145 unsigned int flags, unsigned long *prot, resource_size_t *phys);
75146-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
75147- void *buf, int len, int write);
75148+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
75149+ void *buf, size_t len, int write);
75150
75151 static inline void unmap_shared_mapping_range(struct address_space *mapping,
75152 loff_t const holebegin, loff_t const holelen)
75153@@ -1023,9 +1029,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
75154 }
75155 #endif
75156
75157-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
75158-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
75159- void *buf, int len, int write);
75160+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
75161+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
75162+ void *buf, size_t len, int write);
75163
75164 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
75165 unsigned long start, unsigned long nr_pages,
75166@@ -1057,34 +1063,6 @@ int set_page_dirty(struct page *page);
75167 int set_page_dirty_lock(struct page *page);
75168 int clear_page_dirty_for_io(struct page *page);
75169
75170-/* Is the vma a continuation of the stack vma above it? */
75171-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
75172-{
75173- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
75174-}
75175-
75176-static inline int stack_guard_page_start(struct vm_area_struct *vma,
75177- unsigned long addr)
75178-{
75179- return (vma->vm_flags & VM_GROWSDOWN) &&
75180- (vma->vm_start == addr) &&
75181- !vma_growsdown(vma->vm_prev, addr);
75182-}
75183-
75184-/* Is the vma a continuation of the stack vma below it? */
75185-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
75186-{
75187- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
75188-}
75189-
75190-static inline int stack_guard_page_end(struct vm_area_struct *vma,
75191- unsigned long addr)
75192-{
75193- return (vma->vm_flags & VM_GROWSUP) &&
75194- (vma->vm_end == addr) &&
75195- !vma_growsup(vma->vm_next, addr);
75196-}
75197-
75198 extern pid_t
75199 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
75200
75201@@ -1184,6 +1162,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
75202 }
75203 #endif
75204
75205+#ifdef CONFIG_MMU
75206+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
75207+#else
75208+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
75209+{
75210+ return __pgprot(0);
75211+}
75212+#endif
75213+
75214 int vma_wants_writenotify(struct vm_area_struct *vma);
75215
75216 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
75217@@ -1202,8 +1189,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
75218 {
75219 return 0;
75220 }
75221+
75222+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
75223+ unsigned long address)
75224+{
75225+ return 0;
75226+}
75227 #else
75228 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
75229+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
75230 #endif
75231
75232 #ifdef __PAGETABLE_PMD_FOLDED
75233@@ -1212,8 +1206,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
75234 {
75235 return 0;
75236 }
75237+
75238+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
75239+ unsigned long address)
75240+{
75241+ return 0;
75242+}
75243 #else
75244 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
75245+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
75246 #endif
75247
75248 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
75249@@ -1231,11 +1232,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
75250 NULL: pud_offset(pgd, address);
75251 }
75252
75253+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
75254+{
75255+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
75256+ NULL: pud_offset(pgd, address);
75257+}
75258+
75259 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
75260 {
75261 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
75262 NULL: pmd_offset(pud, address);
75263 }
75264+
75265+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
75266+{
75267+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
75268+ NULL: pmd_offset(pud, address);
75269+}
75270 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
75271
75272 #if USE_SPLIT_PTLOCKS
75273@@ -1531,6 +1544,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
75274 unsigned long len, unsigned long prot, unsigned long flags,
75275 unsigned long pgoff, unsigned long *populate);
75276 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
75277+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
75278
75279 #ifdef CONFIG_MMU
75280 extern int __mm_populate(unsigned long addr, unsigned long len,
75281@@ -1559,10 +1573,11 @@ struct vm_unmapped_area_info {
75282 unsigned long high_limit;
75283 unsigned long align_mask;
75284 unsigned long align_offset;
75285+ unsigned long threadstack_offset;
75286 };
75287
75288-extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
75289-extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
75290+extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
75291+extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
75292
75293 /*
75294 * Search for an unmapped address range.
75295@@ -1574,7 +1589,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
75296 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
75297 */
75298 static inline unsigned long
75299-vm_unmapped_area(struct vm_unmapped_area_info *info)
75300+vm_unmapped_area(const struct vm_unmapped_area_info *info)
75301 {
75302 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
75303 return unmapped_area(info);
75304@@ -1637,6 +1652,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
75305 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
75306 struct vm_area_struct **pprev);
75307
75308+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
75309+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
75310+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
75311+
75312 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
75313 NULL if none. Assume start_addr < end_addr. */
75314 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
75315@@ -1665,15 +1684,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
75316 return vma;
75317 }
75318
75319-#ifdef CONFIG_MMU
75320-pgprot_t vm_get_page_prot(unsigned long vm_flags);
75321-#else
75322-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
75323-{
75324- return __pgprot(0);
75325-}
75326-#endif
75327-
75328 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
75329 unsigned long change_prot_numa(struct vm_area_struct *vma,
75330 unsigned long start, unsigned long end);
75331@@ -1725,6 +1735,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
75332 static inline void vm_stat_account(struct mm_struct *mm,
75333 unsigned long flags, struct file *file, long pages)
75334 {
75335+
75336+#ifdef CONFIG_PAX_RANDMMAP
75337+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
75338+#endif
75339+
75340 mm->total_vm += pages;
75341 }
75342 #endif /* CONFIG_PROC_FS */
75343@@ -1805,7 +1820,7 @@ extern int unpoison_memory(unsigned long pfn);
75344 extern int sysctl_memory_failure_early_kill;
75345 extern int sysctl_memory_failure_recovery;
75346 extern void shake_page(struct page *p, int access);
75347-extern atomic_long_t num_poisoned_pages;
75348+extern atomic_long_unchecked_t num_poisoned_pages;
75349 extern int soft_offline_page(struct page *page, int flags);
75350
75351 extern void dump_page(struct page *page);
75352@@ -1842,5 +1857,11 @@ void __init setup_nr_node_ids(void);
75353 static inline void setup_nr_node_ids(void) {}
75354 #endif
75355
75356+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
75357+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
75358+#else
75359+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
75360+#endif
75361+
75362 #endif /* __KERNEL__ */
75363 #endif /* _LINUX_MM_H */
75364diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
75365index faf4b7c..1e70c6e 100644
75366--- a/include/linux/mm_types.h
75367+++ b/include/linux/mm_types.h
75368@@ -289,6 +289,8 @@ struct vm_area_struct {
75369 #ifdef CONFIG_NUMA
75370 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
75371 #endif
75372+
75373+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
75374 };
75375
75376 struct core_thread {
75377@@ -435,6 +437,24 @@ struct mm_struct {
75378 int first_nid;
75379 #endif
75380 struct uprobes_state uprobes_state;
75381+
75382+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
75383+ unsigned long pax_flags;
75384+#endif
75385+
75386+#ifdef CONFIG_PAX_DLRESOLVE
75387+ unsigned long call_dl_resolve;
75388+#endif
75389+
75390+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
75391+ unsigned long call_syscall;
75392+#endif
75393+
75394+#ifdef CONFIG_PAX_ASLR
75395+ unsigned long delta_mmap; /* randomized offset */
75396+ unsigned long delta_stack; /* randomized offset */
75397+#endif
75398+
75399 };
75400
75401 /* first nid will either be a valid NID or one of these values */
75402diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
75403index c5d5278..f0b68c8 100644
75404--- a/include/linux/mmiotrace.h
75405+++ b/include/linux/mmiotrace.h
75406@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
75407 /* Called from ioremap.c */
75408 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
75409 void __iomem *addr);
75410-extern void mmiotrace_iounmap(volatile void __iomem *addr);
75411+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
75412
75413 /* For anyone to insert markers. Remember trailing newline. */
75414 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
75415@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
75416 {
75417 }
75418
75419-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
75420+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
75421 {
75422 }
75423
75424diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
75425index af4a3b7..9ad8889 100644
75426--- a/include/linux/mmzone.h
75427+++ b/include/linux/mmzone.h
75428@@ -396,7 +396,7 @@ struct zone {
75429 unsigned long flags; /* zone flags, see below */
75430
75431 /* Zone statistics */
75432- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
75433+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
75434
75435 /*
75436 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
75437diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
75438index 45e9214..a7227d6 100644
75439--- a/include/linux/mod_devicetable.h
75440+++ b/include/linux/mod_devicetable.h
75441@@ -13,7 +13,7 @@
75442 typedef unsigned long kernel_ulong_t;
75443 #endif
75444
75445-#define PCI_ANY_ID (~0)
75446+#define PCI_ANY_ID ((__u16)~0)
75447
75448 struct pci_device_id {
75449 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
75450@@ -139,7 +139,7 @@ struct usb_device_id {
75451 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
75452 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
75453
75454-#define HID_ANY_ID (~0)
75455+#define HID_ANY_ID (~0U)
75456 #define HID_BUS_ANY 0xffff
75457 #define HID_GROUP_ANY 0x0000
75458
75459@@ -467,7 +467,7 @@ struct dmi_system_id {
75460 const char *ident;
75461 struct dmi_strmatch matches[4];
75462 void *driver_data;
75463-};
75464+} __do_const;
75465 /*
75466 * struct dmi_device_id appears during expansion of
75467 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
75468diff --git a/include/linux/module.h b/include/linux/module.h
75469index 46f1ea0..a34ca37 100644
75470--- a/include/linux/module.h
75471+++ b/include/linux/module.h
75472@@ -17,9 +17,11 @@
75473 #include <linux/moduleparam.h>
75474 #include <linux/tracepoint.h>
75475 #include <linux/export.h>
75476+#include <linux/fs.h>
75477
75478 #include <linux/percpu.h>
75479 #include <asm/module.h>
75480+#include <asm/pgtable.h>
75481
75482 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
75483 #define MODULE_SIG_STRING "~Module signature appended~\n"
75484@@ -54,12 +56,13 @@ struct module_attribute {
75485 int (*test)(struct module *);
75486 void (*free)(struct module *);
75487 };
75488+typedef struct module_attribute __no_const module_attribute_no_const;
75489
75490 struct module_version_attribute {
75491 struct module_attribute mattr;
75492 const char *module_name;
75493 const char *version;
75494-} __attribute__ ((__aligned__(sizeof(void *))));
75495+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
75496
75497 extern ssize_t __modver_version_show(struct module_attribute *,
75498 struct module_kobject *, char *);
75499@@ -232,7 +235,7 @@ struct module
75500
75501 /* Sysfs stuff. */
75502 struct module_kobject mkobj;
75503- struct module_attribute *modinfo_attrs;
75504+ module_attribute_no_const *modinfo_attrs;
75505 const char *version;
75506 const char *srcversion;
75507 struct kobject *holders_dir;
75508@@ -281,19 +284,16 @@ struct module
75509 int (*init)(void);
75510
75511 /* If this is non-NULL, vfree after init() returns */
75512- void *module_init;
75513+ void *module_init_rx, *module_init_rw;
75514
75515 /* Here is the actual code + data, vfree'd on unload. */
75516- void *module_core;
75517+ void *module_core_rx, *module_core_rw;
75518
75519 /* Here are the sizes of the init and core sections */
75520- unsigned int init_size, core_size;
75521+ unsigned int init_size_rw, core_size_rw;
75522
75523 /* The size of the executable code in each section. */
75524- unsigned int init_text_size, core_text_size;
75525-
75526- /* Size of RO sections of the module (text+rodata) */
75527- unsigned int init_ro_size, core_ro_size;
75528+ unsigned int init_size_rx, core_size_rx;
75529
75530 /* Arch-specific module values */
75531 struct mod_arch_specific arch;
75532@@ -349,6 +349,10 @@ struct module
75533 #ifdef CONFIG_EVENT_TRACING
75534 struct ftrace_event_call **trace_events;
75535 unsigned int num_trace_events;
75536+ struct file_operations trace_id;
75537+ struct file_operations trace_enable;
75538+ struct file_operations trace_format;
75539+ struct file_operations trace_filter;
75540 #endif
75541 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
75542 unsigned int num_ftrace_callsites;
75543@@ -396,16 +400,46 @@ bool is_module_address(unsigned long addr);
75544 bool is_module_percpu_address(unsigned long addr);
75545 bool is_module_text_address(unsigned long addr);
75546
75547+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
75548+{
75549+
75550+#ifdef CONFIG_PAX_KERNEXEC
75551+ if (ktla_ktva(addr) >= (unsigned long)start &&
75552+ ktla_ktva(addr) < (unsigned long)start + size)
75553+ return 1;
75554+#endif
75555+
75556+ return ((void *)addr >= start && (void *)addr < start + size);
75557+}
75558+
75559+static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
75560+{
75561+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
75562+}
75563+
75564+static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
75565+{
75566+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
75567+}
75568+
75569+static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
75570+{
75571+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
75572+}
75573+
75574+static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
75575+{
75576+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
75577+}
75578+
75579 static inline int within_module_core(unsigned long addr, const struct module *mod)
75580 {
75581- return (unsigned long)mod->module_core <= addr &&
75582- addr < (unsigned long)mod->module_core + mod->core_size;
75583+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
75584 }
75585
75586 static inline int within_module_init(unsigned long addr, const struct module *mod)
75587 {
75588- return (unsigned long)mod->module_init <= addr &&
75589- addr < (unsigned long)mod->module_init + mod->init_size;
75590+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
75591 }
75592
75593 /* Search for module by name: must hold module_mutex. */
75594diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
75595index 560ca53..ef621ef 100644
75596--- a/include/linux/moduleloader.h
75597+++ b/include/linux/moduleloader.h
75598@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
75599 sections. Returns NULL on failure. */
75600 void *module_alloc(unsigned long size);
75601
75602+#ifdef CONFIG_PAX_KERNEXEC
75603+void *module_alloc_exec(unsigned long size);
75604+#else
75605+#define module_alloc_exec(x) module_alloc(x)
75606+#endif
75607+
75608 /* Free memory returned from module_alloc. */
75609 void module_free(struct module *mod, void *module_region);
75610
75611+#ifdef CONFIG_PAX_KERNEXEC
75612+void module_free_exec(struct module *mod, void *module_region);
75613+#else
75614+#define module_free_exec(x, y) module_free((x), (y))
75615+#endif
75616+
75617 /*
75618 * Apply the given relocation to the (simplified) ELF. Return -error
75619 * or 0.
75620@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
75621 unsigned int relsec,
75622 struct module *me)
75623 {
75624+#ifdef CONFIG_MODULES
75625 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
75626+#endif
75627 return -ENOEXEC;
75628 }
75629 #endif
75630@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
75631 unsigned int relsec,
75632 struct module *me)
75633 {
75634+#ifdef CONFIG_MODULES
75635 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
75636+#endif
75637 return -ENOEXEC;
75638 }
75639 #endif
75640diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
75641index 27d9da3..5d94aa3 100644
75642--- a/include/linux/moduleparam.h
75643+++ b/include/linux/moduleparam.h
75644@@ -284,7 +284,7 @@ static inline void __kernel_param_unlock(void)
75645 * @len is usually just sizeof(string).
75646 */
75647 #define module_param_string(name, string, len, perm) \
75648- static const struct kparam_string __param_string_##name \
75649+ static const struct kparam_string __param_string_##name __used \
75650 = { len, string }; \
75651 __module_param_call(MODULE_PARAM_PREFIX, name, \
75652 &param_ops_string, \
75653@@ -423,7 +423,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
75654 */
75655 #define module_param_array_named(name, array, type, nump, perm) \
75656 param_check_##type(name, &(array)[0]); \
75657- static const struct kparam_array __param_arr_##name \
75658+ static const struct kparam_array __param_arr_##name __used \
75659 = { .max = ARRAY_SIZE(array), .num = nump, \
75660 .ops = &param_ops_##type, \
75661 .elemsize = sizeof(array[0]), .elem = array }; \
75662diff --git a/include/linux/namei.h b/include/linux/namei.h
75663index 5a5ff57..5ae5070 100644
75664--- a/include/linux/namei.h
75665+++ b/include/linux/namei.h
75666@@ -19,7 +19,7 @@ struct nameidata {
75667 unsigned seq;
75668 int last_type;
75669 unsigned depth;
75670- char *saved_names[MAX_NESTED_LINKS + 1];
75671+ const char *saved_names[MAX_NESTED_LINKS + 1];
75672 };
75673
75674 /*
75675@@ -84,12 +84,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
75676
75677 extern void nd_jump_link(struct nameidata *nd, struct path *path);
75678
75679-static inline void nd_set_link(struct nameidata *nd, char *path)
75680+static inline void nd_set_link(struct nameidata *nd, const char *path)
75681 {
75682 nd->saved_names[nd->depth] = path;
75683 }
75684
75685-static inline char *nd_get_link(struct nameidata *nd)
75686+static inline const char *nd_get_link(const struct nameidata *nd)
75687 {
75688 return nd->saved_names[nd->depth];
75689 }
75690diff --git a/include/linux/net.h b/include/linux/net.h
75691index 4f27575..fc8a65f 100644
75692--- a/include/linux/net.h
75693+++ b/include/linux/net.h
75694@@ -183,7 +183,7 @@ struct net_proto_family {
75695 int (*create)(struct net *net, struct socket *sock,
75696 int protocol, int kern);
75697 struct module *owner;
75698-};
75699+} __do_const;
75700
75701 struct iovec;
75702 struct kvec;
75703diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
75704index 9a41568..203d903 100644
75705--- a/include/linux/netdevice.h
75706+++ b/include/linux/netdevice.h
75707@@ -1061,6 +1061,7 @@ struct net_device_ops {
75708 int (*ndo_change_carrier)(struct net_device *dev,
75709 bool new_carrier);
75710 };
75711+typedef struct net_device_ops __no_const net_device_ops_no_const;
75712
75713 /*
75714 * The DEVICE structure.
75715@@ -1131,7 +1132,7 @@ struct net_device {
75716 int iflink;
75717
75718 struct net_device_stats stats;
75719- atomic_long_t rx_dropped; /* dropped packets by core network
75720+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
75721 * Do not use this in drivers.
75722 */
75723
75724diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
75725index de70f7b..2675e91 100644
75726--- a/include/linux/netfilter.h
75727+++ b/include/linux/netfilter.h
75728@@ -82,7 +82,7 @@ struct nf_sockopt_ops {
75729 #endif
75730 /* Use the module struct to lock set/get code in place */
75731 struct module *owner;
75732-};
75733+} __do_const;
75734
75735 /* Function to register/unregister hook points. */
75736 int nf_register_hook(struct nf_hook_ops *reg);
75737diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
75738index d80e275..c3510b8 100644
75739--- a/include/linux/netfilter/ipset/ip_set.h
75740+++ b/include/linux/netfilter/ipset/ip_set.h
75741@@ -124,7 +124,7 @@ struct ip_set_type_variant {
75742 /* Return true if "b" set is the same as "a"
75743 * according to the create set parameters */
75744 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
75745-};
75746+} __do_const;
75747
75748 /* The core set type structure */
75749 struct ip_set_type {
75750diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
75751index cadb740..d7c37c0 100644
75752--- a/include/linux/netfilter/nfnetlink.h
75753+++ b/include/linux/netfilter/nfnetlink.h
75754@@ -16,7 +16,7 @@ struct nfnl_callback {
75755 const struct nlattr * const cda[]);
75756 const struct nla_policy *policy; /* netlink attribute policy */
75757 const u_int16_t attr_count; /* number of nlattr's */
75758-};
75759+} __do_const;
75760
75761 struct nfnetlink_subsystem {
75762 const char *name;
75763diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
75764new file mode 100644
75765index 0000000..33f4af8
75766--- /dev/null
75767+++ b/include/linux/netfilter/xt_gradm.h
75768@@ -0,0 +1,9 @@
75769+#ifndef _LINUX_NETFILTER_XT_GRADM_H
75770+#define _LINUX_NETFILTER_XT_GRADM_H 1
75771+
75772+struct xt_gradm_mtinfo {
75773+ __u16 flags;
75774+ __u16 invflags;
75775+};
75776+
75777+#endif
75778diff --git a/include/linux/nls.h b/include/linux/nls.h
75779index 5dc635f..35f5e11 100644
75780--- a/include/linux/nls.h
75781+++ b/include/linux/nls.h
75782@@ -31,7 +31,7 @@ struct nls_table {
75783 const unsigned char *charset2upper;
75784 struct module *owner;
75785 struct nls_table *next;
75786-};
75787+} __do_const;
75788
75789 /* this value hold the maximum octet of charset */
75790 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
75791diff --git a/include/linux/notifier.h b/include/linux/notifier.h
75792index d14a4c3..a078786 100644
75793--- a/include/linux/notifier.h
75794+++ b/include/linux/notifier.h
75795@@ -54,7 +54,8 @@ struct notifier_block {
75796 notifier_fn_t notifier_call;
75797 struct notifier_block __rcu *next;
75798 int priority;
75799-};
75800+} __do_const;
75801+typedef struct notifier_block __no_const notifier_block_no_const;
75802
75803 struct atomic_notifier_head {
75804 spinlock_t lock;
75805diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
75806index a4c5624..79d6d88 100644
75807--- a/include/linux/oprofile.h
75808+++ b/include/linux/oprofile.h
75809@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
75810 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
75811 char const * name, ulong * val);
75812
75813-/** Create a file for read-only access to an atomic_t. */
75814+/** Create a file for read-only access to an atomic_unchecked_t. */
75815 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
75816- char const * name, atomic_t * val);
75817+ char const * name, atomic_unchecked_t * val);
75818
75819 /** create a directory */
75820 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
75821diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
75822index 8db71dc..a76bf2c 100644
75823--- a/include/linux/pci_hotplug.h
75824+++ b/include/linux/pci_hotplug.h
75825@@ -80,7 +80,8 @@ struct hotplug_slot_ops {
75826 int (*get_attention_status) (struct hotplug_slot *slot, u8 *value);
75827 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
75828 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
75829-};
75830+} __do_const;
75831+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
75832
75833 /**
75834 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
75835diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
75836index c43f6ea..2d4416f 100644
75837--- a/include/linux/perf_event.h
75838+++ b/include/linux/perf_event.h
75839@@ -328,8 +328,8 @@ struct perf_event {
75840
75841 enum perf_event_active_state state;
75842 unsigned int attach_state;
75843- local64_t count;
75844- atomic64_t child_count;
75845+ local64_t count; /* PaX: fix it one day */
75846+ atomic64_unchecked_t child_count;
75847
75848 /*
75849 * These are the total time in nanoseconds that the event
75850@@ -380,8 +380,8 @@ struct perf_event {
75851 * These accumulate total time (in nanoseconds) that children
75852 * events have been enabled and running, respectively.
75853 */
75854- atomic64_t child_total_time_enabled;
75855- atomic64_t child_total_time_running;
75856+ atomic64_unchecked_t child_total_time_enabled;
75857+ atomic64_unchecked_t child_total_time_running;
75858
75859 /*
75860 * Protect attach/detach and child_list:
75861@@ -703,7 +703,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
75862 entry->ip[entry->nr++] = ip;
75863 }
75864
75865-extern int sysctl_perf_event_paranoid;
75866+extern int sysctl_perf_event_legitimately_concerned;
75867 extern int sysctl_perf_event_mlock;
75868 extern int sysctl_perf_event_sample_rate;
75869 extern int sysctl_perf_cpu_time_max_percent;
75870@@ -718,19 +718,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
75871 loff_t *ppos);
75872
75873
75874+static inline bool perf_paranoid_any(void)
75875+{
75876+ return sysctl_perf_event_legitimately_concerned > 2;
75877+}
75878+
75879 static inline bool perf_paranoid_tracepoint_raw(void)
75880 {
75881- return sysctl_perf_event_paranoid > -1;
75882+ return sysctl_perf_event_legitimately_concerned > -1;
75883 }
75884
75885 static inline bool perf_paranoid_cpu(void)
75886 {
75887- return sysctl_perf_event_paranoid > 0;
75888+ return sysctl_perf_event_legitimately_concerned > 0;
75889 }
75890
75891 static inline bool perf_paranoid_kernel(void)
75892 {
75893- return sysctl_perf_event_paranoid > 1;
75894+ return sysctl_perf_event_legitimately_concerned > 1;
75895 }
75896
75897 extern void perf_event_init(void);
75898@@ -846,7 +851,7 @@ struct perf_pmu_events_attr {
75899 struct device_attribute attr;
75900 u64 id;
75901 const char *event_str;
75902-};
75903+} __do_const;
75904
75905 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
75906 static struct perf_pmu_events_attr _var = { \
75907diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
75908index b8809fe..ae4ccd0 100644
75909--- a/include/linux/pipe_fs_i.h
75910+++ b/include/linux/pipe_fs_i.h
75911@@ -47,10 +47,10 @@ struct pipe_inode_info {
75912 struct mutex mutex;
75913 wait_queue_head_t wait;
75914 unsigned int nrbufs, curbuf, buffers;
75915- unsigned int readers;
75916- unsigned int writers;
75917- unsigned int files;
75918- unsigned int waiting_writers;
75919+ atomic_t readers;
75920+ atomic_t writers;
75921+ atomic_t files;
75922+ atomic_t waiting_writers;
75923 unsigned int r_counter;
75924 unsigned int w_counter;
75925 struct page *tmp_page;
75926diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
75927index 5f28cae..3d23723 100644
75928--- a/include/linux/platform_data/usb-ehci-s5p.h
75929+++ b/include/linux/platform_data/usb-ehci-s5p.h
75930@@ -14,7 +14,7 @@
75931 struct s5p_ehci_platdata {
75932 int (*phy_init)(struct platform_device *pdev, int type);
75933 int (*phy_exit)(struct platform_device *pdev, int type);
75934-};
75935+} __no_const;
75936
75937 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
75938
75939diff --git a/include/linux/platform_data/usb-ohci-exynos.h b/include/linux/platform_data/usb-ohci-exynos.h
75940index c256c59..8ea94c7 100644
75941--- a/include/linux/platform_data/usb-ohci-exynos.h
75942+++ b/include/linux/platform_data/usb-ohci-exynos.h
75943@@ -14,7 +14,7 @@
75944 struct exynos4_ohci_platdata {
75945 int (*phy_init)(struct platform_device *pdev, int type);
75946 int (*phy_exit)(struct platform_device *pdev, int type);
75947-};
75948+} __no_const;
75949
75950 extern void exynos4_ohci_set_platdata(struct exynos4_ohci_platdata *pd);
75951
75952diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
75953index 7c1d252..c5c773e 100644
75954--- a/include/linux/pm_domain.h
75955+++ b/include/linux/pm_domain.h
75956@@ -48,7 +48,7 @@ struct gpd_dev_ops {
75957
75958 struct gpd_cpu_data {
75959 unsigned int saved_exit_latency;
75960- struct cpuidle_state *idle_state;
75961+ cpuidle_state_no_const *idle_state;
75962 };
75963
75964 struct generic_pm_domain {
75965diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
75966index 6fa7cea..7bf6415 100644
75967--- a/include/linux/pm_runtime.h
75968+++ b/include/linux/pm_runtime.h
75969@@ -103,7 +103,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
75970
75971 static inline void pm_runtime_mark_last_busy(struct device *dev)
75972 {
75973- ACCESS_ONCE(dev->power.last_busy) = jiffies;
75974+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
75975 }
75976
75977 #else /* !CONFIG_PM_RUNTIME */
75978diff --git a/include/linux/pnp.h b/include/linux/pnp.h
75979index 195aafc..49a7bc2 100644
75980--- a/include/linux/pnp.h
75981+++ b/include/linux/pnp.h
75982@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
75983 struct pnp_fixup {
75984 char id[7];
75985 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
75986-};
75987+} __do_const;
75988
75989 /* config parameters */
75990 #define PNP_CONFIG_NORMAL 0x0001
75991diff --git a/include/linux/poison.h b/include/linux/poison.h
75992index 2110a81..13a11bb 100644
75993--- a/include/linux/poison.h
75994+++ b/include/linux/poison.h
75995@@ -19,8 +19,8 @@
75996 * under normal circumstances, used to verify that nobody uses
75997 * non-initialized list entries.
75998 */
75999-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
76000-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
76001+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
76002+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
76003
76004 /********** include/linux/timer.h **********/
76005 /*
76006diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
76007index d8b187c3..9a9257a 100644
76008--- a/include/linux/power/smartreflex.h
76009+++ b/include/linux/power/smartreflex.h
76010@@ -238,7 +238,7 @@ struct omap_sr_class_data {
76011 int (*notify)(struct omap_sr *sr, u32 status);
76012 u8 notify_flags;
76013 u8 class_type;
76014-};
76015+} __do_const;
76016
76017 /**
76018 * struct omap_sr_nvalue_table - Smartreflex n-target value info
76019diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
76020index 4ea1d37..80f4b33 100644
76021--- a/include/linux/ppp-comp.h
76022+++ b/include/linux/ppp-comp.h
76023@@ -84,7 +84,7 @@ struct compressor {
76024 struct module *owner;
76025 /* Extra skb space needed by the compressor algorithm */
76026 unsigned int comp_extra;
76027-};
76028+} __do_const;
76029
76030 /*
76031 * The return value from decompress routine is the length of the
76032diff --git a/include/linux/preempt.h b/include/linux/preempt.h
76033index f5d4723..a6ea2fa 100644
76034--- a/include/linux/preempt.h
76035+++ b/include/linux/preempt.h
76036@@ -18,8 +18,13 @@
76037 # define sub_preempt_count(val) do { preempt_count() -= (val); } while (0)
76038 #endif
76039
76040+#define raw_add_preempt_count(val) do { preempt_count() += (val); } while (0)
76041+#define raw_sub_preempt_count(val) do { preempt_count() -= (val); } while (0)
76042+
76043 #define inc_preempt_count() add_preempt_count(1)
76044+#define raw_inc_preempt_count() raw_add_preempt_count(1)
76045 #define dec_preempt_count() sub_preempt_count(1)
76046+#define raw_dec_preempt_count() raw_sub_preempt_count(1)
76047
76048 #define preempt_count() (current_thread_info()->preempt_count)
76049
76050@@ -64,6 +69,12 @@ do { \
76051 barrier(); \
76052 } while (0)
76053
76054+#define raw_preempt_disable() \
76055+do { \
76056+ raw_inc_preempt_count(); \
76057+ barrier(); \
76058+} while (0)
76059+
76060 #define sched_preempt_enable_no_resched() \
76061 do { \
76062 barrier(); \
76063@@ -72,6 +83,12 @@ do { \
76064
76065 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
76066
76067+#define raw_preempt_enable_no_resched() \
76068+do { \
76069+ barrier(); \
76070+ raw_dec_preempt_count(); \
76071+} while (0)
76072+
76073 #define preempt_enable() \
76074 do { \
76075 preempt_enable_no_resched(); \
76076@@ -116,8 +133,10 @@ do { \
76077 * region.
76078 */
76079 #define preempt_disable() barrier()
76080+#define raw_preempt_disable() barrier()
76081 #define sched_preempt_enable_no_resched() barrier()
76082 #define preempt_enable_no_resched() barrier()
76083+#define raw_preempt_enable_no_resched() barrier()
76084 #define preempt_enable() barrier()
76085
76086 #define preempt_disable_notrace() barrier()
76087diff --git a/include/linux/printk.h b/include/linux/printk.h
76088index 22c7052..ad3fa0a 100644
76089--- a/include/linux/printk.h
76090+++ b/include/linux/printk.h
76091@@ -106,6 +106,8 @@ static inline __printf(1, 2) __cold
76092 void early_printk(const char *s, ...) { }
76093 #endif
76094
76095+extern int kptr_restrict;
76096+
76097 #ifdef CONFIG_PRINTK
76098 asmlinkage __printf(5, 0)
76099 int vprintk_emit(int facility, int level,
76100@@ -140,7 +142,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
76101
76102 extern int printk_delay_msec;
76103 extern int dmesg_restrict;
76104-extern int kptr_restrict;
76105
76106 extern void wake_up_klogd(void);
76107
76108diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
76109index 608e60a..c26f864 100644
76110--- a/include/linux/proc_fs.h
76111+++ b/include/linux/proc_fs.h
76112@@ -34,6 +34,19 @@ static inline struct proc_dir_entry *proc_create(
76113 return proc_create_data(name, mode, parent, proc_fops, NULL);
76114 }
76115
76116+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
76117+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
76118+{
76119+#ifdef CONFIG_GRKERNSEC_PROC_USER
76120+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
76121+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
76122+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
76123+#else
76124+ return proc_create_data(name, mode, parent, proc_fops, NULL);
76125+#endif
76126+}
76127+
76128+
76129 extern void proc_set_size(struct proc_dir_entry *, loff_t);
76130 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
76131 extern void *PDE_DATA(const struct inode *);
76132diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
76133index 34a1e10..03a6d03 100644
76134--- a/include/linux/proc_ns.h
76135+++ b/include/linux/proc_ns.h
76136@@ -14,7 +14,7 @@ struct proc_ns_operations {
76137 void (*put)(void *ns);
76138 int (*install)(struct nsproxy *nsproxy, void *ns);
76139 unsigned int (*inum)(void *ns);
76140-};
76141+} __do_const;
76142
76143 struct proc_ns {
76144 void *ns;
76145diff --git a/include/linux/random.h b/include/linux/random.h
76146index 3b9377d..943ad4a 100644
76147--- a/include/linux/random.h
76148+++ b/include/linux/random.h
76149@@ -10,6 +10,16 @@
76150
76151
76152 extern void add_device_randomness(const void *, unsigned int);
76153+
76154+static inline void add_latent_entropy(void)
76155+{
76156+
76157+#ifdef LATENT_ENTROPY_PLUGIN
76158+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
76159+#endif
76160+
76161+}
76162+
76163 extern void add_input_randomness(unsigned int type, unsigned int code,
76164 unsigned int value);
76165 extern void add_interrupt_randomness(int irq, int irq_flags);
76166@@ -32,6 +42,11 @@ void prandom_seed(u32 seed);
76167 u32 prandom_u32_state(struct rnd_state *);
76168 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
76169
76170+static inline unsigned long pax_get_random_long(void)
76171+{
76172+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
76173+}
76174+
76175 /*
76176 * Handle minimum values for seeds
76177 */
76178diff --git a/include/linux/rculist.h b/include/linux/rculist.h
76179index f4b1001..8ddb2b6 100644
76180--- a/include/linux/rculist.h
76181+++ b/include/linux/rculist.h
76182@@ -44,6 +44,9 @@ extern void __list_add_rcu(struct list_head *new,
76183 struct list_head *prev, struct list_head *next);
76184 #endif
76185
76186+extern void __pax_list_add_rcu(struct list_head *new,
76187+ struct list_head *prev, struct list_head *next);
76188+
76189 /**
76190 * list_add_rcu - add a new entry to rcu-protected list
76191 * @new: new entry to be added
76192@@ -65,6 +68,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
76193 __list_add_rcu(new, head, head->next);
76194 }
76195
76196+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
76197+{
76198+ __pax_list_add_rcu(new, head, head->next);
76199+}
76200+
76201 /**
76202 * list_add_tail_rcu - add a new entry to rcu-protected list
76203 * @new: new entry to be added
76204@@ -87,6 +95,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
76205 __list_add_rcu(new, head->prev, head);
76206 }
76207
76208+static inline void pax_list_add_tail_rcu(struct list_head *new,
76209+ struct list_head *head)
76210+{
76211+ __pax_list_add_rcu(new, head->prev, head);
76212+}
76213+
76214 /**
76215 * list_del_rcu - deletes entry from list without re-initialization
76216 * @entry: the element to delete from the list.
76217@@ -117,6 +131,8 @@ static inline void list_del_rcu(struct list_head *entry)
76218 entry->prev = LIST_POISON2;
76219 }
76220
76221+extern void pax_list_del_rcu(struct list_head *entry);
76222+
76223 /**
76224 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
76225 * @n: the element to delete from the hash list.
76226diff --git a/include/linux/reboot.h b/include/linux/reboot.h
76227index 8e00f9f..9449b55 100644
76228--- a/include/linux/reboot.h
76229+++ b/include/linux/reboot.h
76230@@ -43,9 +43,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
76231 * Architecture-specific implementations of sys_reboot commands.
76232 */
76233
76234-extern void machine_restart(char *cmd);
76235-extern void machine_halt(void);
76236-extern void machine_power_off(void);
76237+extern void machine_restart(char *cmd) __noreturn;
76238+extern void machine_halt(void) __noreturn;
76239+extern void machine_power_off(void) __noreturn;
76240
76241 extern void machine_shutdown(void);
76242 struct pt_regs;
76243@@ -56,9 +56,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
76244 */
76245
76246 extern void kernel_restart_prepare(char *cmd);
76247-extern void kernel_restart(char *cmd);
76248-extern void kernel_halt(void);
76249-extern void kernel_power_off(void);
76250+extern void kernel_restart(char *cmd) __noreturn;
76251+extern void kernel_halt(void) __noreturn;
76252+extern void kernel_power_off(void) __noreturn;
76253
76254 extern int C_A_D; /* for sysctl */
76255 void ctrl_alt_del(void);
76256@@ -72,7 +72,7 @@ extern int orderly_poweroff(bool force);
76257 * Emergency restart, callable from an interrupt handler.
76258 */
76259
76260-extern void emergency_restart(void);
76261+extern void emergency_restart(void) __noreturn;
76262 #include <asm/emergency-restart.h>
76263
76264 #endif /* _LINUX_REBOOT_H */
76265diff --git a/include/linux/regset.h b/include/linux/regset.h
76266index 8e0c9fe..ac4d221 100644
76267--- a/include/linux/regset.h
76268+++ b/include/linux/regset.h
76269@@ -161,7 +161,8 @@ struct user_regset {
76270 unsigned int align;
76271 unsigned int bias;
76272 unsigned int core_note_type;
76273-};
76274+} __do_const;
76275+typedef struct user_regset __no_const user_regset_no_const;
76276
76277 /**
76278 * struct user_regset_view - available regsets
76279diff --git a/include/linux/relay.h b/include/linux/relay.h
76280index d7c8359..818daf5 100644
76281--- a/include/linux/relay.h
76282+++ b/include/linux/relay.h
76283@@ -157,7 +157,7 @@ struct rchan_callbacks
76284 * The callback should return 0 if successful, negative if not.
76285 */
76286 int (*remove_buf_file)(struct dentry *dentry);
76287-};
76288+} __no_const;
76289
76290 /*
76291 * CONFIG_RELAY kernel API, kernel/relay.c
76292diff --git a/include/linux/rio.h b/include/linux/rio.h
76293index b71d573..2f940bd 100644
76294--- a/include/linux/rio.h
76295+++ b/include/linux/rio.h
76296@@ -355,7 +355,7 @@ struct rio_ops {
76297 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
76298 u64 rstart, u32 size, u32 flags);
76299 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
76300-};
76301+} __no_const;
76302
76303 #define RIO_RESOURCE_MEM 0x00000100
76304 #define RIO_RESOURCE_DOORBELL 0x00000200
76305diff --git a/include/linux/rmap.h b/include/linux/rmap.h
76306index 6dacb93..6174423 100644
76307--- a/include/linux/rmap.h
76308+++ b/include/linux/rmap.h
76309@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
76310 void anon_vma_init(void); /* create anon_vma_cachep */
76311 int anon_vma_prepare(struct vm_area_struct *);
76312 void unlink_anon_vmas(struct vm_area_struct *);
76313-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
76314-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
76315+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
76316+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
76317
76318 static inline void anon_vma_merge(struct vm_area_struct *vma,
76319 struct vm_area_struct *next)
76320diff --git a/include/linux/sched.h b/include/linux/sched.h
76321index 078066d..4090b3b 100644
76322--- a/include/linux/sched.h
76323+++ b/include/linux/sched.h
76324@@ -62,6 +62,7 @@ struct bio_list;
76325 struct fs_struct;
76326 struct perf_event_context;
76327 struct blk_plug;
76328+struct linux_binprm;
76329
76330 /*
76331 * List of flags we want to share for kernel threads,
76332@@ -303,7 +304,7 @@ extern char __sched_text_start[], __sched_text_end[];
76333 extern int in_sched_functions(unsigned long addr);
76334
76335 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
76336-extern signed long schedule_timeout(signed long timeout);
76337+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
76338 extern signed long schedule_timeout_interruptible(signed long timeout);
76339 extern signed long schedule_timeout_killable(signed long timeout);
76340 extern signed long schedule_timeout_uninterruptible(signed long timeout);
76341@@ -314,6 +315,19 @@ struct nsproxy;
76342 struct user_namespace;
76343
76344 #ifdef CONFIG_MMU
76345+
76346+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
76347+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
76348+#else
76349+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
76350+{
76351+ return 0;
76352+}
76353+#endif
76354+
76355+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
76356+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
76357+
76358 extern void arch_pick_mmap_layout(struct mm_struct *mm);
76359 extern unsigned long
76360 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
76361@@ -589,6 +603,17 @@ struct signal_struct {
76362 #ifdef CONFIG_TASKSTATS
76363 struct taskstats *stats;
76364 #endif
76365+
76366+#ifdef CONFIG_GRKERNSEC
76367+ u32 curr_ip;
76368+ u32 saved_ip;
76369+ u32 gr_saddr;
76370+ u32 gr_daddr;
76371+ u16 gr_sport;
76372+ u16 gr_dport;
76373+ u8 used_accept:1;
76374+#endif
76375+
76376 #ifdef CONFIG_AUDIT
76377 unsigned audit_tty;
76378 unsigned audit_tty_log_passwd;
76379@@ -669,6 +694,14 @@ struct user_struct {
76380 struct key *session_keyring; /* UID's default session keyring */
76381 #endif
76382
76383+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
76384+ unsigned char kernel_banned;
76385+#endif
76386+#ifdef CONFIG_GRKERNSEC_BRUTE
76387+ unsigned char suid_banned;
76388+ unsigned long suid_ban_expires;
76389+#endif
76390+
76391 /* Hash table maintenance information */
76392 struct hlist_node uidhash_node;
76393 kuid_t uid;
76394@@ -1151,8 +1184,8 @@ struct task_struct {
76395 struct list_head thread_group;
76396
76397 struct completion *vfork_done; /* for vfork() */
76398- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
76399- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
76400+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
76401+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
76402
76403 cputime_t utime, stime, utimescaled, stimescaled;
76404 cputime_t gtime;
76405@@ -1177,11 +1210,6 @@ struct task_struct {
76406 struct task_cputime cputime_expires;
76407 struct list_head cpu_timers[3];
76408
76409-/* process credentials */
76410- const struct cred __rcu *real_cred; /* objective and real subjective task
76411- * credentials (COW) */
76412- const struct cred __rcu *cred; /* effective (overridable) subjective task
76413- * credentials (COW) */
76414 char comm[TASK_COMM_LEN]; /* executable name excluding path
76415 - access with [gs]et_task_comm (which lock
76416 it with task_lock())
76417@@ -1198,6 +1226,10 @@ struct task_struct {
76418 #endif
76419 /* CPU-specific state of this task */
76420 struct thread_struct thread;
76421+/* thread_info moved to task_struct */
76422+#ifdef CONFIG_X86
76423+ struct thread_info tinfo;
76424+#endif
76425 /* filesystem information */
76426 struct fs_struct *fs;
76427 /* open file information */
76428@@ -1271,6 +1303,10 @@ struct task_struct {
76429 gfp_t lockdep_reclaim_gfp;
76430 #endif
76431
76432+/* process credentials */
76433+ const struct cred __rcu *real_cred; /* objective and real subjective task
76434+ * credentials (COW) */
76435+
76436 /* journalling filesystem info */
76437 void *journal_info;
76438
76439@@ -1309,6 +1345,10 @@ struct task_struct {
76440 /* cg_list protected by css_set_lock and tsk->alloc_lock */
76441 struct list_head cg_list;
76442 #endif
76443+
76444+ const struct cred __rcu *cred; /* effective (overridable) subjective task
76445+ * credentials (COW) */
76446+
76447 #ifdef CONFIG_FUTEX
76448 struct robust_list_head __user *robust_list;
76449 #ifdef CONFIG_COMPAT
76450@@ -1406,8 +1446,76 @@ struct task_struct {
76451 unsigned int sequential_io;
76452 unsigned int sequential_io_avg;
76453 #endif
76454+
76455+#ifdef CONFIG_GRKERNSEC
76456+ /* grsecurity */
76457+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
76458+ u64 exec_id;
76459+#endif
76460+#ifdef CONFIG_GRKERNSEC_SETXID
76461+ const struct cred *delayed_cred;
76462+#endif
76463+ struct dentry *gr_chroot_dentry;
76464+ struct acl_subject_label *acl;
76465+ struct acl_role_label *role;
76466+ struct file *exec_file;
76467+ unsigned long brute_expires;
76468+ u16 acl_role_id;
76469+ /* is this the task that authenticated to the special role */
76470+ u8 acl_sp_role;
76471+ u8 is_writable;
76472+ u8 brute;
76473+ u8 gr_is_chrooted;
76474+#endif
76475+
76476 };
76477
76478+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
76479+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
76480+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
76481+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
76482+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
76483+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
76484+
76485+#ifdef CONFIG_PAX_SOFTMODE
76486+extern int pax_softmode;
76487+#endif
76488+
76489+extern int pax_check_flags(unsigned long *);
76490+
76491+/* if tsk != current then task_lock must be held on it */
76492+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
76493+static inline unsigned long pax_get_flags(struct task_struct *tsk)
76494+{
76495+ if (likely(tsk->mm))
76496+ return tsk->mm->pax_flags;
76497+ else
76498+ return 0UL;
76499+}
76500+
76501+/* if tsk != current then task_lock must be held on it */
76502+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
76503+{
76504+ if (likely(tsk->mm)) {
76505+ tsk->mm->pax_flags = flags;
76506+ return 0;
76507+ }
76508+ return -EINVAL;
76509+}
76510+#endif
76511+
76512+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
76513+extern void pax_set_initial_flags(struct linux_binprm *bprm);
76514+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
76515+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
76516+#endif
76517+
76518+struct path;
76519+extern char *pax_get_path(const struct path *path, char *buf, int buflen);
76520+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
76521+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
76522+extern void pax_report_refcount_overflow(struct pt_regs *regs);
76523+
76524 /* Future-safe accessor for struct task_struct's cpus_allowed. */
76525 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
76526
76527@@ -1466,7 +1574,7 @@ struct pid_namespace;
76528 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
76529 struct pid_namespace *ns);
76530
76531-static inline pid_t task_pid_nr(struct task_struct *tsk)
76532+static inline pid_t task_pid_nr(const struct task_struct *tsk)
76533 {
76534 return tsk->pid;
76535 }
76536@@ -1916,7 +2024,9 @@ void yield(void);
76537 extern struct exec_domain default_exec_domain;
76538
76539 union thread_union {
76540+#ifndef CONFIG_X86
76541 struct thread_info thread_info;
76542+#endif
76543 unsigned long stack[THREAD_SIZE/sizeof(long)];
76544 };
76545
76546@@ -1949,6 +2059,7 @@ extern struct pid_namespace init_pid_ns;
76547 */
76548
76549 extern struct task_struct *find_task_by_vpid(pid_t nr);
76550+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
76551 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
76552 struct pid_namespace *ns);
76553
76554@@ -2113,7 +2224,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
76555 extern void exit_itimers(struct signal_struct *);
76556 extern void flush_itimer_signals(void);
76557
76558-extern void do_group_exit(int);
76559+extern __noreturn void do_group_exit(int);
76560
76561 extern int allow_signal(int);
76562 extern int disallow_signal(int);
76563@@ -2304,9 +2415,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
76564
76565 #endif
76566
76567-static inline int object_is_on_stack(void *obj)
76568+static inline int object_starts_on_stack(void *obj)
76569 {
76570- void *stack = task_stack_page(current);
76571+ const void *stack = task_stack_page(current);
76572
76573 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
76574 }
76575diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
76576index bf8086b..962b035 100644
76577--- a/include/linux/sched/sysctl.h
76578+++ b/include/linux/sched/sysctl.h
76579@@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
76580 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
76581
76582 extern int sysctl_max_map_count;
76583+extern unsigned long sysctl_heap_stack_gap;
76584
76585 extern unsigned int sysctl_sched_latency;
76586 extern unsigned int sysctl_sched_min_granularity;
76587diff --git a/include/linux/security.h b/include/linux/security.h
76588index 7ce53ae..8ee24a5 100644
76589--- a/include/linux/security.h
76590+++ b/include/linux/security.h
76591@@ -27,6 +27,7 @@
76592 #include <linux/slab.h>
76593 #include <linux/err.h>
76594 #include <linux/string.h>
76595+#include <linux/grsecurity.h>
76596
76597 struct linux_binprm;
76598 struct cred;
76599@@ -116,8 +117,6 @@ struct seq_file;
76600
76601 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
76602
76603-void reset_security_ops(void);
76604-
76605 #ifdef CONFIG_MMU
76606 extern unsigned long mmap_min_addr;
76607 extern unsigned long dac_mmap_min_addr;
76608diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
76609index 4e32edc..f8f2d18 100644
76610--- a/include/linux/seq_file.h
76611+++ b/include/linux/seq_file.h
76612@@ -26,6 +26,9 @@ struct seq_file {
76613 struct mutex lock;
76614 const struct seq_operations *op;
76615 int poll_event;
76616+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
76617+ u64 exec_id;
76618+#endif
76619 #ifdef CONFIG_USER_NS
76620 struct user_namespace *user_ns;
76621 #endif
76622@@ -38,6 +41,7 @@ struct seq_operations {
76623 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
76624 int (*show) (struct seq_file *m, void *v);
76625 };
76626+typedef struct seq_operations __no_const seq_operations_no_const;
76627
76628 #define SEQ_SKIP 1
76629
76630diff --git a/include/linux/shm.h b/include/linux/shm.h
76631index 429c199..4d42e38 100644
76632--- a/include/linux/shm.h
76633+++ b/include/linux/shm.h
76634@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
76635
76636 /* The task created the shm object. NULL if the task is dead. */
76637 struct task_struct *shm_creator;
76638+#ifdef CONFIG_GRKERNSEC
76639+ time_t shm_createtime;
76640+ pid_t shm_lapid;
76641+#endif
76642 };
76643
76644 /* shm_mode upper byte flags */
76645diff --git a/include/linux/signal.h b/include/linux/signal.h
76646index d897484..323ba98 100644
76647--- a/include/linux/signal.h
76648+++ b/include/linux/signal.h
76649@@ -433,6 +433,7 @@ void signals_init(void);
76650
76651 int restore_altstack(const stack_t __user *);
76652 int __save_altstack(stack_t __user *, unsigned long);
76653+void __save_altstack_ex(stack_t __user *, unsigned long);
76654
76655 #ifdef CONFIG_PROC_FS
76656 struct seq_file;
76657diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
76658index 3b71a4e..5c9f309 100644
76659--- a/include/linux/skbuff.h
76660+++ b/include/linux/skbuff.h
76661@@ -648,7 +648,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
76662 extern struct sk_buff *__alloc_skb(unsigned int size,
76663 gfp_t priority, int flags, int node);
76664 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
76665-static inline struct sk_buff *alloc_skb(unsigned int size,
76666+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
76667 gfp_t priority)
76668 {
76669 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
76670@@ -764,7 +764,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
76671 */
76672 static inline int skb_queue_empty(const struct sk_buff_head *list)
76673 {
76674- return list->next == (struct sk_buff *)list;
76675+ return list->next == (const struct sk_buff *)list;
76676 }
76677
76678 /**
76679@@ -777,7 +777,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
76680 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
76681 const struct sk_buff *skb)
76682 {
76683- return skb->next == (struct sk_buff *)list;
76684+ return skb->next == (const struct sk_buff *)list;
76685 }
76686
76687 /**
76688@@ -790,7 +790,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
76689 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
76690 const struct sk_buff *skb)
76691 {
76692- return skb->prev == (struct sk_buff *)list;
76693+ return skb->prev == (const struct sk_buff *)list;
76694 }
76695
76696 /**
76697@@ -1750,7 +1750,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
76698 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
76699 */
76700 #ifndef NET_SKB_PAD
76701-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
76702+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
76703 #endif
76704
76705 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
76706@@ -2345,7 +2345,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
76707 int noblock, int *err);
76708 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
76709 struct poll_table_struct *wait);
76710-extern int skb_copy_datagram_iovec(const struct sk_buff *from,
76711+extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
76712 int offset, struct iovec *to,
76713 int size);
76714 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
76715@@ -2636,6 +2636,9 @@ static inline void nf_reset(struct sk_buff *skb)
76716 nf_bridge_put(skb->nf_bridge);
76717 skb->nf_bridge = NULL;
76718 #endif
76719+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
76720+ skb->nf_trace = 0;
76721+#endif
76722 }
76723
76724 static inline void nf_reset_trace(struct sk_buff *skb)
76725diff --git a/include/linux/slab.h b/include/linux/slab.h
76726index 6c5cc0e..9ca0fd6 100644
76727--- a/include/linux/slab.h
76728+++ b/include/linux/slab.h
76729@@ -12,15 +12,29 @@
76730 #include <linux/gfp.h>
76731 #include <linux/types.h>
76732 #include <linux/workqueue.h>
76733-
76734+#include <linux/err.h>
76735
76736 /*
76737 * Flags to pass to kmem_cache_create().
76738 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
76739 */
76740 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
76741+
76742+#ifdef CONFIG_PAX_USERCOPY_SLABS
76743+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
76744+#else
76745+#define SLAB_USERCOPY 0x00000000UL
76746+#endif
76747+
76748 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
76749 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
76750+
76751+#ifdef CONFIG_PAX_MEMORY_SANITIZE
76752+#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
76753+#else
76754+#define SLAB_NO_SANITIZE 0x00000000UL
76755+#endif
76756+
76757 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
76758 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
76759 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
76760@@ -89,10 +103,13 @@
76761 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
76762 * Both make kfree a no-op.
76763 */
76764-#define ZERO_SIZE_PTR ((void *)16)
76765+#define ZERO_SIZE_PTR \
76766+({ \
76767+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
76768+ (void *)(-MAX_ERRNO-1L); \
76769+})
76770
76771-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
76772- (unsigned long)ZERO_SIZE_PTR)
76773+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
76774
76775
76776 struct mem_cgroup;
76777@@ -132,6 +149,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
76778 void kfree(const void *);
76779 void kzfree(const void *);
76780 size_t ksize(const void *);
76781+const char *check_heap_object(const void *ptr, unsigned long n);
76782+bool is_usercopy_object(const void *ptr);
76783
76784 /*
76785 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
76786@@ -164,7 +183,7 @@ struct kmem_cache {
76787 unsigned int align; /* Alignment as calculated */
76788 unsigned long flags; /* Active flags on the slab */
76789 const char *name; /* Slab name for sysfs */
76790- int refcount; /* Use counter */
76791+ atomic_t refcount; /* Use counter */
76792 void (*ctor)(void *); /* Called on object slot creation */
76793 struct list_head list; /* List of all slab caches on the system */
76794 };
76795@@ -238,6 +257,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
76796 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
76797 #endif
76798
76799+#ifdef CONFIG_PAX_USERCOPY_SLABS
76800+extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
76801+#endif
76802+
76803 /*
76804 * Figure out which kmalloc slab an allocation of a certain size
76805 * belongs to.
76806@@ -246,7 +269,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
76807 * 2 = 120 .. 192 bytes
76808 * n = 2^(n-1) .. 2^n -1
76809 */
76810-static __always_inline int kmalloc_index(size_t size)
76811+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
76812 {
76813 if (!size)
76814 return 0;
76815@@ -492,7 +515,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
76816 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
76817 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
76818 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
76819-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
76820+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
76821 #define kmalloc_track_caller(size, flags) \
76822 __kmalloc_track_caller(size, flags, _RET_IP_)
76823 #else
76824@@ -512,7 +535,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
76825 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
76826 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
76827 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
76828-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
76829+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
76830 #define kmalloc_node_track_caller(size, flags, node) \
76831 __kmalloc_node_track_caller(size, flags, node, \
76832 _RET_IP_)
76833diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
76834index cd40158..4e2f7af 100644
76835--- a/include/linux/slab_def.h
76836+++ b/include/linux/slab_def.h
76837@@ -50,7 +50,7 @@ struct kmem_cache {
76838 /* 4) cache creation/removal */
76839 const char *name;
76840 struct list_head list;
76841- int refcount;
76842+ atomic_t refcount;
76843 int object_size;
76844 int align;
76845
76846@@ -66,10 +66,14 @@ struct kmem_cache {
76847 unsigned long node_allocs;
76848 unsigned long node_frees;
76849 unsigned long node_overflow;
76850- atomic_t allochit;
76851- atomic_t allocmiss;
76852- atomic_t freehit;
76853- atomic_t freemiss;
76854+ atomic_unchecked_t allochit;
76855+ atomic_unchecked_t allocmiss;
76856+ atomic_unchecked_t freehit;
76857+ atomic_unchecked_t freemiss;
76858+#ifdef CONFIG_PAX_MEMORY_SANITIZE
76859+ atomic_unchecked_t sanitized;
76860+ atomic_unchecked_t not_sanitized;
76861+#endif
76862
76863 /*
76864 * If debugging is enabled, then the allocator can add additional
76865@@ -103,7 +107,7 @@ struct kmem_cache {
76866 };
76867
76868 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
76869-void *__kmalloc(size_t size, gfp_t flags);
76870+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
76871
76872 #ifdef CONFIG_TRACING
76873 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
76874@@ -136,6 +140,13 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
76875 cachep = kmalloc_dma_caches[i];
76876 else
76877 #endif
76878+
76879+#ifdef CONFIG_PAX_USERCOPY_SLABS
76880+ if (flags & GFP_USERCOPY)
76881+ cachep = kmalloc_usercopy_caches[i];
76882+ else
76883+#endif
76884+
76885 cachep = kmalloc_caches[i];
76886
76887 ret = kmem_cache_alloc_trace(cachep, flags, size);
76888@@ -146,7 +157,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
76889 }
76890
76891 #ifdef CONFIG_NUMA
76892-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
76893+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
76894 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
76895
76896 #ifdef CONFIG_TRACING
76897@@ -185,6 +196,13 @@ static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
76898 cachep = kmalloc_dma_caches[i];
76899 else
76900 #endif
76901+
76902+#ifdef CONFIG_PAX_USERCOPY_SLABS
76903+ if (flags & GFP_USERCOPY)
76904+ cachep = kmalloc_usercopy_caches[i];
76905+ else
76906+#endif
76907+
76908 cachep = kmalloc_caches[i];
76909
76910 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
76911diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
76912index 095a5a4..4b82027 100644
76913--- a/include/linux/slob_def.h
76914+++ b/include/linux/slob_def.h
76915@@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
76916 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
76917 }
76918
76919-void *__kmalloc_node(size_t size, gfp_t flags, int node);
76920+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
76921
76922 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
76923 {
76924@@ -23,7 +23,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
76925 return __kmalloc_node(size, flags, NUMA_NO_NODE);
76926 }
76927
76928-static __always_inline void *__kmalloc(size_t size, gfp_t flags)
76929+static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
76930 {
76931 return kmalloc(size, flags);
76932 }
76933diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
76934index 027276f..092bfe8 100644
76935--- a/include/linux/slub_def.h
76936+++ b/include/linux/slub_def.h
76937@@ -80,7 +80,7 @@ struct kmem_cache {
76938 struct kmem_cache_order_objects max;
76939 struct kmem_cache_order_objects min;
76940 gfp_t allocflags; /* gfp flags to use on each alloc */
76941- int refcount; /* Refcount for slab cache destroy */
76942+ atomic_t refcount; /* Refcount for slab cache destroy */
76943 void (*ctor)(void *);
76944 int inuse; /* Offset to metadata */
76945 int align; /* Alignment */
76946@@ -105,7 +105,7 @@ struct kmem_cache {
76947 };
76948
76949 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
76950-void *__kmalloc(size_t size, gfp_t flags);
76951+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
76952
76953 static __always_inline void *
76954 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
76955@@ -149,7 +149,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
76956 }
76957 #endif
76958
76959-static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
76960+static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
76961 {
76962 unsigned int order = get_order(size);
76963 return kmalloc_order_trace(size, flags, order);
76964@@ -175,7 +175,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
76965 }
76966
76967 #ifdef CONFIG_NUMA
76968-void *__kmalloc_node(size_t size, gfp_t flags, int node);
76969+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
76970 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
76971
76972 #ifdef CONFIG_TRACING
76973diff --git a/include/linux/smp.h b/include/linux/smp.h
76974index c181399..09d7b92 100644
76975--- a/include/linux/smp.h
76976+++ b/include/linux/smp.h
76977@@ -217,7 +217,9 @@ static inline void kick_all_cpus_sync(void) { }
76978 #endif
76979
76980 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
76981+#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
76982 #define put_cpu() preempt_enable()
76983+#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
76984
76985 /*
76986 * Callback to arch code if there's nosmp or maxcpus=0 on the
76987diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
76988index 54f91d3..be2c379 100644
76989--- a/include/linux/sock_diag.h
76990+++ b/include/linux/sock_diag.h
76991@@ -11,7 +11,7 @@ struct sock;
76992 struct sock_diag_handler {
76993 __u8 family;
76994 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
76995-};
76996+} __do_const;
76997
76998 int sock_diag_register(const struct sock_diag_handler *h);
76999 void sock_diag_unregister(const struct sock_diag_handler *h);
77000diff --git a/include/linux/sonet.h b/include/linux/sonet.h
77001index 680f9a3..f13aeb0 100644
77002--- a/include/linux/sonet.h
77003+++ b/include/linux/sonet.h
77004@@ -7,7 +7,7 @@
77005 #include <uapi/linux/sonet.h>
77006
77007 struct k_sonet_stats {
77008-#define __HANDLE_ITEM(i) atomic_t i
77009+#define __HANDLE_ITEM(i) atomic_unchecked_t i
77010 __SONET_ITEMS
77011 #undef __HANDLE_ITEM
77012 };
77013diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
77014index 07d8e53..dc934c9 100644
77015--- a/include/linux/sunrpc/addr.h
77016+++ b/include/linux/sunrpc/addr.h
77017@@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
77018 {
77019 switch (sap->sa_family) {
77020 case AF_INET:
77021- return ntohs(((struct sockaddr_in *)sap)->sin_port);
77022+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
77023 case AF_INET6:
77024- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
77025+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
77026 }
77027 return 0;
77028 }
77029@@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
77030 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
77031 const struct sockaddr *src)
77032 {
77033- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
77034+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
77035 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
77036
77037 dsin->sin_family = ssin->sin_family;
77038@@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
77039 if (sa->sa_family != AF_INET6)
77040 return 0;
77041
77042- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
77043+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
77044 }
77045
77046 #endif /* _LINUX_SUNRPC_ADDR_H */
77047diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
77048index bfe11be..12bc8c4 100644
77049--- a/include/linux/sunrpc/clnt.h
77050+++ b/include/linux/sunrpc/clnt.h
77051@@ -96,7 +96,7 @@ struct rpc_procinfo {
77052 unsigned int p_timer; /* Which RTT timer to use */
77053 u32 p_statidx; /* Which procedure to account */
77054 const char * p_name; /* name of procedure */
77055-};
77056+} __do_const;
77057
77058 #ifdef __KERNEL__
77059
77060diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
77061index 1f0216b..6a4fa50 100644
77062--- a/include/linux/sunrpc/svc.h
77063+++ b/include/linux/sunrpc/svc.h
77064@@ -411,7 +411,7 @@ struct svc_procedure {
77065 unsigned int pc_count; /* call count */
77066 unsigned int pc_cachetype; /* cache info (NFS) */
77067 unsigned int pc_xdrressize; /* maximum size of XDR reply */
77068-};
77069+} __do_const;
77070
77071 /*
77072 * Function prototypes.
77073diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
77074index 0b8e3e6..33e0a01 100644
77075--- a/include/linux/sunrpc/svc_rdma.h
77076+++ b/include/linux/sunrpc/svc_rdma.h
77077@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
77078 extern unsigned int svcrdma_max_requests;
77079 extern unsigned int svcrdma_max_req_size;
77080
77081-extern atomic_t rdma_stat_recv;
77082-extern atomic_t rdma_stat_read;
77083-extern atomic_t rdma_stat_write;
77084-extern atomic_t rdma_stat_sq_starve;
77085-extern atomic_t rdma_stat_rq_starve;
77086-extern atomic_t rdma_stat_rq_poll;
77087-extern atomic_t rdma_stat_rq_prod;
77088-extern atomic_t rdma_stat_sq_poll;
77089-extern atomic_t rdma_stat_sq_prod;
77090+extern atomic_unchecked_t rdma_stat_recv;
77091+extern atomic_unchecked_t rdma_stat_read;
77092+extern atomic_unchecked_t rdma_stat_write;
77093+extern atomic_unchecked_t rdma_stat_sq_starve;
77094+extern atomic_unchecked_t rdma_stat_rq_starve;
77095+extern atomic_unchecked_t rdma_stat_rq_poll;
77096+extern atomic_unchecked_t rdma_stat_rq_prod;
77097+extern atomic_unchecked_t rdma_stat_sq_poll;
77098+extern atomic_unchecked_t rdma_stat_sq_prod;
77099
77100 #define RPCRDMA_VERSION 1
77101
77102diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
77103index 8d71d65..f79586e 100644
77104--- a/include/linux/sunrpc/svcauth.h
77105+++ b/include/linux/sunrpc/svcauth.h
77106@@ -120,7 +120,7 @@ struct auth_ops {
77107 int (*release)(struct svc_rqst *rq);
77108 void (*domain_release)(struct auth_domain *);
77109 int (*set_client)(struct svc_rqst *rq);
77110-};
77111+} __do_const;
77112
77113 #define SVC_GARBAGE 1
77114 #define SVC_SYSERR 2
77115diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
77116index a5ffd32..0935dea 100644
77117--- a/include/linux/swiotlb.h
77118+++ b/include/linux/swiotlb.h
77119@@ -60,7 +60,8 @@ extern void
77120
77121 extern void
77122 swiotlb_free_coherent(struct device *hwdev, size_t size,
77123- void *vaddr, dma_addr_t dma_handle);
77124+ void *vaddr, dma_addr_t dma_handle,
77125+ struct dma_attrs *attrs);
77126
77127 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
77128 unsigned long offset, size_t size,
77129diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
77130index 84662ec..5271947 100644
77131--- a/include/linux/syscalls.h
77132+++ b/include/linux/syscalls.h
77133@@ -97,8 +97,14 @@ struct sigaltstack;
77134 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
77135
77136 #define __SC_DECL(t, a) t a
77137+#define __TYPE_IS_U(t) (__same_type((t)0, 0UL) || __same_type((t)0, 0U) || __same_type((t)0, (unsigned short)0) || __same_type((t)0, (unsigned char)0))
77138 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
77139-#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
77140+#define __SC_LONG(t, a) __typeof( \
77141+ __builtin_choose_expr( \
77142+ sizeof(t) > sizeof(int), \
77143+ (t) 0, \
77144+ __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
77145+ )) a
77146 #define __SC_CAST(t, a) (t) a
77147 #define __SC_ARGS(t, a) a
77148 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
77149@@ -362,11 +368,11 @@ asmlinkage long sys_sync(void);
77150 asmlinkage long sys_fsync(unsigned int fd);
77151 asmlinkage long sys_fdatasync(unsigned int fd);
77152 asmlinkage long sys_bdflush(int func, long data);
77153-asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
77154- char __user *type, unsigned long flags,
77155+asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
77156+ const char __user *type, unsigned long flags,
77157 void __user *data);
77158-asmlinkage long sys_umount(char __user *name, int flags);
77159-asmlinkage long sys_oldumount(char __user *name);
77160+asmlinkage long sys_umount(const char __user *name, int flags);
77161+asmlinkage long sys_oldumount(const char __user *name);
77162 asmlinkage long sys_truncate(const char __user *path, long length);
77163 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
77164 asmlinkage long sys_stat(const char __user *filename,
77165@@ -578,7 +584,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
77166 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
77167 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
77168 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
77169- struct sockaddr __user *, int);
77170+ struct sockaddr __user *, int) __intentional_overflow(0);
77171 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
77172 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
77173 unsigned int vlen, unsigned flags);
77174diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
77175index 27b3b0b..e093dd9 100644
77176--- a/include/linux/syscore_ops.h
77177+++ b/include/linux/syscore_ops.h
77178@@ -16,7 +16,7 @@ struct syscore_ops {
77179 int (*suspend)(void);
77180 void (*resume)(void);
77181 void (*shutdown)(void);
77182-};
77183+} __do_const;
77184
77185 extern void register_syscore_ops(struct syscore_ops *ops);
77186 extern void unregister_syscore_ops(struct syscore_ops *ops);
77187diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
77188index 14a8ff2..af52bad 100644
77189--- a/include/linux/sysctl.h
77190+++ b/include/linux/sysctl.h
77191@@ -34,13 +34,13 @@ struct ctl_table_root;
77192 struct ctl_table_header;
77193 struct ctl_dir;
77194
77195-typedef struct ctl_table ctl_table;
77196-
77197 typedef int proc_handler (struct ctl_table *ctl, int write,
77198 void __user *buffer, size_t *lenp, loff_t *ppos);
77199
77200 extern int proc_dostring(struct ctl_table *, int,
77201 void __user *, size_t *, loff_t *);
77202+extern int proc_dostring_modpriv(struct ctl_table *, int,
77203+ void __user *, size_t *, loff_t *);
77204 extern int proc_dointvec(struct ctl_table *, int,
77205 void __user *, size_t *, loff_t *);
77206 extern int proc_dointvec_minmax(struct ctl_table *, int,
77207@@ -115,7 +115,9 @@ struct ctl_table
77208 struct ctl_table_poll *poll;
77209 void *extra1;
77210 void *extra2;
77211-};
77212+} __do_const;
77213+typedef struct ctl_table __no_const ctl_table_no_const;
77214+typedef struct ctl_table ctl_table;
77215
77216 struct ctl_node {
77217 struct rb_node node;
77218diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
77219index 9e8a9b5..753de68 100644
77220--- a/include/linux/sysfs.h
77221+++ b/include/linux/sysfs.h
77222@@ -33,7 +33,8 @@ struct attribute {
77223 struct lock_class_key *key;
77224 struct lock_class_key skey;
77225 #endif
77226-};
77227+} __do_const;
77228+typedef struct attribute __no_const attribute_no_const;
77229
77230 /**
77231 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
77232@@ -62,7 +63,8 @@ struct attribute_group {
77233 struct attribute *, int);
77234 struct attribute **attrs;
77235 struct bin_attribute **bin_attrs;
77236-};
77237+} __do_const;
77238+typedef struct attribute_group __no_const attribute_group_no_const;
77239
77240 /**
77241 * Use these macros to make defining attributes easier. See include/linux/device.h
77242@@ -123,7 +125,8 @@ struct bin_attribute {
77243 char *, loff_t, size_t);
77244 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
77245 struct vm_area_struct *vma);
77246-};
77247+} __do_const;
77248+typedef struct bin_attribute __no_const bin_attribute_no_const;
77249
77250 /**
77251 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
77252diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
77253index 7faf933..9b85a0c 100644
77254--- a/include/linux/sysrq.h
77255+++ b/include/linux/sysrq.h
77256@@ -16,6 +16,7 @@
77257
77258 #include <linux/errno.h>
77259 #include <linux/types.h>
77260+#include <linux/compiler.h>
77261
77262 /* Enable/disable SYSRQ support by default (0==no, 1==yes). */
77263 #define SYSRQ_DEFAULT_ENABLE 1
77264@@ -36,7 +37,7 @@ struct sysrq_key_op {
77265 char *help_msg;
77266 char *action_msg;
77267 int enable_mask;
77268-};
77269+} __do_const;
77270
77271 #ifdef CONFIG_MAGIC_SYSRQ
77272
77273diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
77274index e7e0473..7989295 100644
77275--- a/include/linux/thread_info.h
77276+++ b/include/linux/thread_info.h
77277@@ -148,6 +148,15 @@ static inline bool test_and_clear_restore_sigmask(void)
77278 #error "no set_restore_sigmask() provided and default one won't work"
77279 #endif
77280
77281+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
77282+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
77283+{
77284+#ifndef CONFIG_PAX_USERCOPY_DEBUG
77285+ if (!__builtin_constant_p(n))
77286+#endif
77287+ __check_object_size(ptr, n, to_user);
77288+}
77289+
77290 #endif /* __KERNEL__ */
77291
77292 #endif /* _LINUX_THREAD_INFO_H */
77293diff --git a/include/linux/tty.h b/include/linux/tty.h
77294index 01ac30e..bf18a71 100644
77295--- a/include/linux/tty.h
77296+++ b/include/linux/tty.h
77297@@ -194,7 +194,7 @@ struct tty_port {
77298 const struct tty_port_operations *ops; /* Port operations */
77299 spinlock_t lock; /* Lock protecting tty field */
77300 int blocked_open; /* Waiting to open */
77301- int count; /* Usage count */
77302+ atomic_t count; /* Usage count */
77303 wait_queue_head_t open_wait; /* Open waiters */
77304 wait_queue_head_t close_wait; /* Close waiters */
77305 wait_queue_head_t delta_msr_wait; /* Modem status change */
77306@@ -547,7 +547,7 @@ extern int tty_port_open(struct tty_port *port,
77307 struct tty_struct *tty, struct file *filp);
77308 static inline int tty_port_users(struct tty_port *port)
77309 {
77310- return port->count + port->blocked_open;
77311+ return atomic_read(&port->count) + port->blocked_open;
77312 }
77313
77314 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
77315diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
77316index 756a609..b302dd6 100644
77317--- a/include/linux/tty_driver.h
77318+++ b/include/linux/tty_driver.h
77319@@ -285,7 +285,7 @@ struct tty_operations {
77320 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
77321 #endif
77322 const struct file_operations *proc_fops;
77323-};
77324+} __do_const;
77325
77326 struct tty_driver {
77327 int magic; /* magic number for this structure */
77328diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
77329index a1b0489..f02e17c 100644
77330--- a/include/linux/tty_ldisc.h
77331+++ b/include/linux/tty_ldisc.h
77332@@ -198,7 +198,7 @@ struct tty_ldisc_ops {
77333
77334 struct module *owner;
77335
77336- int refcount;
77337+ atomic_t refcount;
77338 };
77339
77340 struct tty_ldisc {
77341diff --git a/include/linux/types.h b/include/linux/types.h
77342index 4d118ba..c3ee9bf 100644
77343--- a/include/linux/types.h
77344+++ b/include/linux/types.h
77345@@ -176,10 +176,26 @@ typedef struct {
77346 int counter;
77347 } atomic_t;
77348
77349+#ifdef CONFIG_PAX_REFCOUNT
77350+typedef struct {
77351+ int counter;
77352+} atomic_unchecked_t;
77353+#else
77354+typedef atomic_t atomic_unchecked_t;
77355+#endif
77356+
77357 #ifdef CONFIG_64BIT
77358 typedef struct {
77359 long counter;
77360 } atomic64_t;
77361+
77362+#ifdef CONFIG_PAX_REFCOUNT
77363+typedef struct {
77364+ long counter;
77365+} atomic64_unchecked_t;
77366+#else
77367+typedef atomic64_t atomic64_unchecked_t;
77368+#endif
77369 #endif
77370
77371 struct list_head {
77372diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
77373index 5ca0951..ab496a5 100644
77374--- a/include/linux/uaccess.h
77375+++ b/include/linux/uaccess.h
77376@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
77377 long ret; \
77378 mm_segment_t old_fs = get_fs(); \
77379 \
77380- set_fs(KERNEL_DS); \
77381 pagefault_disable(); \
77382- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
77383- pagefault_enable(); \
77384+ set_fs(KERNEL_DS); \
77385+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
77386 set_fs(old_fs); \
77387+ pagefault_enable(); \
77388 ret; \
77389 })
77390
77391diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
77392index 8e522cbc..aa8572d 100644
77393--- a/include/linux/uidgid.h
77394+++ b/include/linux/uidgid.h
77395@@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
77396
77397 #endif /* CONFIG_USER_NS */
77398
77399+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
77400+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
77401+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
77402+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
77403+
77404 #endif /* _LINUX_UIDGID_H */
77405diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
77406index 99c1b4d..562e6f3 100644
77407--- a/include/linux/unaligned/access_ok.h
77408+++ b/include/linux/unaligned/access_ok.h
77409@@ -4,34 +4,34 @@
77410 #include <linux/kernel.h>
77411 #include <asm/byteorder.h>
77412
77413-static inline u16 get_unaligned_le16(const void *p)
77414+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
77415 {
77416- return le16_to_cpup((__le16 *)p);
77417+ return le16_to_cpup((const __le16 *)p);
77418 }
77419
77420-static inline u32 get_unaligned_le32(const void *p)
77421+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
77422 {
77423- return le32_to_cpup((__le32 *)p);
77424+ return le32_to_cpup((const __le32 *)p);
77425 }
77426
77427-static inline u64 get_unaligned_le64(const void *p)
77428+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
77429 {
77430- return le64_to_cpup((__le64 *)p);
77431+ return le64_to_cpup((const __le64 *)p);
77432 }
77433
77434-static inline u16 get_unaligned_be16(const void *p)
77435+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
77436 {
77437- return be16_to_cpup((__be16 *)p);
77438+ return be16_to_cpup((const __be16 *)p);
77439 }
77440
77441-static inline u32 get_unaligned_be32(const void *p)
77442+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
77443 {
77444- return be32_to_cpup((__be32 *)p);
77445+ return be32_to_cpup((const __be32 *)p);
77446 }
77447
77448-static inline u64 get_unaligned_be64(const void *p)
77449+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
77450 {
77451- return be64_to_cpup((__be64 *)p);
77452+ return be64_to_cpup((const __be64 *)p);
77453 }
77454
77455 static inline void put_unaligned_le16(u16 val, void *p)
77456diff --git a/include/linux/usb.h b/include/linux/usb.h
77457index 0eec268..4496526 100644
77458--- a/include/linux/usb.h
77459+++ b/include/linux/usb.h
77460@@ -560,7 +560,7 @@ struct usb_device {
77461 int maxchild;
77462
77463 u32 quirks;
77464- atomic_t urbnum;
77465+ atomic_unchecked_t urbnum;
77466
77467 unsigned long active_duration;
77468
77469@@ -1617,7 +1617,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
77470
77471 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
77472 __u8 request, __u8 requesttype, __u16 value, __u16 index,
77473- void *data, __u16 size, int timeout);
77474+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
77475 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
77476 void *data, int len, int *actual_length, int timeout);
77477 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
77478diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
77479index e452ba6..78f8e80 100644
77480--- a/include/linux/usb/renesas_usbhs.h
77481+++ b/include/linux/usb/renesas_usbhs.h
77482@@ -39,7 +39,7 @@ enum {
77483 */
77484 struct renesas_usbhs_driver_callback {
77485 int (*notify_hotplug)(struct platform_device *pdev);
77486-};
77487+} __no_const;
77488
77489 /*
77490 * callback functions for platform
77491diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
77492index 6f8fbcf..8259001 100644
77493--- a/include/linux/vermagic.h
77494+++ b/include/linux/vermagic.h
77495@@ -25,9 +25,35 @@
77496 #define MODULE_ARCH_VERMAGIC ""
77497 #endif
77498
77499+#ifdef CONFIG_PAX_REFCOUNT
77500+#define MODULE_PAX_REFCOUNT "REFCOUNT "
77501+#else
77502+#define MODULE_PAX_REFCOUNT ""
77503+#endif
77504+
77505+#ifdef CONSTIFY_PLUGIN
77506+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
77507+#else
77508+#define MODULE_CONSTIFY_PLUGIN ""
77509+#endif
77510+
77511+#ifdef STACKLEAK_PLUGIN
77512+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
77513+#else
77514+#define MODULE_STACKLEAK_PLUGIN ""
77515+#endif
77516+
77517+#ifdef CONFIG_GRKERNSEC
77518+#define MODULE_GRSEC "GRSEC "
77519+#else
77520+#define MODULE_GRSEC ""
77521+#endif
77522+
77523 #define VERMAGIC_STRING \
77524 UTS_RELEASE " " \
77525 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
77526 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
77527- MODULE_ARCH_VERMAGIC
77528+ MODULE_ARCH_VERMAGIC \
77529+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
77530+ MODULE_GRSEC
77531
77532diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
77533index 4b8a891..c20e936 100644
77534--- a/include/linux/vmalloc.h
77535+++ b/include/linux/vmalloc.h
77536@@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
77537 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
77538 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
77539 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
77540+
77541+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
77542+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
77543+#endif
77544+
77545 /* bits [20..32] reserved for arch specific ioremap internals */
77546
77547 /*
77548@@ -75,7 +80,7 @@ extern void *vmalloc_32_user(unsigned long size);
77549 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
77550 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
77551 unsigned long start, unsigned long end, gfp_t gfp_mask,
77552- pgprot_t prot, int node, const void *caller);
77553+ pgprot_t prot, int node, const void *caller) __size_overflow(1);
77554 extern void vfree(const void *addr);
77555
77556 extern void *vmap(struct page **pages, unsigned int count,
77557@@ -141,8 +146,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
77558 extern void free_vm_area(struct vm_struct *area);
77559
77560 /* for /dev/kmem */
77561-extern long vread(char *buf, char *addr, unsigned long count);
77562-extern long vwrite(char *buf, char *addr, unsigned long count);
77563+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
77564+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
77565
77566 /*
77567 * Internals. Dont't use..
77568diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
77569index c586679..f06b389 100644
77570--- a/include/linux/vmstat.h
77571+++ b/include/linux/vmstat.h
77572@@ -90,18 +90,18 @@ static inline void vm_events_fold_cpu(int cpu)
77573 /*
77574 * Zone based page accounting with per cpu differentials.
77575 */
77576-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
77577+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
77578
77579 static inline void zone_page_state_add(long x, struct zone *zone,
77580 enum zone_stat_item item)
77581 {
77582- atomic_long_add(x, &zone->vm_stat[item]);
77583- atomic_long_add(x, &vm_stat[item]);
77584+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
77585+ atomic_long_add_unchecked(x, &vm_stat[item]);
77586 }
77587
77588 static inline unsigned long global_page_state(enum zone_stat_item item)
77589 {
77590- long x = atomic_long_read(&vm_stat[item]);
77591+ long x = atomic_long_read_unchecked(&vm_stat[item]);
77592 #ifdef CONFIG_SMP
77593 if (x < 0)
77594 x = 0;
77595@@ -112,7 +112,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
77596 static inline unsigned long zone_page_state(struct zone *zone,
77597 enum zone_stat_item item)
77598 {
77599- long x = atomic_long_read(&zone->vm_stat[item]);
77600+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
77601 #ifdef CONFIG_SMP
77602 if (x < 0)
77603 x = 0;
77604@@ -129,7 +129,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
77605 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
77606 enum zone_stat_item item)
77607 {
77608- long x = atomic_long_read(&zone->vm_stat[item]);
77609+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
77610
77611 #ifdef CONFIG_SMP
77612 int cpu;
77613@@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
77614
77615 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
77616 {
77617- atomic_long_inc(&zone->vm_stat[item]);
77618- atomic_long_inc(&vm_stat[item]);
77619+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
77620+ atomic_long_inc_unchecked(&vm_stat[item]);
77621 }
77622
77623 static inline void __inc_zone_page_state(struct page *page,
77624@@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
77625
77626 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
77627 {
77628- atomic_long_dec(&zone->vm_stat[item]);
77629- atomic_long_dec(&vm_stat[item]);
77630+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
77631+ atomic_long_dec_unchecked(&vm_stat[item]);
77632 }
77633
77634 static inline void __dec_zone_page_state(struct page *page,
77635diff --git a/include/linux/xattr.h b/include/linux/xattr.h
77636index fdbafc6..49dfe4f 100644
77637--- a/include/linux/xattr.h
77638+++ b/include/linux/xattr.h
77639@@ -28,7 +28,7 @@ struct xattr_handler {
77640 size_t size, int handler_flags);
77641 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
77642 size_t size, int flags, int handler_flags);
77643-};
77644+} __do_const;
77645
77646 struct xattr {
77647 char *name;
77648@@ -37,6 +37,9 @@ struct xattr {
77649 };
77650
77651 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
77652+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
77653+ssize_t pax_getxattr(struct dentry *, void *, size_t);
77654+#endif
77655 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
77656 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
77657 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
77658diff --git a/include/linux/zlib.h b/include/linux/zlib.h
77659index 9c5a6b4..09c9438 100644
77660--- a/include/linux/zlib.h
77661+++ b/include/linux/zlib.h
77662@@ -31,6 +31,7 @@
77663 #define _ZLIB_H
77664
77665 #include <linux/zconf.h>
77666+#include <linux/compiler.h>
77667
77668 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
77669 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
77670@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
77671
77672 /* basic functions */
77673
77674-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
77675+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
77676 /*
77677 Returns the number of bytes that needs to be allocated for a per-
77678 stream workspace with the specified parameters. A pointer to this
77679diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
77680index c768c9f..bdcaa5a 100644
77681--- a/include/media/v4l2-dev.h
77682+++ b/include/media/v4l2-dev.h
77683@@ -76,7 +76,7 @@ struct v4l2_file_operations {
77684 int (*mmap) (struct file *, struct vm_area_struct *);
77685 int (*open) (struct file *);
77686 int (*release) (struct file *);
77687-};
77688+} __do_const;
77689
77690 /*
77691 * Newer version of video_device, handled by videodev2.c
77692diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
77693index c9b1593..a572459 100644
77694--- a/include/media/v4l2-device.h
77695+++ b/include/media/v4l2-device.h
77696@@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
77697 this function returns 0. If the name ends with a digit (e.g. cx18),
77698 then the name will be set to cx18-0 since cx180 looks really odd. */
77699 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
77700- atomic_t *instance);
77701+ atomic_unchecked_t *instance);
77702
77703 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
77704 Since the parent disappears this ensures that v4l2_dev doesn't have an
77705diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
77706index d9fa68f..45c88d1 100644
77707--- a/include/net/9p/transport.h
77708+++ b/include/net/9p/transport.h
77709@@ -63,7 +63,7 @@ struct p9_trans_module {
77710 int (*cancelled)(struct p9_client *, struct p9_req_t *req);
77711 int (*zc_request)(struct p9_client *, struct p9_req_t *,
77712 char *, char *, int , int, int, int);
77713-};
77714+} __do_const;
77715
77716 void v9fs_register_trans(struct p9_trans_module *m);
77717 void v9fs_unregister_trans(struct p9_trans_module *m);
77718diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
77719index 1a966af..2767cf6 100644
77720--- a/include/net/bluetooth/l2cap.h
77721+++ b/include/net/bluetooth/l2cap.h
77722@@ -551,7 +551,7 @@ struct l2cap_ops {
77723 void (*defer) (struct l2cap_chan *chan);
77724 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
77725 unsigned long len, int nb);
77726-};
77727+} __do_const;
77728
77729 struct l2cap_conn {
77730 struct hci_conn *hcon;
77731diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
77732index f2ae33d..c457cf0 100644
77733--- a/include/net/caif/cfctrl.h
77734+++ b/include/net/caif/cfctrl.h
77735@@ -52,7 +52,7 @@ struct cfctrl_rsp {
77736 void (*radioset_rsp)(void);
77737 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
77738 struct cflayer *client_layer);
77739-};
77740+} __no_const;
77741
77742 /* Link Setup Parameters for CAIF-Links. */
77743 struct cfctrl_link_param {
77744@@ -101,8 +101,8 @@ struct cfctrl_request_info {
77745 struct cfctrl {
77746 struct cfsrvl serv;
77747 struct cfctrl_rsp res;
77748- atomic_t req_seq_no;
77749- atomic_t rsp_seq_no;
77750+ atomic_unchecked_t req_seq_no;
77751+ atomic_unchecked_t rsp_seq_no;
77752 struct list_head list;
77753 /* Protects from simultaneous access to first_req list */
77754 spinlock_t info_list_lock;
77755diff --git a/include/net/flow.h b/include/net/flow.h
77756index 628e11b..4c475df 100644
77757--- a/include/net/flow.h
77758+++ b/include/net/flow.h
77759@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
77760
77761 extern void flow_cache_flush(void);
77762 extern void flow_cache_flush_deferred(void);
77763-extern atomic_t flow_cache_genid;
77764+extern atomic_unchecked_t flow_cache_genid;
77765
77766 #endif
77767diff --git a/include/net/genetlink.h b/include/net/genetlink.h
77768index 8e0b6c8..73cf605 100644
77769--- a/include/net/genetlink.h
77770+++ b/include/net/genetlink.h
77771@@ -120,7 +120,7 @@ struct genl_ops {
77772 struct netlink_callback *cb);
77773 int (*done)(struct netlink_callback *cb);
77774 struct list_head ops_list;
77775-};
77776+} __do_const;
77777
77778 extern int __genl_register_family(struct genl_family *family);
77779
77780diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
77781index 734d9b5..48a9a4b 100644
77782--- a/include/net/gro_cells.h
77783+++ b/include/net/gro_cells.h
77784@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
77785 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
77786
77787 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
77788- atomic_long_inc(&dev->rx_dropped);
77789+ atomic_long_inc_unchecked(&dev->rx_dropped);
77790 kfree_skb(skb);
77791 return;
77792 }
77793diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
77794index de2c785..0588a6b 100644
77795--- a/include/net/inet_connection_sock.h
77796+++ b/include/net/inet_connection_sock.h
77797@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
77798 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
77799 int (*bind_conflict)(const struct sock *sk,
77800 const struct inet_bind_bucket *tb, bool relax);
77801-};
77802+} __do_const;
77803
77804 /** inet_connection_sock - INET connection oriented sock
77805 *
77806diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
77807index 53f464d..0bd0b49 100644
77808--- a/include/net/inetpeer.h
77809+++ b/include/net/inetpeer.h
77810@@ -47,8 +47,8 @@ struct inet_peer {
77811 */
77812 union {
77813 struct {
77814- atomic_t rid; /* Frag reception counter */
77815- atomic_t ip_id_count; /* IP ID for the next packet */
77816+ atomic_unchecked_t rid; /* Frag reception counter */
77817+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
77818 };
77819 struct rcu_head rcu;
77820 struct inet_peer *gc_next;
77821@@ -178,16 +178,13 @@ static inline void inet_peer_refcheck(const struct inet_peer *p)
77822 /* can be called with or without local BH being disabled */
77823 static inline int inet_getid(struct inet_peer *p, int more)
77824 {
77825- int old, new;
77826+ int id;
77827 more++;
77828 inet_peer_refcheck(p);
77829- do {
77830- old = atomic_read(&p->ip_id_count);
77831- new = old + more;
77832- if (!new)
77833- new = 1;
77834- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
77835- return new;
77836+ id = atomic_add_return_unchecked(more, &p->ip_id_count);
77837+ if (!id)
77838+ id = atomic_inc_return_unchecked(&p->ip_id_count);
77839+ return id;
77840 }
77841
77842 #endif /* _NET_INETPEER_H */
77843diff --git a/include/net/ip.h b/include/net/ip.h
77844index a68f838..74518ab 100644
77845--- a/include/net/ip.h
77846+++ b/include/net/ip.h
77847@@ -202,7 +202,7 @@ extern struct local_ports {
77848 } sysctl_local_ports;
77849 extern void inet_get_local_port_range(int *low, int *high);
77850
77851-extern unsigned long *sysctl_local_reserved_ports;
77852+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
77853 static inline int inet_is_reserved_local_port(int port)
77854 {
77855 return test_bit(port, sysctl_local_reserved_ports);
77856diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
77857index cbf2be3..3683f6d 100644
77858--- a/include/net/ip_fib.h
77859+++ b/include/net/ip_fib.h
77860@@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
77861
77862 #define FIB_RES_SADDR(net, res) \
77863 ((FIB_RES_NH(res).nh_saddr_genid == \
77864- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
77865+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
77866 FIB_RES_NH(res).nh_saddr : \
77867 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
77868 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
77869diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
77870index f0d70f0..185f15b 100644
77871--- a/include/net/ip_vs.h
77872+++ b/include/net/ip_vs.h
77873@@ -588,7 +588,7 @@ struct ip_vs_conn {
77874 struct ip_vs_conn *control; /* Master control connection */
77875 atomic_t n_control; /* Number of controlled ones */
77876 struct ip_vs_dest *dest; /* real server */
77877- atomic_t in_pkts; /* incoming packet counter */
77878+ atomic_unchecked_t in_pkts; /* incoming packet counter */
77879
77880 /* packet transmitter for different forwarding methods. If it
77881 mangles the packet, it must return NF_DROP or better NF_STOLEN,
77882@@ -737,7 +737,7 @@ struct ip_vs_dest {
77883 __be16 port; /* port number of the server */
77884 union nf_inet_addr addr; /* IP address of the server */
77885 volatile unsigned int flags; /* dest status flags */
77886- atomic_t conn_flags; /* flags to copy to conn */
77887+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
77888 atomic_t weight; /* server weight */
77889
77890 atomic_t refcnt; /* reference counter */
77891@@ -993,11 +993,11 @@ struct netns_ipvs {
77892 /* ip_vs_lblc */
77893 int sysctl_lblc_expiration;
77894 struct ctl_table_header *lblc_ctl_header;
77895- struct ctl_table *lblc_ctl_table;
77896+ ctl_table_no_const *lblc_ctl_table;
77897 /* ip_vs_lblcr */
77898 int sysctl_lblcr_expiration;
77899 struct ctl_table_header *lblcr_ctl_header;
77900- struct ctl_table *lblcr_ctl_table;
77901+ ctl_table_no_const *lblcr_ctl_table;
77902 /* ip_vs_est */
77903 struct list_head est_list; /* estimator list */
77904 spinlock_t est_lock;
77905diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
77906index 80ffde3..968b0f4 100644
77907--- a/include/net/irda/ircomm_tty.h
77908+++ b/include/net/irda/ircomm_tty.h
77909@@ -35,6 +35,7 @@
77910 #include <linux/termios.h>
77911 #include <linux/timer.h>
77912 #include <linux/tty.h> /* struct tty_struct */
77913+#include <asm/local.h>
77914
77915 #include <net/irda/irias_object.h>
77916 #include <net/irda/ircomm_core.h>
77917diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
77918index 714cc9a..ea05f3e 100644
77919--- a/include/net/iucv/af_iucv.h
77920+++ b/include/net/iucv/af_iucv.h
77921@@ -149,7 +149,7 @@ struct iucv_skb_cb {
77922 struct iucv_sock_list {
77923 struct hlist_head head;
77924 rwlock_t lock;
77925- atomic_t autobind_name;
77926+ atomic_unchecked_t autobind_name;
77927 };
77928
77929 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
77930diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
77931index df83f69..9b640b8 100644
77932--- a/include/net/llc_c_ac.h
77933+++ b/include/net/llc_c_ac.h
77934@@ -87,7 +87,7 @@
77935 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
77936 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
77937
77938-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
77939+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
77940
77941 extern int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
77942 extern int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
77943diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
77944index 6ca3113..f8026dd 100644
77945--- a/include/net/llc_c_ev.h
77946+++ b/include/net/llc_c_ev.h
77947@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
77948 return (struct llc_conn_state_ev *)skb->cb;
77949 }
77950
77951-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
77952-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
77953+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
77954+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
77955
77956 extern int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
77957 extern int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
77958diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
77959index 0e79cfb..f46db31 100644
77960--- a/include/net/llc_c_st.h
77961+++ b/include/net/llc_c_st.h
77962@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
77963 u8 next_state;
77964 llc_conn_ev_qfyr_t *ev_qualifiers;
77965 llc_conn_action_t *ev_actions;
77966-};
77967+} __do_const;
77968
77969 struct llc_conn_state {
77970 u8 current_state;
77971diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
77972index 37a3bbd..55a4241 100644
77973--- a/include/net/llc_s_ac.h
77974+++ b/include/net/llc_s_ac.h
77975@@ -23,7 +23,7 @@
77976 #define SAP_ACT_TEST_IND 9
77977
77978 /* All action functions must look like this */
77979-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
77980+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
77981
77982 extern int llc_sap_action_unitdata_ind(struct llc_sap *sap,
77983 struct sk_buff *skb);
77984diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
77985index 567c681..cd73ac0 100644
77986--- a/include/net/llc_s_st.h
77987+++ b/include/net/llc_s_st.h
77988@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
77989 llc_sap_ev_t ev;
77990 u8 next_state;
77991 llc_sap_action_t *ev_actions;
77992-};
77993+} __do_const;
77994
77995 struct llc_sap_state {
77996 u8 curr_state;
77997diff --git a/include/net/mac80211.h b/include/net/mac80211.h
77998index 551ba6a..11c99c1 100644
77999--- a/include/net/mac80211.h
78000+++ b/include/net/mac80211.h
78001@@ -4221,7 +4221,7 @@ struct rate_control_ops {
78002 void (*add_sta_debugfs)(void *priv, void *priv_sta,
78003 struct dentry *dir);
78004 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
78005-};
78006+} __do_const;
78007
78008 static inline int rate_supported(struct ieee80211_sta *sta,
78009 enum ieee80211_band band,
78010diff --git a/include/net/neighbour.h b/include/net/neighbour.h
78011index 7e748ad..5c6229b 100644
78012--- a/include/net/neighbour.h
78013+++ b/include/net/neighbour.h
78014@@ -123,7 +123,7 @@ struct neigh_ops {
78015 void (*error_report)(struct neighbour *, struct sk_buff *);
78016 int (*output)(struct neighbour *, struct sk_buff *);
78017 int (*connected_output)(struct neighbour *, struct sk_buff *);
78018-};
78019+} __do_const;
78020
78021 struct pneigh_entry {
78022 struct pneigh_entry *next;
78023diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
78024index 84e37b1..8eba19a 100644
78025--- a/include/net/net_namespace.h
78026+++ b/include/net/net_namespace.h
78027@@ -119,8 +119,8 @@ struct net {
78028 struct netns_ipvs *ipvs;
78029 #endif
78030 struct sock *diag_nlsk;
78031- atomic_t rt_genid;
78032- atomic_t fnhe_genid;
78033+ atomic_unchecked_t rt_genid;
78034+ atomic_unchecked_t fnhe_genid;
78035 };
78036
78037 /*
78038@@ -277,7 +277,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
78039 #define __net_init __init
78040 #define __net_exit __exit_refok
78041 #define __net_initdata __initdata
78042+#ifdef CONSTIFY_PLUGIN
78043 #define __net_initconst __initconst
78044+#else
78045+#define __net_initconst __initdata
78046+#endif
78047 #endif
78048
78049 struct pernet_operations {
78050@@ -287,7 +291,7 @@ struct pernet_operations {
78051 void (*exit_batch)(struct list_head *net_exit_list);
78052 int *id;
78053 size_t size;
78054-};
78055+} __do_const;
78056
78057 /*
78058 * Use these carefully. If you implement a network device and it
78059@@ -335,22 +339,22 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
78060
78061 static inline int rt_genid(struct net *net)
78062 {
78063- return atomic_read(&net->rt_genid);
78064+ return atomic_read_unchecked(&net->rt_genid);
78065 }
78066
78067 static inline void rt_genid_bump(struct net *net)
78068 {
78069- atomic_inc(&net->rt_genid);
78070+ atomic_inc_unchecked(&net->rt_genid);
78071 }
78072
78073 static inline int fnhe_genid(struct net *net)
78074 {
78075- return atomic_read(&net->fnhe_genid);
78076+ return atomic_read_unchecked(&net->fnhe_genid);
78077 }
78078
78079 static inline void fnhe_genid_bump(struct net *net)
78080 {
78081- atomic_inc(&net->fnhe_genid);
78082+ atomic_inc_unchecked(&net->fnhe_genid);
78083 }
78084
78085 #endif /* __NET_NET_NAMESPACE_H */
78086diff --git a/include/net/netdma.h b/include/net/netdma.h
78087index 8ba8ce2..99b7fff 100644
78088--- a/include/net/netdma.h
78089+++ b/include/net/netdma.h
78090@@ -24,7 +24,7 @@
78091 #include <linux/dmaengine.h>
78092 #include <linux/skbuff.h>
78093
78094-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
78095+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
78096 struct sk_buff *skb, int offset, struct iovec *to,
78097 size_t len, struct dma_pinned_list *pinned_list);
78098
78099diff --git a/include/net/netlink.h b/include/net/netlink.h
78100index 9690b0f..87aded7 100644
78101--- a/include/net/netlink.h
78102+++ b/include/net/netlink.h
78103@@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
78104 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
78105 {
78106 if (mark)
78107- skb_trim(skb, (unsigned char *) mark - skb->data);
78108+ skb_trim(skb, (const unsigned char *) mark - skb->data);
78109 }
78110
78111 /**
78112diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
78113index c9c0c53..53f24c3 100644
78114--- a/include/net/netns/conntrack.h
78115+++ b/include/net/netns/conntrack.h
78116@@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
78117 struct nf_proto_net {
78118 #ifdef CONFIG_SYSCTL
78119 struct ctl_table_header *ctl_table_header;
78120- struct ctl_table *ctl_table;
78121+ ctl_table_no_const *ctl_table;
78122 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
78123 struct ctl_table_header *ctl_compat_header;
78124- struct ctl_table *ctl_compat_table;
78125+ ctl_table_no_const *ctl_compat_table;
78126 #endif
78127 #endif
78128 unsigned int users;
78129@@ -58,7 +58,7 @@ struct nf_ip_net {
78130 struct nf_icmp_net icmpv6;
78131 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
78132 struct ctl_table_header *ctl_table_header;
78133- struct ctl_table *ctl_table;
78134+ ctl_table_no_const *ctl_table;
78135 #endif
78136 };
78137
78138diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
78139index 2ba9de8..47bd6c7 100644
78140--- a/include/net/netns/ipv4.h
78141+++ b/include/net/netns/ipv4.h
78142@@ -67,7 +67,7 @@ struct netns_ipv4 {
78143 kgid_t sysctl_ping_group_range[2];
78144 long sysctl_tcp_mem[3];
78145
78146- atomic_t dev_addr_genid;
78147+ atomic_unchecked_t dev_addr_genid;
78148
78149 #ifdef CONFIG_IP_MROUTE
78150 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
78151diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
78152index 005e2c2..023d340 100644
78153--- a/include/net/netns/ipv6.h
78154+++ b/include/net/netns/ipv6.h
78155@@ -71,7 +71,7 @@ struct netns_ipv6 {
78156 struct fib_rules_ops *mr6_rules_ops;
78157 #endif
78158 #endif
78159- atomic_t dev_addr_genid;
78160+ atomic_unchecked_t dev_addr_genid;
78161 };
78162
78163 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
78164diff --git a/include/net/ping.h b/include/net/ping.h
78165index 5db0224..0d65365 100644
78166--- a/include/net/ping.h
78167+++ b/include/net/ping.h
78168@@ -55,7 +55,7 @@ struct ping_iter_state {
78169 extern struct proto ping_prot;
78170 extern struct ping_table ping_table;
78171 #if IS_ENABLED(CONFIG_IPV6)
78172-extern struct pingv6_ops pingv6_ops;
78173+extern struct pingv6_ops *pingv6_ops;
78174 #endif
78175
78176 struct pingfakehdr {
78177diff --git a/include/net/protocol.h b/include/net/protocol.h
78178index 047c047..b9dad15 100644
78179--- a/include/net/protocol.h
78180+++ b/include/net/protocol.h
78181@@ -44,7 +44,7 @@ struct net_protocol {
78182 void (*err_handler)(struct sk_buff *skb, u32 info);
78183 unsigned int no_policy:1,
78184 netns_ok:1;
78185-};
78186+} __do_const;
78187
78188 #if IS_ENABLED(CONFIG_IPV6)
78189 struct inet6_protocol {
78190@@ -57,7 +57,7 @@ struct inet6_protocol {
78191 u8 type, u8 code, int offset,
78192 __be32 info);
78193 unsigned int flags; /* INET6_PROTO_xxx */
78194-};
78195+} __do_const;
78196
78197 #define INET6_PROTO_NOPOLICY 0x1
78198 #define INET6_PROTO_FINAL 0x2
78199diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
78200index 7026648..584cc8c 100644
78201--- a/include/net/rtnetlink.h
78202+++ b/include/net/rtnetlink.h
78203@@ -81,7 +81,7 @@ struct rtnl_link_ops {
78204 const struct net_device *dev);
78205 unsigned int (*get_num_tx_queues)(void);
78206 unsigned int (*get_num_rx_queues)(void);
78207-};
78208+} __do_const;
78209
78210 extern int __rtnl_link_register(struct rtnl_link_ops *ops);
78211 extern void __rtnl_link_unregister(struct rtnl_link_ops *ops);
78212diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
78213index 2a82d13..62a31c2 100644
78214--- a/include/net/sctp/sm.h
78215+++ b/include/net/sctp/sm.h
78216@@ -87,7 +87,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
78217 typedef struct {
78218 sctp_state_fn_t *fn;
78219 const char *name;
78220-} sctp_sm_table_entry_t;
78221+} __do_const sctp_sm_table_entry_t;
78222
78223 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
78224 * currently in use.
78225@@ -299,7 +299,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
78226 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
78227
78228 /* Extern declarations for major data structures. */
78229-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
78230+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
78231
78232
78233 /* Get the size of a DATA chunk payload. */
78234diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
78235index e745c92..3641448 100644
78236--- a/include/net/sctp/structs.h
78237+++ b/include/net/sctp/structs.h
78238@@ -516,7 +516,7 @@ struct sctp_pf {
78239 struct sctp_association *asoc);
78240 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
78241 struct sctp_af *af;
78242-};
78243+} __do_const;
78244
78245
78246 /* Structure to track chunk fragments that have been acked, but peer
78247diff --git a/include/net/sock.h b/include/net/sock.h
78248index 31d5cfb..9ee0602 100644
78249--- a/include/net/sock.h
78250+++ b/include/net/sock.h
78251@@ -331,7 +331,7 @@ struct sock {
78252 unsigned int sk_napi_id;
78253 unsigned int sk_ll_usec;
78254 #endif
78255- atomic_t sk_drops;
78256+ atomic_unchecked_t sk_drops;
78257 int sk_rcvbuf;
78258
78259 struct sk_filter __rcu *sk_filter;
78260@@ -1803,7 +1803,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
78261 }
78262
78263 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
78264- char __user *from, char *to,
78265+ char __user *from, unsigned char *to,
78266 int copy, int offset)
78267 {
78268 if (skb->ip_summed == CHECKSUM_NONE) {
78269@@ -2065,7 +2065,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
78270 }
78271 }
78272
78273-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
78274+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
78275
78276 /**
78277 * sk_page_frag - return an appropriate page_frag
78278diff --git a/include/net/tcp.h b/include/net/tcp.h
78279index d198005..c974a393 100644
78280--- a/include/net/tcp.h
78281+++ b/include/net/tcp.h
78282@@ -521,7 +521,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
78283 extern void tcp_xmit_retransmit_queue(struct sock *);
78284 extern void tcp_simple_retransmit(struct sock *);
78285 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
78286-extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
78287+extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
78288
78289 extern void tcp_send_probe0(struct sock *);
78290 extern void tcp_send_partial(struct sock *);
78291@@ -694,8 +694,8 @@ struct tcp_skb_cb {
78292 struct inet6_skb_parm h6;
78293 #endif
78294 } header; /* For incoming frames */
78295- __u32 seq; /* Starting sequence number */
78296- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
78297+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
78298+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
78299 __u32 when; /* used to compute rtt's */
78300 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
78301
78302@@ -709,7 +709,7 @@ struct tcp_skb_cb {
78303
78304 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
78305 /* 1 byte hole */
78306- __u32 ack_seq; /* Sequence number ACK'd */
78307+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
78308 };
78309
78310 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
78311diff --git a/include/net/xfrm.h b/include/net/xfrm.h
78312index e823786..53b0608 100644
78313--- a/include/net/xfrm.h
78314+++ b/include/net/xfrm.h
78315@@ -287,7 +287,6 @@ struct xfrm_dst;
78316 struct xfrm_policy_afinfo {
78317 unsigned short family;
78318 struct dst_ops *dst_ops;
78319- void (*garbage_collect)(struct net *net);
78320 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
78321 const xfrm_address_t *saddr,
78322 const xfrm_address_t *daddr);
78323@@ -305,7 +304,7 @@ struct xfrm_policy_afinfo {
78324 struct net_device *dev,
78325 const struct flowi *fl);
78326 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
78327-};
78328+} __do_const;
78329
78330 extern int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
78331 extern int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
78332@@ -342,7 +341,7 @@ struct xfrm_state_afinfo {
78333 int (*transport_finish)(struct sk_buff *skb,
78334 int async);
78335 void (*local_error)(struct sk_buff *skb, u32 mtu);
78336-};
78337+} __do_const;
78338
78339 extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
78340 extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
78341@@ -427,7 +426,7 @@ struct xfrm_mode {
78342 struct module *owner;
78343 unsigned int encap;
78344 int flags;
78345-};
78346+} __do_const;
78347
78348 /* Flags for xfrm_mode. */
78349 enum {
78350@@ -524,7 +523,7 @@ struct xfrm_policy {
78351 struct timer_list timer;
78352
78353 struct flow_cache_object flo;
78354- atomic_t genid;
78355+ atomic_unchecked_t genid;
78356 u32 priority;
78357 u32 index;
78358 struct xfrm_mark mark;
78359@@ -1164,6 +1163,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
78360 }
78361
78362 extern void xfrm_garbage_collect(struct net *net);
78363+extern void xfrm_garbage_collect_deferred(struct net *net);
78364
78365 #else
78366
78367@@ -1202,6 +1202,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
78368 static inline void xfrm_garbage_collect(struct net *net)
78369 {
78370 }
78371+static inline void xfrm_garbage_collect_deferred(struct net *net)
78372+{
78373+}
78374 #endif
78375
78376 static __inline__
78377diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
78378index 1a046b1..ee0bef0 100644
78379--- a/include/rdma/iw_cm.h
78380+++ b/include/rdma/iw_cm.h
78381@@ -122,7 +122,7 @@ struct iw_cm_verbs {
78382 int backlog);
78383
78384 int (*destroy_listen)(struct iw_cm_id *cm_id);
78385-};
78386+} __no_const;
78387
78388 /**
78389 * iw_create_cm_id - Create an IW CM identifier.
78390diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
78391index e1379b4..67eafbe 100644
78392--- a/include/scsi/libfc.h
78393+++ b/include/scsi/libfc.h
78394@@ -762,6 +762,7 @@ struct libfc_function_template {
78395 */
78396 void (*disc_stop_final) (struct fc_lport *);
78397 };
78398+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
78399
78400 /**
78401 * struct fc_disc - Discovery context
78402@@ -866,7 +867,7 @@ struct fc_lport {
78403 struct fc_vport *vport;
78404
78405 /* Operational Information */
78406- struct libfc_function_template tt;
78407+ libfc_function_template_no_const tt;
78408 u8 link_up;
78409 u8 qfull;
78410 enum fc_lport_state state;
78411diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
78412index a44954c..5da04b2 100644
78413--- a/include/scsi/scsi_device.h
78414+++ b/include/scsi/scsi_device.h
78415@@ -172,9 +172,9 @@ struct scsi_device {
78416 unsigned int max_device_blocked; /* what device_blocked counts down from */
78417 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
78418
78419- atomic_t iorequest_cnt;
78420- atomic_t iodone_cnt;
78421- atomic_t ioerr_cnt;
78422+ atomic_unchecked_t iorequest_cnt;
78423+ atomic_unchecked_t iodone_cnt;
78424+ atomic_unchecked_t ioerr_cnt;
78425
78426 struct device sdev_gendev,
78427 sdev_dev;
78428diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
78429index b797e8f..8e2c3aa 100644
78430--- a/include/scsi/scsi_transport_fc.h
78431+++ b/include/scsi/scsi_transport_fc.h
78432@@ -751,7 +751,8 @@ struct fc_function_template {
78433 unsigned long show_host_system_hostname:1;
78434
78435 unsigned long disable_target_scan:1;
78436-};
78437+} __do_const;
78438+typedef struct fc_function_template __no_const fc_function_template_no_const;
78439
78440
78441 /**
78442diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
78443index 9031a26..750d592 100644
78444--- a/include/sound/compress_driver.h
78445+++ b/include/sound/compress_driver.h
78446@@ -128,7 +128,7 @@ struct snd_compr_ops {
78447 struct snd_compr_caps *caps);
78448 int (*get_codec_caps) (struct snd_compr_stream *stream,
78449 struct snd_compr_codec_caps *codec);
78450-};
78451+} __no_const;
78452
78453 /**
78454 * struct snd_compr: Compressed device
78455diff --git a/include/sound/soc.h b/include/sound/soc.h
78456index 6eabee7..58afb50 100644
78457--- a/include/sound/soc.h
78458+++ b/include/sound/soc.h
78459@@ -783,7 +783,7 @@ struct snd_soc_codec_driver {
78460 /* probe ordering - for components with runtime dependencies */
78461 int probe_order;
78462 int remove_order;
78463-};
78464+} __do_const;
78465
78466 /* SoC platform interface */
78467 struct snd_soc_platform_driver {
78468@@ -829,7 +829,7 @@ struct snd_soc_platform_driver {
78469 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
78470 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
78471 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
78472-};
78473+} __do_const;
78474
78475 struct snd_soc_platform {
78476 const char *name;
78477diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
78478index e34fc90..ecefa2c 100644
78479--- a/include/target/target_core_base.h
78480+++ b/include/target/target_core_base.h
78481@@ -643,7 +643,7 @@ struct se_device {
78482 spinlock_t stats_lock;
78483 /* Active commands on this virtual SE device */
78484 atomic_t simple_cmds;
78485- atomic_t dev_ordered_id;
78486+ atomic_unchecked_t dev_ordered_id;
78487 atomic_t dev_ordered_sync;
78488 atomic_t dev_qf_count;
78489 int export_count;
78490diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
78491new file mode 100644
78492index 0000000..fb634b7
78493--- /dev/null
78494+++ b/include/trace/events/fs.h
78495@@ -0,0 +1,53 @@
78496+#undef TRACE_SYSTEM
78497+#define TRACE_SYSTEM fs
78498+
78499+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
78500+#define _TRACE_FS_H
78501+
78502+#include <linux/fs.h>
78503+#include <linux/tracepoint.h>
78504+
78505+TRACE_EVENT(do_sys_open,
78506+
78507+ TP_PROTO(const char *filename, int flags, int mode),
78508+
78509+ TP_ARGS(filename, flags, mode),
78510+
78511+ TP_STRUCT__entry(
78512+ __string( filename, filename )
78513+ __field( int, flags )
78514+ __field( int, mode )
78515+ ),
78516+
78517+ TP_fast_assign(
78518+ __assign_str(filename, filename);
78519+ __entry->flags = flags;
78520+ __entry->mode = mode;
78521+ ),
78522+
78523+ TP_printk("\"%s\" %x %o",
78524+ __get_str(filename), __entry->flags, __entry->mode)
78525+);
78526+
78527+TRACE_EVENT(open_exec,
78528+
78529+ TP_PROTO(const char *filename),
78530+
78531+ TP_ARGS(filename),
78532+
78533+ TP_STRUCT__entry(
78534+ __string( filename, filename )
78535+ ),
78536+
78537+ TP_fast_assign(
78538+ __assign_str(filename, filename);
78539+ ),
78540+
78541+ TP_printk("\"%s\"",
78542+ __get_str(filename))
78543+);
78544+
78545+#endif /* _TRACE_FS_H */
78546+
78547+/* This part must be outside protection */
78548+#include <trace/define_trace.h>
78549diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
78550index 1c09820..7f5ec79 100644
78551--- a/include/trace/events/irq.h
78552+++ b/include/trace/events/irq.h
78553@@ -36,7 +36,7 @@ struct softirq_action;
78554 */
78555 TRACE_EVENT(irq_handler_entry,
78556
78557- TP_PROTO(int irq, struct irqaction *action),
78558+ TP_PROTO(int irq, const struct irqaction *action),
78559
78560 TP_ARGS(irq, action),
78561
78562@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
78563 */
78564 TRACE_EVENT(irq_handler_exit,
78565
78566- TP_PROTO(int irq, struct irqaction *action, int ret),
78567+ TP_PROTO(int irq, const struct irqaction *action, int ret),
78568
78569 TP_ARGS(irq, action, ret),
78570
78571diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
78572index 7caf44c..23c6f27 100644
78573--- a/include/uapi/linux/a.out.h
78574+++ b/include/uapi/linux/a.out.h
78575@@ -39,6 +39,14 @@ enum machine_type {
78576 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
78577 };
78578
78579+/* Constants for the N_FLAGS field */
78580+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
78581+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
78582+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
78583+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
78584+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
78585+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
78586+
78587 #if !defined (N_MAGIC)
78588 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
78589 #endif
78590diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
78591index d876736..ccce5c0 100644
78592--- a/include/uapi/linux/byteorder/little_endian.h
78593+++ b/include/uapi/linux/byteorder/little_endian.h
78594@@ -42,51 +42,51 @@
78595
78596 static inline __le64 __cpu_to_le64p(const __u64 *p)
78597 {
78598- return (__force __le64)*p;
78599+ return (__force const __le64)*p;
78600 }
78601-static inline __u64 __le64_to_cpup(const __le64 *p)
78602+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
78603 {
78604- return (__force __u64)*p;
78605+ return (__force const __u64)*p;
78606 }
78607 static inline __le32 __cpu_to_le32p(const __u32 *p)
78608 {
78609- return (__force __le32)*p;
78610+ return (__force const __le32)*p;
78611 }
78612 static inline __u32 __le32_to_cpup(const __le32 *p)
78613 {
78614- return (__force __u32)*p;
78615+ return (__force const __u32)*p;
78616 }
78617 static inline __le16 __cpu_to_le16p(const __u16 *p)
78618 {
78619- return (__force __le16)*p;
78620+ return (__force const __le16)*p;
78621 }
78622 static inline __u16 __le16_to_cpup(const __le16 *p)
78623 {
78624- return (__force __u16)*p;
78625+ return (__force const __u16)*p;
78626 }
78627 static inline __be64 __cpu_to_be64p(const __u64 *p)
78628 {
78629- return (__force __be64)__swab64p(p);
78630+ return (__force const __be64)__swab64p(p);
78631 }
78632 static inline __u64 __be64_to_cpup(const __be64 *p)
78633 {
78634- return __swab64p((__u64 *)p);
78635+ return __swab64p((const __u64 *)p);
78636 }
78637 static inline __be32 __cpu_to_be32p(const __u32 *p)
78638 {
78639- return (__force __be32)__swab32p(p);
78640+ return (__force const __be32)__swab32p(p);
78641 }
78642-static inline __u32 __be32_to_cpup(const __be32 *p)
78643+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
78644 {
78645- return __swab32p((__u32 *)p);
78646+ return __swab32p((const __u32 *)p);
78647 }
78648 static inline __be16 __cpu_to_be16p(const __u16 *p)
78649 {
78650- return (__force __be16)__swab16p(p);
78651+ return (__force const __be16)__swab16p(p);
78652 }
78653 static inline __u16 __be16_to_cpup(const __be16 *p)
78654 {
78655- return __swab16p((__u16 *)p);
78656+ return __swab16p((const __u16 *)p);
78657 }
78658 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
78659 #define __le64_to_cpus(x) do { (void)(x); } while (0)
78660diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
78661index ef6103b..d4e65dd 100644
78662--- a/include/uapi/linux/elf.h
78663+++ b/include/uapi/linux/elf.h
78664@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
78665 #define PT_GNU_EH_FRAME 0x6474e550
78666
78667 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
78668+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
78669+
78670+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
78671+
78672+/* Constants for the e_flags field */
78673+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
78674+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
78675+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
78676+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
78677+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
78678+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
78679
78680 /*
78681 * Extended Numbering
78682@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
78683 #define DT_DEBUG 21
78684 #define DT_TEXTREL 22
78685 #define DT_JMPREL 23
78686+#define DT_FLAGS 30
78687+ #define DF_TEXTREL 0x00000004
78688 #define DT_ENCODING 32
78689 #define OLD_DT_LOOS 0x60000000
78690 #define DT_LOOS 0x6000000d
78691@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
78692 #define PF_W 0x2
78693 #define PF_X 0x1
78694
78695+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
78696+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
78697+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
78698+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
78699+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
78700+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
78701+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
78702+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
78703+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
78704+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
78705+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
78706+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
78707+
78708 typedef struct elf32_phdr{
78709 Elf32_Word p_type;
78710 Elf32_Off p_offset;
78711@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
78712 #define EI_OSABI 7
78713 #define EI_PAD 8
78714
78715+#define EI_PAX 14
78716+
78717 #define ELFMAG0 0x7f /* EI_MAG */
78718 #define ELFMAG1 'E'
78719 #define ELFMAG2 'L'
78720diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
78721index aa169c4..6a2771d 100644
78722--- a/include/uapi/linux/personality.h
78723+++ b/include/uapi/linux/personality.h
78724@@ -30,6 +30,7 @@ enum {
78725 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
78726 ADDR_NO_RANDOMIZE | \
78727 ADDR_COMPAT_LAYOUT | \
78728+ ADDR_LIMIT_3GB | \
78729 MMAP_PAGE_ZERO)
78730
78731 /*
78732diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
78733index 7530e74..e714828 100644
78734--- a/include/uapi/linux/screen_info.h
78735+++ b/include/uapi/linux/screen_info.h
78736@@ -43,7 +43,8 @@ struct screen_info {
78737 __u16 pages; /* 0x32 */
78738 __u16 vesa_attributes; /* 0x34 */
78739 __u32 capabilities; /* 0x36 */
78740- __u8 _reserved[6]; /* 0x3a */
78741+ __u16 vesapm_size; /* 0x3a */
78742+ __u8 _reserved[4]; /* 0x3c */
78743 } __attribute__((packed));
78744
78745 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
78746diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
78747index 0e011eb..82681b1 100644
78748--- a/include/uapi/linux/swab.h
78749+++ b/include/uapi/linux/swab.h
78750@@ -43,7 +43,7 @@
78751 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
78752 */
78753
78754-static inline __attribute_const__ __u16 __fswab16(__u16 val)
78755+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
78756 {
78757 #ifdef __HAVE_BUILTIN_BSWAP16__
78758 return __builtin_bswap16(val);
78759@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
78760 #endif
78761 }
78762
78763-static inline __attribute_const__ __u32 __fswab32(__u32 val)
78764+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
78765 {
78766 #ifdef __HAVE_BUILTIN_BSWAP32__
78767 return __builtin_bswap32(val);
78768@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
78769 #endif
78770 }
78771
78772-static inline __attribute_const__ __u64 __fswab64(__u64 val)
78773+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
78774 {
78775 #ifdef __HAVE_BUILTIN_BSWAP64__
78776 return __builtin_bswap64(val);
78777diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
78778index 6d67213..8dab561 100644
78779--- a/include/uapi/linux/sysctl.h
78780+++ b/include/uapi/linux/sysctl.h
78781@@ -155,7 +155,11 @@ enum
78782 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
78783 };
78784
78785-
78786+#ifdef CONFIG_PAX_SOFTMODE
78787+enum {
78788+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
78789+};
78790+#endif
78791
78792 /* CTL_VM names: */
78793 enum
78794diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
78795index e4629b9..6958086 100644
78796--- a/include/uapi/linux/xattr.h
78797+++ b/include/uapi/linux/xattr.h
78798@@ -63,5 +63,9 @@
78799 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
78800 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
78801
78802+/* User namespace */
78803+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
78804+#define XATTR_PAX_FLAGS_SUFFIX "flags"
78805+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
78806
78807 #endif /* _UAPI_LINUX_XATTR_H */
78808diff --git a/include/video/udlfb.h b/include/video/udlfb.h
78809index f9466fa..f4e2b81 100644
78810--- a/include/video/udlfb.h
78811+++ b/include/video/udlfb.h
78812@@ -53,10 +53,10 @@ struct dlfb_data {
78813 u32 pseudo_palette[256];
78814 int blank_mode; /*one of FB_BLANK_ */
78815 /* blit-only rendering path metrics, exposed through sysfs */
78816- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
78817- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
78818- atomic_t bytes_sent; /* to usb, after compression including overhead */
78819- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
78820+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
78821+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
78822+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
78823+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
78824 };
78825
78826 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
78827diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
78828index 30f5362..8ed8ac9 100644
78829--- a/include/video/uvesafb.h
78830+++ b/include/video/uvesafb.h
78831@@ -122,6 +122,7 @@ struct uvesafb_par {
78832 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
78833 u8 pmi_setpal; /* PMI for palette changes */
78834 u16 *pmi_base; /* protected mode interface location */
78835+ u8 *pmi_code; /* protected mode code location */
78836 void *pmi_start;
78837 void *pmi_pal;
78838 u8 *vbe_state_orig; /*
78839diff --git a/init/Kconfig b/init/Kconfig
78840index fed81b5..0d3b964 100644
78841--- a/init/Kconfig
78842+++ b/init/Kconfig
78843@@ -1069,6 +1069,7 @@ endif # CGROUPS
78844
78845 config CHECKPOINT_RESTORE
78846 bool "Checkpoint/restore support" if EXPERT
78847+ depends on !GRKERNSEC
78848 default n
78849 help
78850 Enables additional kernel features in a sake of checkpoint/restore.
78851@@ -1553,7 +1554,7 @@ config SLUB_DEBUG
78852
78853 config COMPAT_BRK
78854 bool "Disable heap randomization"
78855- default y
78856+ default n
78857 help
78858 Randomizing heap placement makes heap exploits harder, but it
78859 also breaks ancient binaries (including anything libc5 based).
78860@@ -1827,7 +1828,7 @@ config INIT_ALL_POSSIBLE
78861 config STOP_MACHINE
78862 bool
78863 default y
78864- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
78865+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
78866 help
78867 Need stop_machine() primitive.
78868
78869diff --git a/init/Makefile b/init/Makefile
78870index 7bc47ee..6da2dc7 100644
78871--- a/init/Makefile
78872+++ b/init/Makefile
78873@@ -2,6 +2,9 @@
78874 # Makefile for the linux kernel.
78875 #
78876
78877+ccflags-y := $(GCC_PLUGINS_CFLAGS)
78878+asflags-y := $(GCC_PLUGINS_AFLAGS)
78879+
78880 obj-y := main.o version.o mounts.o
78881 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
78882 obj-y += noinitramfs.o
78883diff --git a/init/do_mounts.c b/init/do_mounts.c
78884index 816014c..c2054db 100644
78885--- a/init/do_mounts.c
78886+++ b/init/do_mounts.c
78887@@ -355,11 +355,11 @@ static void __init get_fs_names(char *page)
78888 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
78889 {
78890 struct super_block *s;
78891- int err = sys_mount(name, "/root", fs, flags, data);
78892+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
78893 if (err)
78894 return err;
78895
78896- sys_chdir("/root");
78897+ sys_chdir((const char __force_user *)"/root");
78898 s = current->fs->pwd.dentry->d_sb;
78899 ROOT_DEV = s->s_dev;
78900 printk(KERN_INFO
78901@@ -480,18 +480,18 @@ void __init change_floppy(char *fmt, ...)
78902 va_start(args, fmt);
78903 vsprintf(buf, fmt, args);
78904 va_end(args);
78905- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
78906+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
78907 if (fd >= 0) {
78908 sys_ioctl(fd, FDEJECT, 0);
78909 sys_close(fd);
78910 }
78911 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
78912- fd = sys_open("/dev/console", O_RDWR, 0);
78913+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
78914 if (fd >= 0) {
78915 sys_ioctl(fd, TCGETS, (long)&termios);
78916 termios.c_lflag &= ~ICANON;
78917 sys_ioctl(fd, TCSETSF, (long)&termios);
78918- sys_read(fd, &c, 1);
78919+ sys_read(fd, (char __user *)&c, 1);
78920 termios.c_lflag |= ICANON;
78921 sys_ioctl(fd, TCSETSF, (long)&termios);
78922 sys_close(fd);
78923@@ -585,6 +585,6 @@ void __init prepare_namespace(void)
78924 mount_root();
78925 out:
78926 devtmpfs_mount("dev");
78927- sys_mount(".", "/", NULL, MS_MOVE, NULL);
78928- sys_chroot(".");
78929+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
78930+ sys_chroot((const char __force_user *)".");
78931 }
78932diff --git a/init/do_mounts.h b/init/do_mounts.h
78933index f5b978a..69dbfe8 100644
78934--- a/init/do_mounts.h
78935+++ b/init/do_mounts.h
78936@@ -15,15 +15,15 @@ extern int root_mountflags;
78937
78938 static inline int create_dev(char *name, dev_t dev)
78939 {
78940- sys_unlink(name);
78941- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
78942+ sys_unlink((char __force_user *)name);
78943+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
78944 }
78945
78946 #if BITS_PER_LONG == 32
78947 static inline u32 bstat(char *name)
78948 {
78949 struct stat64 stat;
78950- if (sys_stat64(name, &stat) != 0)
78951+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
78952 return 0;
78953 if (!S_ISBLK(stat.st_mode))
78954 return 0;
78955@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
78956 static inline u32 bstat(char *name)
78957 {
78958 struct stat stat;
78959- if (sys_newstat(name, &stat) != 0)
78960+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
78961 return 0;
78962 if (!S_ISBLK(stat.st_mode))
78963 return 0;
78964diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
78965index 3e0878e..8a9d7a0 100644
78966--- a/init/do_mounts_initrd.c
78967+++ b/init/do_mounts_initrd.c
78968@@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
78969 {
78970 sys_unshare(CLONE_FS | CLONE_FILES);
78971 /* stdin/stdout/stderr for /linuxrc */
78972- sys_open("/dev/console", O_RDWR, 0);
78973+ sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
78974 sys_dup(0);
78975 sys_dup(0);
78976 /* move initrd over / and chdir/chroot in initrd root */
78977- sys_chdir("/root");
78978- sys_mount(".", "/", NULL, MS_MOVE, NULL);
78979- sys_chroot(".");
78980+ sys_chdir((const char __force_user *)"/root");
78981+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
78982+ sys_chroot((const char __force_user *)".");
78983 sys_setsid();
78984 return 0;
78985 }
78986@@ -59,8 +59,8 @@ static void __init handle_initrd(void)
78987 create_dev("/dev/root.old", Root_RAM0);
78988 /* mount initrd on rootfs' /root */
78989 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
78990- sys_mkdir("/old", 0700);
78991- sys_chdir("/old");
78992+ sys_mkdir((const char __force_user *)"/old", 0700);
78993+ sys_chdir((const char __force_user *)"/old");
78994
78995 /* try loading default modules from initrd */
78996 load_default_modules();
78997@@ -80,31 +80,31 @@ static void __init handle_initrd(void)
78998 current->flags &= ~PF_FREEZER_SKIP;
78999
79000 /* move initrd to rootfs' /old */
79001- sys_mount("..", ".", NULL, MS_MOVE, NULL);
79002+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
79003 /* switch root and cwd back to / of rootfs */
79004- sys_chroot("..");
79005+ sys_chroot((const char __force_user *)"..");
79006
79007 if (new_decode_dev(real_root_dev) == Root_RAM0) {
79008- sys_chdir("/old");
79009+ sys_chdir((const char __force_user *)"/old");
79010 return;
79011 }
79012
79013- sys_chdir("/");
79014+ sys_chdir((const char __force_user *)"/");
79015 ROOT_DEV = new_decode_dev(real_root_dev);
79016 mount_root();
79017
79018 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
79019- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
79020+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
79021 if (!error)
79022 printk("okay\n");
79023 else {
79024- int fd = sys_open("/dev/root.old", O_RDWR, 0);
79025+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
79026 if (error == -ENOENT)
79027 printk("/initrd does not exist. Ignored.\n");
79028 else
79029 printk("failed\n");
79030 printk(KERN_NOTICE "Unmounting old root\n");
79031- sys_umount("/old", MNT_DETACH);
79032+ sys_umount((char __force_user *)"/old", MNT_DETACH);
79033 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
79034 if (fd < 0) {
79035 error = fd;
79036@@ -127,11 +127,11 @@ int __init initrd_load(void)
79037 * mounted in the normal path.
79038 */
79039 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
79040- sys_unlink("/initrd.image");
79041+ sys_unlink((const char __force_user *)"/initrd.image");
79042 handle_initrd();
79043 return 1;
79044 }
79045 }
79046- sys_unlink("/initrd.image");
79047+ sys_unlink((const char __force_user *)"/initrd.image");
79048 return 0;
79049 }
79050diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
79051index 8cb6db5..d729f50 100644
79052--- a/init/do_mounts_md.c
79053+++ b/init/do_mounts_md.c
79054@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
79055 partitioned ? "_d" : "", minor,
79056 md_setup_args[ent].device_names);
79057
79058- fd = sys_open(name, 0, 0);
79059+ fd = sys_open((char __force_user *)name, 0, 0);
79060 if (fd < 0) {
79061 printk(KERN_ERR "md: open failed - cannot start "
79062 "array %s\n", name);
79063@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
79064 * array without it
79065 */
79066 sys_close(fd);
79067- fd = sys_open(name, 0, 0);
79068+ fd = sys_open((char __force_user *)name, 0, 0);
79069 sys_ioctl(fd, BLKRRPART, 0);
79070 }
79071 sys_close(fd);
79072@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
79073
79074 wait_for_device_probe();
79075
79076- fd = sys_open("/dev/md0", 0, 0);
79077+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
79078 if (fd >= 0) {
79079 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
79080 sys_close(fd);
79081diff --git a/init/init_task.c b/init/init_task.c
79082index ba0a7f36..2bcf1d5 100644
79083--- a/init/init_task.c
79084+++ b/init/init_task.c
79085@@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
79086 * Initial thread structure. Alignment of this is handled by a special
79087 * linker map entry.
79088 */
79089+#ifdef CONFIG_X86
79090+union thread_union init_thread_union __init_task_data;
79091+#else
79092 union thread_union init_thread_union __init_task_data =
79093 { INIT_THREAD_INFO(init_task) };
79094+#endif
79095diff --git a/init/initramfs.c b/init/initramfs.c
79096index a67ef9d..2d17ed9 100644
79097--- a/init/initramfs.c
79098+++ b/init/initramfs.c
79099@@ -84,7 +84,7 @@ static void __init free_hash(void)
79100 }
79101 }
79102
79103-static long __init do_utime(char *filename, time_t mtime)
79104+static long __init do_utime(char __force_user *filename, time_t mtime)
79105 {
79106 struct timespec t[2];
79107
79108@@ -119,7 +119,7 @@ static void __init dir_utime(void)
79109 struct dir_entry *de, *tmp;
79110 list_for_each_entry_safe(de, tmp, &dir_list, list) {
79111 list_del(&de->list);
79112- do_utime(de->name, de->mtime);
79113+ do_utime((char __force_user *)de->name, de->mtime);
79114 kfree(de->name);
79115 kfree(de);
79116 }
79117@@ -281,7 +281,7 @@ static int __init maybe_link(void)
79118 if (nlink >= 2) {
79119 char *old = find_link(major, minor, ino, mode, collected);
79120 if (old)
79121- return (sys_link(old, collected) < 0) ? -1 : 1;
79122+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
79123 }
79124 return 0;
79125 }
79126@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
79127 {
79128 struct stat st;
79129
79130- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
79131+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
79132 if (S_ISDIR(st.st_mode))
79133- sys_rmdir(path);
79134+ sys_rmdir((char __force_user *)path);
79135 else
79136- sys_unlink(path);
79137+ sys_unlink((char __force_user *)path);
79138 }
79139 }
79140
79141@@ -315,7 +315,7 @@ static int __init do_name(void)
79142 int openflags = O_WRONLY|O_CREAT;
79143 if (ml != 1)
79144 openflags |= O_TRUNC;
79145- wfd = sys_open(collected, openflags, mode);
79146+ wfd = sys_open((char __force_user *)collected, openflags, mode);
79147
79148 if (wfd >= 0) {
79149 sys_fchown(wfd, uid, gid);
79150@@ -327,17 +327,17 @@ static int __init do_name(void)
79151 }
79152 }
79153 } else if (S_ISDIR(mode)) {
79154- sys_mkdir(collected, mode);
79155- sys_chown(collected, uid, gid);
79156- sys_chmod(collected, mode);
79157+ sys_mkdir((char __force_user *)collected, mode);
79158+ sys_chown((char __force_user *)collected, uid, gid);
79159+ sys_chmod((char __force_user *)collected, mode);
79160 dir_add(collected, mtime);
79161 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
79162 S_ISFIFO(mode) || S_ISSOCK(mode)) {
79163 if (maybe_link() == 0) {
79164- sys_mknod(collected, mode, rdev);
79165- sys_chown(collected, uid, gid);
79166- sys_chmod(collected, mode);
79167- do_utime(collected, mtime);
79168+ sys_mknod((char __force_user *)collected, mode, rdev);
79169+ sys_chown((char __force_user *)collected, uid, gid);
79170+ sys_chmod((char __force_user *)collected, mode);
79171+ do_utime((char __force_user *)collected, mtime);
79172 }
79173 }
79174 return 0;
79175@@ -346,15 +346,15 @@ static int __init do_name(void)
79176 static int __init do_copy(void)
79177 {
79178 if (count >= body_len) {
79179- sys_write(wfd, victim, body_len);
79180+ sys_write(wfd, (char __force_user *)victim, body_len);
79181 sys_close(wfd);
79182- do_utime(vcollected, mtime);
79183+ do_utime((char __force_user *)vcollected, mtime);
79184 kfree(vcollected);
79185 eat(body_len);
79186 state = SkipIt;
79187 return 0;
79188 } else {
79189- sys_write(wfd, victim, count);
79190+ sys_write(wfd, (char __force_user *)victim, count);
79191 body_len -= count;
79192 eat(count);
79193 return 1;
79194@@ -365,9 +365,9 @@ static int __init do_symlink(void)
79195 {
79196 collected[N_ALIGN(name_len) + body_len] = '\0';
79197 clean_path(collected, 0);
79198- sys_symlink(collected + N_ALIGN(name_len), collected);
79199- sys_lchown(collected, uid, gid);
79200- do_utime(collected, mtime);
79201+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
79202+ sys_lchown((char __force_user *)collected, uid, gid);
79203+ do_utime((char __force_user *)collected, mtime);
79204 state = SkipIt;
79205 next_state = Reset;
79206 return 0;
79207@@ -583,7 +583,7 @@ static int __init populate_rootfs(void)
79208 {
79209 char *err = unpack_to_rootfs(__initramfs_start, __initramfs_size);
79210 if (err)
79211- panic(err); /* Failed to decompress INTERNAL initramfs */
79212+ panic("%s", err); /* Failed to decompress INTERNAL initramfs */
79213 if (initrd_start) {
79214 #ifdef CONFIG_BLK_DEV_RAM
79215 int fd;
79216diff --git a/init/main.c b/init/main.c
79217index d03d2ec..9fc4737 100644
79218--- a/init/main.c
79219+++ b/init/main.c
79220@@ -101,6 +101,8 @@ static inline void mark_rodata_ro(void) { }
79221 extern void tc_init(void);
79222 #endif
79223
79224+extern void grsecurity_init(void);
79225+
79226 /*
79227 * Debug helper: via this flag we know that we are in 'early bootup code'
79228 * where only the boot processor is running with IRQ disabled. This means
79229@@ -154,6 +156,74 @@ static int __init set_reset_devices(char *str)
79230
79231 __setup("reset_devices", set_reset_devices);
79232
79233+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
79234+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
79235+static int __init setup_grsec_proc_gid(char *str)
79236+{
79237+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
79238+ return 1;
79239+}
79240+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
79241+#endif
79242+
79243+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
79244+unsigned long pax_user_shadow_base __read_only;
79245+EXPORT_SYMBOL(pax_user_shadow_base);
79246+extern char pax_enter_kernel_user[];
79247+extern char pax_exit_kernel_user[];
79248+#endif
79249+
79250+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
79251+static int __init setup_pax_nouderef(char *str)
79252+{
79253+#ifdef CONFIG_X86_32
79254+ unsigned int cpu;
79255+ struct desc_struct *gdt;
79256+
79257+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
79258+ gdt = get_cpu_gdt_table(cpu);
79259+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
79260+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
79261+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
79262+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
79263+ }
79264+ loadsegment(ds, __KERNEL_DS);
79265+ loadsegment(es, __KERNEL_DS);
79266+ loadsegment(ss, __KERNEL_DS);
79267+#else
79268+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
79269+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
79270+ clone_pgd_mask = ~(pgdval_t)0UL;
79271+ pax_user_shadow_base = 0UL;
79272+ setup_clear_cpu_cap(X86_FEATURE_PCID);
79273+#endif
79274+
79275+ return 0;
79276+}
79277+early_param("pax_nouderef", setup_pax_nouderef);
79278+
79279+#ifdef CONFIG_X86_64
79280+static int __init setup_pax_weakuderef(char *str)
79281+{
79282+ if (clone_pgd_mask != ~(pgdval_t)0UL)
79283+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
79284+ return 1;
79285+}
79286+__setup("pax_weakuderef", setup_pax_weakuderef);
79287+#endif
79288+#endif
79289+
79290+#ifdef CONFIG_PAX_SOFTMODE
79291+int pax_softmode;
79292+
79293+static int __init setup_pax_softmode(char *str)
79294+{
79295+ get_option(&str, &pax_softmode);
79296+ return 1;
79297+}
79298+__setup("pax_softmode=", setup_pax_softmode);
79299+#endif
79300+
79301 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
79302 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
79303 static const char *panic_later, *panic_param;
79304@@ -679,25 +749,24 @@ int __init_or_module do_one_initcall(initcall_t fn)
79305 {
79306 int count = preempt_count();
79307 int ret;
79308- char msgbuf[64];
79309+ const char *msg1 = "", *msg2 = "";
79310
79311 if (initcall_debug)
79312 ret = do_one_initcall_debug(fn);
79313 else
79314 ret = fn();
79315
79316- msgbuf[0] = 0;
79317-
79318 if (preempt_count() != count) {
79319- sprintf(msgbuf, "preemption imbalance ");
79320+ msg1 = " preemption imbalance";
79321 preempt_count() = count;
79322 }
79323 if (irqs_disabled()) {
79324- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
79325+ msg2 = " disabled interrupts";
79326 local_irq_enable();
79327 }
79328- WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
79329+ WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
79330
79331+ add_latent_entropy();
79332 return ret;
79333 }
79334
79335@@ -803,8 +872,8 @@ static int run_init_process(const char *init_filename)
79336 {
79337 argv_init[0] = init_filename;
79338 return do_execve(init_filename,
79339- (const char __user *const __user *)argv_init,
79340- (const char __user *const __user *)envp_init);
79341+ (const char __user *const __force_user *)argv_init,
79342+ (const char __user *const __force_user *)envp_init);
79343 }
79344
79345 static noinline void __init kernel_init_freeable(void);
79346@@ -881,7 +950,7 @@ static noinline void __init kernel_init_freeable(void)
79347 do_basic_setup();
79348
79349 /* Open the /dev/console on the rootfs, this should never fail */
79350- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
79351+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
79352 pr_err("Warning: unable to open an initial console.\n");
79353
79354 (void) sys_dup(0);
79355@@ -894,11 +963,13 @@ static noinline void __init kernel_init_freeable(void)
79356 if (!ramdisk_execute_command)
79357 ramdisk_execute_command = "/init";
79358
79359- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
79360+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
79361 ramdisk_execute_command = NULL;
79362 prepare_namespace();
79363 }
79364
79365+ grsecurity_init();
79366+
79367 /*
79368 * Ok, we have completed the initial bootup, and
79369 * we're essentially up and running. Get rid of the
79370diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
79371index 130dfec..cc88451 100644
79372--- a/ipc/ipc_sysctl.c
79373+++ b/ipc/ipc_sysctl.c
79374@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
79375 static int proc_ipc_dointvec(ctl_table *table, int write,
79376 void __user *buffer, size_t *lenp, loff_t *ppos)
79377 {
79378- struct ctl_table ipc_table;
79379+ ctl_table_no_const ipc_table;
79380
79381 memcpy(&ipc_table, table, sizeof(ipc_table));
79382 ipc_table.data = get_ipc(table);
79383@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
79384 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
79385 void __user *buffer, size_t *lenp, loff_t *ppos)
79386 {
79387- struct ctl_table ipc_table;
79388+ ctl_table_no_const ipc_table;
79389
79390 memcpy(&ipc_table, table, sizeof(ipc_table));
79391 ipc_table.data = get_ipc(table);
79392@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
79393 static int proc_ipc_callback_dointvec(ctl_table *table, int write,
79394 void __user *buffer, size_t *lenp, loff_t *ppos)
79395 {
79396- struct ctl_table ipc_table;
79397+ ctl_table_no_const ipc_table;
79398 size_t lenp_bef = *lenp;
79399 int rc;
79400
79401@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec(ctl_table *table, int write,
79402 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
79403 void __user *buffer, size_t *lenp, loff_t *ppos)
79404 {
79405- struct ctl_table ipc_table;
79406+ ctl_table_no_const ipc_table;
79407 memcpy(&ipc_table, table, sizeof(ipc_table));
79408 ipc_table.data = get_ipc(table);
79409
79410@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
79411 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
79412 void __user *buffer, size_t *lenp, loff_t *ppos)
79413 {
79414- struct ctl_table ipc_table;
79415+ ctl_table_no_const ipc_table;
79416 size_t lenp_bef = *lenp;
79417 int oldval;
79418 int rc;
79419diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
79420index 383d638..943fdbb 100644
79421--- a/ipc/mq_sysctl.c
79422+++ b/ipc/mq_sysctl.c
79423@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
79424 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
79425 void __user *buffer, size_t *lenp, loff_t *ppos)
79426 {
79427- struct ctl_table mq_table;
79428+ ctl_table_no_const mq_table;
79429 memcpy(&mq_table, table, sizeof(mq_table));
79430 mq_table.data = get_mq(table);
79431
79432diff --git a/ipc/mqueue.c b/ipc/mqueue.c
79433index ae1996d..a35f2cc 100644
79434--- a/ipc/mqueue.c
79435+++ b/ipc/mqueue.c
79436@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
79437 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
79438 info->attr.mq_msgsize);
79439
79440+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
79441 spin_lock(&mq_lock);
79442 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
79443 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
79444diff --git a/ipc/msg.c b/ipc/msg.c
79445index 9f29d9e..8f284e0 100644
79446--- a/ipc/msg.c
79447+++ b/ipc/msg.c
79448@@ -291,18 +291,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
79449 return security_msg_queue_associate(msq, msgflg);
79450 }
79451
79452+static struct ipc_ops msg_ops = {
79453+ .getnew = newque,
79454+ .associate = msg_security,
79455+ .more_checks = NULL
79456+};
79457+
79458 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
79459 {
79460 struct ipc_namespace *ns;
79461- struct ipc_ops msg_ops;
79462 struct ipc_params msg_params;
79463
79464 ns = current->nsproxy->ipc_ns;
79465
79466- msg_ops.getnew = newque;
79467- msg_ops.associate = msg_security;
79468- msg_ops.more_checks = NULL;
79469-
79470 msg_params.key = key;
79471 msg_params.flg = msgflg;
79472
79473diff --git a/ipc/sem.c b/ipc/sem.c
79474index 4108889..511ada1 100644
79475--- a/ipc/sem.c
79476+++ b/ipc/sem.c
79477@@ -517,10 +517,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
79478 return 0;
79479 }
79480
79481+static struct ipc_ops sem_ops = {
79482+ .getnew = newary,
79483+ .associate = sem_security,
79484+ .more_checks = sem_more_checks
79485+};
79486+
79487 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
79488 {
79489 struct ipc_namespace *ns;
79490- struct ipc_ops sem_ops;
79491 struct ipc_params sem_params;
79492
79493 ns = current->nsproxy->ipc_ns;
79494@@ -528,10 +533,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
79495 if (nsems < 0 || nsems > ns->sc_semmsl)
79496 return -EINVAL;
79497
79498- sem_ops.getnew = newary;
79499- sem_ops.associate = sem_security;
79500- sem_ops.more_checks = sem_more_checks;
79501-
79502 sem_params.key = key;
79503 sem_params.flg = semflg;
79504 sem_params.u.nsems = nsems;
79505diff --git a/ipc/shm.c b/ipc/shm.c
79506index c6b4ad5..3ec3254 100644
79507--- a/ipc/shm.c
79508+++ b/ipc/shm.c
79509@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
79510 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
79511 #endif
79512
79513+#ifdef CONFIG_GRKERNSEC
79514+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
79515+ const time_t shm_createtime, const kuid_t cuid,
79516+ const int shmid);
79517+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
79518+ const time_t shm_createtime);
79519+#endif
79520+
79521 void shm_init_ns(struct ipc_namespace *ns)
79522 {
79523 ns->shm_ctlmax = SHMMAX;
79524@@ -531,6 +539,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
79525 shp->shm_lprid = 0;
79526 shp->shm_atim = shp->shm_dtim = 0;
79527 shp->shm_ctim = get_seconds();
79528+#ifdef CONFIG_GRKERNSEC
79529+ {
79530+ struct timespec timeval;
79531+ do_posix_clock_monotonic_gettime(&timeval);
79532+
79533+ shp->shm_createtime = timeval.tv_sec;
79534+ }
79535+#endif
79536 shp->shm_segsz = size;
79537 shp->shm_nattch = 0;
79538 shp->shm_file = file;
79539@@ -585,18 +601,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
79540 return 0;
79541 }
79542
79543+static struct ipc_ops shm_ops = {
79544+ .getnew = newseg,
79545+ .associate = shm_security,
79546+ .more_checks = shm_more_checks
79547+};
79548+
79549 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
79550 {
79551 struct ipc_namespace *ns;
79552- struct ipc_ops shm_ops;
79553 struct ipc_params shm_params;
79554
79555 ns = current->nsproxy->ipc_ns;
79556
79557- shm_ops.getnew = newseg;
79558- shm_ops.associate = shm_security;
79559- shm_ops.more_checks = shm_more_checks;
79560-
79561 shm_params.key = key;
79562 shm_params.flg = shmflg;
79563 shm_params.u.size = size;
79564@@ -1028,6 +1045,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
79565 f_mode = FMODE_READ | FMODE_WRITE;
79566 }
79567 if (shmflg & SHM_EXEC) {
79568+
79569+#ifdef CONFIG_PAX_MPROTECT
79570+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
79571+ goto out;
79572+#endif
79573+
79574 prot |= PROT_EXEC;
79575 acc_mode |= S_IXUGO;
79576 }
79577@@ -1051,9 +1074,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
79578 if (err)
79579 goto out_unlock;
79580
79581+#ifdef CONFIG_GRKERNSEC
79582+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
79583+ shp->shm_perm.cuid, shmid) ||
79584+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
79585+ err = -EACCES;
79586+ goto out_unlock;
79587+ }
79588+#endif
79589+
79590 path = shp->shm_file->f_path;
79591 path_get(&path);
79592 shp->shm_nattch++;
79593+#ifdef CONFIG_GRKERNSEC
79594+ shp->shm_lapid = current->pid;
79595+#endif
79596 size = i_size_read(path.dentry->d_inode);
79597 shm_unlock(shp);
79598
79599diff --git a/kernel/acct.c b/kernel/acct.c
79600index 8d6e145..33e0b1e 100644
79601--- a/kernel/acct.c
79602+++ b/kernel/acct.c
79603@@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
79604 */
79605 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
79606 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
79607- file->f_op->write(file, (char *)&ac,
79608+ file->f_op->write(file, (char __force_user *)&ac,
79609 sizeof(acct_t), &file->f_pos);
79610 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
79611 set_fs(fs);
79612diff --git a/kernel/audit.c b/kernel/audit.c
79613index 91e53d0..d9e3ec4 100644
79614--- a/kernel/audit.c
79615+++ b/kernel/audit.c
79616@@ -118,7 +118,7 @@ u32 audit_sig_sid = 0;
79617 3) suppressed due to audit_rate_limit
79618 4) suppressed due to audit_backlog_limit
79619 */
79620-static atomic_t audit_lost = ATOMIC_INIT(0);
79621+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
79622
79623 /* The netlink socket. */
79624 static struct sock *audit_sock;
79625@@ -240,7 +240,7 @@ void audit_log_lost(const char *message)
79626 unsigned long now;
79627 int print;
79628
79629- atomic_inc(&audit_lost);
79630+ atomic_inc_unchecked(&audit_lost);
79631
79632 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
79633
79634@@ -259,7 +259,7 @@ void audit_log_lost(const char *message)
79635 printk(KERN_WARNING
79636 "audit: audit_lost=%d audit_rate_limit=%d "
79637 "audit_backlog_limit=%d\n",
79638- atomic_read(&audit_lost),
79639+ atomic_read_unchecked(&audit_lost),
79640 audit_rate_limit,
79641 audit_backlog_limit);
79642 audit_panic(message);
79643@@ -664,7 +664,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
79644 status_set.pid = audit_pid;
79645 status_set.rate_limit = audit_rate_limit;
79646 status_set.backlog_limit = audit_backlog_limit;
79647- status_set.lost = atomic_read(&audit_lost);
79648+ status_set.lost = atomic_read_unchecked(&audit_lost);
79649 status_set.backlog = skb_queue_len(&audit_skb_queue);
79650 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
79651 &status_set, sizeof(status_set));
79652diff --git a/kernel/auditsc.c b/kernel/auditsc.c
79653index 9845cb3..3ec9369 100644
79654--- a/kernel/auditsc.c
79655+++ b/kernel/auditsc.c
79656@@ -1962,7 +1962,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
79657 }
79658
79659 /* global counter which is incremented every time something logs in */
79660-static atomic_t session_id = ATOMIC_INIT(0);
79661+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
79662
79663 /**
79664 * audit_set_loginuid - set current task's audit_context loginuid
79665@@ -1986,7 +1986,7 @@ int audit_set_loginuid(kuid_t loginuid)
79666 return -EPERM;
79667 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
79668
79669- sessionid = atomic_inc_return(&session_id);
79670+ sessionid = atomic_inc_return_unchecked(&session_id);
79671 if (context && context->in_syscall) {
79672 struct audit_buffer *ab;
79673
79674diff --git a/kernel/capability.c b/kernel/capability.c
79675index f6c2ce5..982c0f9 100644
79676--- a/kernel/capability.c
79677+++ b/kernel/capability.c
79678@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
79679 * before modification is attempted and the application
79680 * fails.
79681 */
79682+ if (tocopy > ARRAY_SIZE(kdata))
79683+ return -EFAULT;
79684+
79685 if (copy_to_user(dataptr, kdata, tocopy
79686 * sizeof(struct __user_cap_data_struct))) {
79687 return -EFAULT;
79688@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
79689 int ret;
79690
79691 rcu_read_lock();
79692- ret = security_capable(__task_cred(t), ns, cap);
79693+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
79694+ gr_task_is_capable(t, __task_cred(t), cap);
79695 rcu_read_unlock();
79696
79697- return (ret == 0);
79698+ return ret;
79699 }
79700
79701 /**
79702@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
79703 int ret;
79704
79705 rcu_read_lock();
79706- ret = security_capable_noaudit(__task_cred(t), ns, cap);
79707+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
79708 rcu_read_unlock();
79709
79710- return (ret == 0);
79711+ return ret;
79712 }
79713
79714 /**
79715@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
79716 BUG();
79717 }
79718
79719- if (security_capable(current_cred(), ns, cap) == 0) {
79720+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
79721 current->flags |= PF_SUPERPRIV;
79722 return true;
79723 }
79724@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
79725 }
79726 EXPORT_SYMBOL(ns_capable);
79727
79728+bool ns_capable_nolog(struct user_namespace *ns, int cap)
79729+{
79730+ if (unlikely(!cap_valid(cap))) {
79731+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
79732+ BUG();
79733+ }
79734+
79735+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
79736+ current->flags |= PF_SUPERPRIV;
79737+ return true;
79738+ }
79739+ return false;
79740+}
79741+EXPORT_SYMBOL(ns_capable_nolog);
79742+
79743 /**
79744 * file_ns_capable - Determine if the file's opener had a capability in effect
79745 * @file: The file we want to check
79746@@ -432,6 +451,12 @@ bool capable(int cap)
79747 }
79748 EXPORT_SYMBOL(capable);
79749
79750+bool capable_nolog(int cap)
79751+{
79752+ return ns_capable_nolog(&init_user_ns, cap);
79753+}
79754+EXPORT_SYMBOL(capable_nolog);
79755+
79756 /**
79757 * nsown_capable - Check superior capability to one's own user_ns
79758 * @cap: The capability in question
79759@@ -464,3 +489,10 @@ bool inode_capable(const struct inode *inode, int cap)
79760
79761 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
79762 }
79763+
79764+bool inode_capable_nolog(const struct inode *inode, int cap)
79765+{
79766+ struct user_namespace *ns = current_user_ns();
79767+
79768+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
79769+}
79770diff --git a/kernel/cgroup.c b/kernel/cgroup.c
79771index e919633..f46b08f 100644
79772--- a/kernel/cgroup.c
79773+++ b/kernel/cgroup.c
79774@@ -5623,7 +5623,7 @@ static int cgroup_css_links_read(struct cgroup *cgrp,
79775 struct css_set *cset = link->cset;
79776 struct task_struct *task;
79777 int count = 0;
79778- seq_printf(seq, "css_set %p\n", cset);
79779+ seq_printf(seq, "css_set %pK\n", cset);
79780 list_for_each_entry(task, &cset->tasks, cg_list) {
79781 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
79782 seq_puts(seq, " ...\n");
79783diff --git a/kernel/compat.c b/kernel/compat.c
79784index 0a09e48..f44f3f0 100644
79785--- a/kernel/compat.c
79786+++ b/kernel/compat.c
79787@@ -13,6 +13,7 @@
79788
79789 #include <linux/linkage.h>
79790 #include <linux/compat.h>
79791+#include <linux/module.h>
79792 #include <linux/errno.h>
79793 #include <linux/time.h>
79794 #include <linux/signal.h>
79795@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
79796 mm_segment_t oldfs;
79797 long ret;
79798
79799- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
79800+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
79801 oldfs = get_fs();
79802 set_fs(KERNEL_DS);
79803 ret = hrtimer_nanosleep_restart(restart);
79804@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
79805 oldfs = get_fs();
79806 set_fs(KERNEL_DS);
79807 ret = hrtimer_nanosleep(&tu,
79808- rmtp ? (struct timespec __user *)&rmt : NULL,
79809+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
79810 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
79811 set_fs(oldfs);
79812
79813@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
79814 mm_segment_t old_fs = get_fs();
79815
79816 set_fs(KERNEL_DS);
79817- ret = sys_sigpending((old_sigset_t __user *) &s);
79818+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
79819 set_fs(old_fs);
79820 if (ret == 0)
79821 ret = put_user(s, set);
79822@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
79823 mm_segment_t old_fs = get_fs();
79824
79825 set_fs(KERNEL_DS);
79826- ret = sys_old_getrlimit(resource, &r);
79827+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
79828 set_fs(old_fs);
79829
79830 if (!ret) {
79831@@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
79832 set_fs (KERNEL_DS);
79833 ret = sys_wait4(pid,
79834 (stat_addr ?
79835- (unsigned int __user *) &status : NULL),
79836- options, (struct rusage __user *) &r);
79837+ (unsigned int __force_user *) &status : NULL),
79838+ options, (struct rusage __force_user *) &r);
79839 set_fs (old_fs);
79840
79841 if (ret > 0) {
79842@@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
79843 memset(&info, 0, sizeof(info));
79844
79845 set_fs(KERNEL_DS);
79846- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
79847- uru ? (struct rusage __user *)&ru : NULL);
79848+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
79849+ uru ? (struct rusage __force_user *)&ru : NULL);
79850 set_fs(old_fs);
79851
79852 if ((ret < 0) || (info.si_signo == 0))
79853@@ -695,8 +696,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
79854 oldfs = get_fs();
79855 set_fs(KERNEL_DS);
79856 err = sys_timer_settime(timer_id, flags,
79857- (struct itimerspec __user *) &newts,
79858- (struct itimerspec __user *) &oldts);
79859+ (struct itimerspec __force_user *) &newts,
79860+ (struct itimerspec __force_user *) &oldts);
79861 set_fs(oldfs);
79862 if (!err && old && put_compat_itimerspec(old, &oldts))
79863 return -EFAULT;
79864@@ -713,7 +714,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
79865 oldfs = get_fs();
79866 set_fs(KERNEL_DS);
79867 err = sys_timer_gettime(timer_id,
79868- (struct itimerspec __user *) &ts);
79869+ (struct itimerspec __force_user *) &ts);
79870 set_fs(oldfs);
79871 if (!err && put_compat_itimerspec(setting, &ts))
79872 return -EFAULT;
79873@@ -732,7 +733,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
79874 oldfs = get_fs();
79875 set_fs(KERNEL_DS);
79876 err = sys_clock_settime(which_clock,
79877- (struct timespec __user *) &ts);
79878+ (struct timespec __force_user *) &ts);
79879 set_fs(oldfs);
79880 return err;
79881 }
79882@@ -747,7 +748,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
79883 oldfs = get_fs();
79884 set_fs(KERNEL_DS);
79885 err = sys_clock_gettime(which_clock,
79886- (struct timespec __user *) &ts);
79887+ (struct timespec __force_user *) &ts);
79888 set_fs(oldfs);
79889 if (!err && put_compat_timespec(&ts, tp))
79890 return -EFAULT;
79891@@ -767,7 +768,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
79892
79893 oldfs = get_fs();
79894 set_fs(KERNEL_DS);
79895- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
79896+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
79897 set_fs(oldfs);
79898
79899 err = compat_put_timex(utp, &txc);
79900@@ -787,7 +788,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
79901 oldfs = get_fs();
79902 set_fs(KERNEL_DS);
79903 err = sys_clock_getres(which_clock,
79904- (struct timespec __user *) &ts);
79905+ (struct timespec __force_user *) &ts);
79906 set_fs(oldfs);
79907 if (!err && tp && put_compat_timespec(&ts, tp))
79908 return -EFAULT;
79909@@ -799,9 +800,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
79910 long err;
79911 mm_segment_t oldfs;
79912 struct timespec tu;
79913- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
79914+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
79915
79916- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
79917+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
79918 oldfs = get_fs();
79919 set_fs(KERNEL_DS);
79920 err = clock_nanosleep_restart(restart);
79921@@ -833,8 +834,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
79922 oldfs = get_fs();
79923 set_fs(KERNEL_DS);
79924 err = sys_clock_nanosleep(which_clock, flags,
79925- (struct timespec __user *) &in,
79926- (struct timespec __user *) &out);
79927+ (struct timespec __force_user *) &in,
79928+ (struct timespec __force_user *) &out);
79929 set_fs(oldfs);
79930
79931 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
79932diff --git a/kernel/configs.c b/kernel/configs.c
79933index c18b1f1..b9a0132 100644
79934--- a/kernel/configs.c
79935+++ b/kernel/configs.c
79936@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
79937 struct proc_dir_entry *entry;
79938
79939 /* create the current config file */
79940+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
79941+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
79942+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
79943+ &ikconfig_file_ops);
79944+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
79945+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
79946+ &ikconfig_file_ops);
79947+#endif
79948+#else
79949 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
79950 &ikconfig_file_ops);
79951+#endif
79952+
79953 if (!entry)
79954 return -ENOMEM;
79955
79956diff --git a/kernel/cred.c b/kernel/cred.c
79957index e0573a4..3874e41 100644
79958--- a/kernel/cred.c
79959+++ b/kernel/cred.c
79960@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
79961 validate_creds(cred);
79962 alter_cred_subscribers(cred, -1);
79963 put_cred(cred);
79964+
79965+#ifdef CONFIG_GRKERNSEC_SETXID
79966+ cred = (struct cred *) tsk->delayed_cred;
79967+ if (cred != NULL) {
79968+ tsk->delayed_cred = NULL;
79969+ validate_creds(cred);
79970+ alter_cred_subscribers(cred, -1);
79971+ put_cred(cred);
79972+ }
79973+#endif
79974 }
79975
79976 /**
79977@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
79978 * Always returns 0 thus allowing this function to be tail-called at the end
79979 * of, say, sys_setgid().
79980 */
79981-int commit_creds(struct cred *new)
79982+static int __commit_creds(struct cred *new)
79983 {
79984 struct task_struct *task = current;
79985 const struct cred *old = task->real_cred;
79986@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
79987
79988 get_cred(new); /* we will require a ref for the subj creds too */
79989
79990+ gr_set_role_label(task, new->uid, new->gid);
79991+
79992 /* dumpability changes */
79993 if (!uid_eq(old->euid, new->euid) ||
79994 !gid_eq(old->egid, new->egid) ||
79995@@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
79996 put_cred(old);
79997 return 0;
79998 }
79999+#ifdef CONFIG_GRKERNSEC_SETXID
80000+extern int set_user(struct cred *new);
80001+
80002+void gr_delayed_cred_worker(void)
80003+{
80004+ const struct cred *new = current->delayed_cred;
80005+ struct cred *ncred;
80006+
80007+ current->delayed_cred = NULL;
80008+
80009+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
80010+ // from doing get_cred on it when queueing this
80011+ put_cred(new);
80012+ return;
80013+ } else if (new == NULL)
80014+ return;
80015+
80016+ ncred = prepare_creds();
80017+ if (!ncred)
80018+ goto die;
80019+ // uids
80020+ ncred->uid = new->uid;
80021+ ncred->euid = new->euid;
80022+ ncred->suid = new->suid;
80023+ ncred->fsuid = new->fsuid;
80024+ // gids
80025+ ncred->gid = new->gid;
80026+ ncred->egid = new->egid;
80027+ ncred->sgid = new->sgid;
80028+ ncred->fsgid = new->fsgid;
80029+ // groups
80030+ if (set_groups(ncred, new->group_info) < 0) {
80031+ abort_creds(ncred);
80032+ goto die;
80033+ }
80034+ // caps
80035+ ncred->securebits = new->securebits;
80036+ ncred->cap_inheritable = new->cap_inheritable;
80037+ ncred->cap_permitted = new->cap_permitted;
80038+ ncred->cap_effective = new->cap_effective;
80039+ ncred->cap_bset = new->cap_bset;
80040+
80041+ if (set_user(ncred)) {
80042+ abort_creds(ncred);
80043+ goto die;
80044+ }
80045+
80046+ // from doing get_cred on it when queueing this
80047+ put_cred(new);
80048+
80049+ __commit_creds(ncred);
80050+ return;
80051+die:
80052+ // from doing get_cred on it when queueing this
80053+ put_cred(new);
80054+ do_group_exit(SIGKILL);
80055+}
80056+#endif
80057+
80058+int commit_creds(struct cred *new)
80059+{
80060+#ifdef CONFIG_GRKERNSEC_SETXID
80061+ int ret;
80062+ int schedule_it = 0;
80063+ struct task_struct *t;
80064+
80065+ /* we won't get called with tasklist_lock held for writing
80066+ and interrupts disabled as the cred struct in that case is
80067+ init_cred
80068+ */
80069+ if (grsec_enable_setxid && !current_is_single_threaded() &&
80070+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
80071+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
80072+ schedule_it = 1;
80073+ }
80074+ ret = __commit_creds(new);
80075+ if (schedule_it) {
80076+ rcu_read_lock();
80077+ read_lock(&tasklist_lock);
80078+ for (t = next_thread(current); t != current;
80079+ t = next_thread(t)) {
80080+ if (t->delayed_cred == NULL) {
80081+ t->delayed_cred = get_cred(new);
80082+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
80083+ set_tsk_need_resched(t);
80084+ }
80085+ }
80086+ read_unlock(&tasklist_lock);
80087+ rcu_read_unlock();
80088+ }
80089+ return ret;
80090+#else
80091+ return __commit_creds(new);
80092+#endif
80093+}
80094+
80095 EXPORT_SYMBOL(commit_creds);
80096
80097 /**
80098diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
80099index 0506d44..2c20034 100644
80100--- a/kernel/debug/debug_core.c
80101+++ b/kernel/debug/debug_core.c
80102@@ -123,7 +123,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
80103 */
80104 static atomic_t masters_in_kgdb;
80105 static atomic_t slaves_in_kgdb;
80106-static atomic_t kgdb_break_tasklet_var;
80107+static atomic_unchecked_t kgdb_break_tasklet_var;
80108 atomic_t kgdb_setting_breakpoint;
80109
80110 struct task_struct *kgdb_usethread;
80111@@ -133,7 +133,7 @@ int kgdb_single_step;
80112 static pid_t kgdb_sstep_pid;
80113
80114 /* to keep track of the CPU which is doing the single stepping*/
80115-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
80116+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
80117
80118 /*
80119 * If you are debugging a problem where roundup (the collection of
80120@@ -541,7 +541,7 @@ return_normal:
80121 * kernel will only try for the value of sstep_tries before
80122 * giving up and continuing on.
80123 */
80124- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
80125+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
80126 (kgdb_info[cpu].task &&
80127 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
80128 atomic_set(&kgdb_active, -1);
80129@@ -635,8 +635,8 @@ cpu_master_loop:
80130 }
80131
80132 kgdb_restore:
80133- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
80134- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
80135+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
80136+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
80137 if (kgdb_info[sstep_cpu].task)
80138 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
80139 else
80140@@ -888,18 +888,18 @@ static void kgdb_unregister_callbacks(void)
80141 static void kgdb_tasklet_bpt(unsigned long ing)
80142 {
80143 kgdb_breakpoint();
80144- atomic_set(&kgdb_break_tasklet_var, 0);
80145+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
80146 }
80147
80148 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
80149
80150 void kgdb_schedule_breakpoint(void)
80151 {
80152- if (atomic_read(&kgdb_break_tasklet_var) ||
80153+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
80154 atomic_read(&kgdb_active) != -1 ||
80155 atomic_read(&kgdb_setting_breakpoint))
80156 return;
80157- atomic_inc(&kgdb_break_tasklet_var);
80158+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
80159 tasklet_schedule(&kgdb_tasklet_breakpoint);
80160 }
80161 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
80162diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
80163index 00eb8f7..d7e3244 100644
80164--- a/kernel/debug/kdb/kdb_main.c
80165+++ b/kernel/debug/kdb/kdb_main.c
80166@@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
80167 continue;
80168
80169 kdb_printf("%-20s%8u 0x%p ", mod->name,
80170- mod->core_size, (void *)mod);
80171+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
80172 #ifdef CONFIG_MODULE_UNLOAD
80173 kdb_printf("%4ld ", module_refcount(mod));
80174 #endif
80175@@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
80176 kdb_printf(" (Loading)");
80177 else
80178 kdb_printf(" (Live)");
80179- kdb_printf(" 0x%p", mod->module_core);
80180+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
80181
80182 #ifdef CONFIG_MODULE_UNLOAD
80183 {
80184diff --git a/kernel/events/core.c b/kernel/events/core.c
80185index f86599e..b18b180 100644
80186--- a/kernel/events/core.c
80187+++ b/kernel/events/core.c
80188@@ -156,8 +156,15 @@ static struct srcu_struct pmus_srcu;
80189 * 0 - disallow raw tracepoint access for unpriv
80190 * 1 - disallow cpu events for unpriv
80191 * 2 - disallow kernel profiling for unpriv
80192+ * 3 - disallow all unpriv perf event use
80193 */
80194-int sysctl_perf_event_paranoid __read_mostly = 1;
80195+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
80196+int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
80197+#elif defined(CONFIG_GRKERNSEC_HIDESYM)
80198+int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
80199+#else
80200+int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
80201+#endif
80202
80203 /* Minimum for 512 kiB + 1 user control page */
80204 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
80205@@ -270,7 +277,7 @@ void perf_sample_event_took(u64 sample_len_ns)
80206 update_perf_cpu_limits();
80207 }
80208
80209-static atomic64_t perf_event_id;
80210+static atomic64_unchecked_t perf_event_id;
80211
80212 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
80213 enum event_type_t event_type);
80214@@ -2936,7 +2943,7 @@ static void __perf_event_read(void *info)
80215
80216 static inline u64 perf_event_count(struct perf_event *event)
80217 {
80218- return local64_read(&event->count) + atomic64_read(&event->child_count);
80219+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
80220 }
80221
80222 static u64 perf_event_read(struct perf_event *event)
80223@@ -3282,9 +3289,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
80224 mutex_lock(&event->child_mutex);
80225 total += perf_event_read(event);
80226 *enabled += event->total_time_enabled +
80227- atomic64_read(&event->child_total_time_enabled);
80228+ atomic64_read_unchecked(&event->child_total_time_enabled);
80229 *running += event->total_time_running +
80230- atomic64_read(&event->child_total_time_running);
80231+ atomic64_read_unchecked(&event->child_total_time_running);
80232
80233 list_for_each_entry(child, &event->child_list, child_list) {
80234 total += perf_event_read(child);
80235@@ -3670,10 +3677,10 @@ void perf_event_update_userpage(struct perf_event *event)
80236 userpg->offset -= local64_read(&event->hw.prev_count);
80237
80238 userpg->time_enabled = enabled +
80239- atomic64_read(&event->child_total_time_enabled);
80240+ atomic64_read_unchecked(&event->child_total_time_enabled);
80241
80242 userpg->time_running = running +
80243- atomic64_read(&event->child_total_time_running);
80244+ atomic64_read_unchecked(&event->child_total_time_running);
80245
80246 arch_perf_update_userpage(userpg, now);
80247
80248@@ -4223,7 +4230,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
80249
80250 /* Data. */
80251 sp = perf_user_stack_pointer(regs);
80252- rem = __output_copy_user(handle, (void *) sp, dump_size);
80253+ rem = __output_copy_user(handle, (void __user *) sp, dump_size);
80254 dyn_size = dump_size - rem;
80255
80256 perf_output_skip(handle, rem);
80257@@ -4311,11 +4318,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
80258 values[n++] = perf_event_count(event);
80259 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
80260 values[n++] = enabled +
80261- atomic64_read(&event->child_total_time_enabled);
80262+ atomic64_read_unchecked(&event->child_total_time_enabled);
80263 }
80264 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
80265 values[n++] = running +
80266- atomic64_read(&event->child_total_time_running);
80267+ atomic64_read_unchecked(&event->child_total_time_running);
80268 }
80269 if (read_format & PERF_FORMAT_ID)
80270 values[n++] = primary_event_id(event);
80271@@ -5024,12 +5031,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
80272 * need to add enough zero bytes after the string to handle
80273 * the 64bit alignment we do later.
80274 */
80275- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
80276+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
80277 if (!buf) {
80278 name = strncpy(tmp, "//enomem", sizeof(tmp));
80279 goto got_name;
80280 }
80281- name = d_path(&file->f_path, buf, PATH_MAX);
80282+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
80283 if (IS_ERR(name)) {
80284 name = strncpy(tmp, "//toolong", sizeof(tmp));
80285 goto got_name;
80286@@ -6498,7 +6505,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
80287 event->parent = parent_event;
80288
80289 event->ns = get_pid_ns(task_active_pid_ns(current));
80290- event->id = atomic64_inc_return(&perf_event_id);
80291+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
80292
80293 event->state = PERF_EVENT_STATE_INACTIVE;
80294
80295@@ -6807,6 +6814,11 @@ SYSCALL_DEFINE5(perf_event_open,
80296 if (flags & ~PERF_FLAG_ALL)
80297 return -EINVAL;
80298
80299+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
80300+ if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
80301+ return -EACCES;
80302+#endif
80303+
80304 err = perf_copy_attr(attr_uptr, &attr);
80305 if (err)
80306 return err;
80307@@ -7139,10 +7151,10 @@ static void sync_child_event(struct perf_event *child_event,
80308 /*
80309 * Add back the child's count to the parent's count:
80310 */
80311- atomic64_add(child_val, &parent_event->child_count);
80312- atomic64_add(child_event->total_time_enabled,
80313+ atomic64_add_unchecked(child_val, &parent_event->child_count);
80314+ atomic64_add_unchecked(child_event->total_time_enabled,
80315 &parent_event->child_total_time_enabled);
80316- atomic64_add(child_event->total_time_running,
80317+ atomic64_add_unchecked(child_event->total_time_running,
80318 &parent_event->child_total_time_running);
80319
80320 /*
80321diff --git a/kernel/events/internal.h b/kernel/events/internal.h
80322index ca65997..60df03d 100644
80323--- a/kernel/events/internal.h
80324+++ b/kernel/events/internal.h
80325@@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
80326 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
80327 }
80328
80329-#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
80330-static inline unsigned int \
80331+#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
80332+static inline unsigned long \
80333 func_name(struct perf_output_handle *handle, \
80334- const void *buf, unsigned int len) \
80335+ const void user *buf, unsigned long len) \
80336 { \
80337 unsigned long size, written; \
80338 \
80339@@ -116,17 +116,17 @@ static inline int memcpy_common(void *dst, const void *src, size_t n)
80340 return n;
80341 }
80342
80343-DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
80344+DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
80345
80346 #define MEMCPY_SKIP(dst, src, n) (n)
80347
80348-DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP)
80349+DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP, )
80350
80351 #ifndef arch_perf_out_copy_user
80352 #define arch_perf_out_copy_user __copy_from_user_inatomic
80353 #endif
80354
80355-DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
80356+DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
80357
80358 /* Callchain handling */
80359 extern struct perf_callchain_entry *
80360diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
80361index f356974..cb8c570 100644
80362--- a/kernel/events/uprobes.c
80363+++ b/kernel/events/uprobes.c
80364@@ -1556,7 +1556,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
80365 {
80366 struct page *page;
80367 uprobe_opcode_t opcode;
80368- int result;
80369+ long result;
80370
80371 pagefault_disable();
80372 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
80373diff --git a/kernel/exit.c b/kernel/exit.c
80374index a949819..a5f127d 100644
80375--- a/kernel/exit.c
80376+++ b/kernel/exit.c
80377@@ -172,6 +172,10 @@ void release_task(struct task_struct * p)
80378 struct task_struct *leader;
80379 int zap_leader;
80380 repeat:
80381+#ifdef CONFIG_NET
80382+ gr_del_task_from_ip_table(p);
80383+#endif
80384+
80385 /* don't need to get the RCU readlock here - the process is dead and
80386 * can't be modifying its own credentials. But shut RCU-lockdep up */
80387 rcu_read_lock();
80388@@ -329,7 +333,7 @@ int allow_signal(int sig)
80389 * know it'll be handled, so that they don't get converted to
80390 * SIGKILL or just silently dropped.
80391 */
80392- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
80393+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
80394 recalc_sigpending();
80395 spin_unlock_irq(&current->sighand->siglock);
80396 return 0;
80397@@ -698,6 +702,8 @@ void do_exit(long code)
80398 struct task_struct *tsk = current;
80399 int group_dead;
80400
80401+ set_fs(USER_DS);
80402+
80403 profile_task_exit(tsk);
80404
80405 WARN_ON(blk_needs_flush_plug(tsk));
80406@@ -714,7 +720,6 @@ void do_exit(long code)
80407 * mm_release()->clear_child_tid() from writing to a user-controlled
80408 * kernel address.
80409 */
80410- set_fs(USER_DS);
80411
80412 ptrace_event(PTRACE_EVENT_EXIT, code);
80413
80414@@ -773,6 +778,9 @@ void do_exit(long code)
80415 tsk->exit_code = code;
80416 taskstats_exit(tsk, group_dead);
80417
80418+ gr_acl_handle_psacct(tsk, code);
80419+ gr_acl_handle_exit();
80420+
80421 exit_mm(tsk);
80422
80423 if (group_dead)
80424@@ -894,7 +902,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
80425 * Take down every thread in the group. This is called by fatal signals
80426 * as well as by sys_exit_group (below).
80427 */
80428-void
80429+__noreturn void
80430 do_group_exit(int exit_code)
80431 {
80432 struct signal_struct *sig = current->signal;
80433diff --git a/kernel/fork.c b/kernel/fork.c
80434index bf46287..2af185d 100644
80435--- a/kernel/fork.c
80436+++ b/kernel/fork.c
80437@@ -319,7 +319,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
80438 *stackend = STACK_END_MAGIC; /* for overflow detection */
80439
80440 #ifdef CONFIG_CC_STACKPROTECTOR
80441- tsk->stack_canary = get_random_int();
80442+ tsk->stack_canary = pax_get_random_long();
80443 #endif
80444
80445 /*
80446@@ -345,13 +345,81 @@ free_tsk:
80447 }
80448
80449 #ifdef CONFIG_MMU
80450-static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
80451+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
80452 {
80453- struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
80454- struct rb_node **rb_link, *rb_parent;
80455- int retval;
80456+ struct vm_area_struct *tmp;
80457 unsigned long charge;
80458 struct mempolicy *pol;
80459+ struct file *file;
80460+
80461+ charge = 0;
80462+ if (mpnt->vm_flags & VM_ACCOUNT) {
80463+ unsigned long len = vma_pages(mpnt);
80464+
80465+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
80466+ goto fail_nomem;
80467+ charge = len;
80468+ }
80469+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
80470+ if (!tmp)
80471+ goto fail_nomem;
80472+ *tmp = *mpnt;
80473+ tmp->vm_mm = mm;
80474+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
80475+ pol = mpol_dup(vma_policy(mpnt));
80476+ if (IS_ERR(pol))
80477+ goto fail_nomem_policy;
80478+ vma_set_policy(tmp, pol);
80479+ if (anon_vma_fork(tmp, mpnt))
80480+ goto fail_nomem_anon_vma_fork;
80481+ tmp->vm_flags &= ~VM_LOCKED;
80482+ tmp->vm_next = tmp->vm_prev = NULL;
80483+ tmp->vm_mirror = NULL;
80484+ file = tmp->vm_file;
80485+ if (file) {
80486+ struct inode *inode = file_inode(file);
80487+ struct address_space *mapping = file->f_mapping;
80488+
80489+ get_file(file);
80490+ if (tmp->vm_flags & VM_DENYWRITE)
80491+ atomic_dec(&inode->i_writecount);
80492+ mutex_lock(&mapping->i_mmap_mutex);
80493+ if (tmp->vm_flags & VM_SHARED)
80494+ mapping->i_mmap_writable++;
80495+ flush_dcache_mmap_lock(mapping);
80496+ /* insert tmp into the share list, just after mpnt */
80497+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
80498+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
80499+ else
80500+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
80501+ flush_dcache_mmap_unlock(mapping);
80502+ mutex_unlock(&mapping->i_mmap_mutex);
80503+ }
80504+
80505+ /*
80506+ * Clear hugetlb-related page reserves for children. This only
80507+ * affects MAP_PRIVATE mappings. Faults generated by the child
80508+ * are not guaranteed to succeed, even if read-only
80509+ */
80510+ if (is_vm_hugetlb_page(tmp))
80511+ reset_vma_resv_huge_pages(tmp);
80512+
80513+ return tmp;
80514+
80515+fail_nomem_anon_vma_fork:
80516+ mpol_put(pol);
80517+fail_nomem_policy:
80518+ kmem_cache_free(vm_area_cachep, tmp);
80519+fail_nomem:
80520+ vm_unacct_memory(charge);
80521+ return NULL;
80522+}
80523+
80524+static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
80525+{
80526+ struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
80527+ struct rb_node **rb_link, *rb_parent;
80528+ int retval;
80529
80530 uprobe_start_dup_mmap();
80531 down_write(&oldmm->mmap_sem);
80532@@ -380,57 +448,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
80533
80534 prev = NULL;
80535 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
80536- struct file *file;
80537-
80538 if (mpnt->vm_flags & VM_DONTCOPY) {
80539 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
80540 -vma_pages(mpnt));
80541 continue;
80542 }
80543- charge = 0;
80544- if (mpnt->vm_flags & VM_ACCOUNT) {
80545- unsigned long len = vma_pages(mpnt);
80546-
80547- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
80548- goto fail_nomem;
80549- charge = len;
80550- }
80551- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
80552- if (!tmp)
80553- goto fail_nomem;
80554- *tmp = *mpnt;
80555- INIT_LIST_HEAD(&tmp->anon_vma_chain);
80556- pol = mpol_dup(vma_policy(mpnt));
80557- retval = PTR_ERR(pol);
80558- if (IS_ERR(pol))
80559- goto fail_nomem_policy;
80560- vma_set_policy(tmp, pol);
80561- tmp->vm_mm = mm;
80562- if (anon_vma_fork(tmp, mpnt))
80563- goto fail_nomem_anon_vma_fork;
80564- tmp->vm_flags &= ~VM_LOCKED;
80565- tmp->vm_next = tmp->vm_prev = NULL;
80566- file = tmp->vm_file;
80567- if (file) {
80568- struct inode *inode = file_inode(file);
80569- struct address_space *mapping = file->f_mapping;
80570-
80571- get_file(file);
80572- if (tmp->vm_flags & VM_DENYWRITE)
80573- atomic_dec(&inode->i_writecount);
80574- mutex_lock(&mapping->i_mmap_mutex);
80575- if (tmp->vm_flags & VM_SHARED)
80576- mapping->i_mmap_writable++;
80577- flush_dcache_mmap_lock(mapping);
80578- /* insert tmp into the share list, just after mpnt */
80579- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
80580- vma_nonlinear_insert(tmp,
80581- &mapping->i_mmap_nonlinear);
80582- else
80583- vma_interval_tree_insert_after(tmp, mpnt,
80584- &mapping->i_mmap);
80585- flush_dcache_mmap_unlock(mapping);
80586- mutex_unlock(&mapping->i_mmap_mutex);
80587+ tmp = dup_vma(mm, oldmm, mpnt);
80588+ if (!tmp) {
80589+ retval = -ENOMEM;
80590+ goto out;
80591 }
80592
80593 /*
80594@@ -462,6 +488,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
80595 if (retval)
80596 goto out;
80597 }
80598+
80599+#ifdef CONFIG_PAX_SEGMEXEC
80600+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
80601+ struct vm_area_struct *mpnt_m;
80602+
80603+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
80604+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
80605+
80606+ if (!mpnt->vm_mirror)
80607+ continue;
80608+
80609+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
80610+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
80611+ mpnt->vm_mirror = mpnt_m;
80612+ } else {
80613+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
80614+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
80615+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
80616+ mpnt->vm_mirror->vm_mirror = mpnt;
80617+ }
80618+ }
80619+ BUG_ON(mpnt_m);
80620+ }
80621+#endif
80622+
80623 /* a new mm has just been created */
80624 arch_dup_mmap(oldmm, mm);
80625 retval = 0;
80626@@ -471,14 +522,6 @@ out:
80627 up_write(&oldmm->mmap_sem);
80628 uprobe_end_dup_mmap();
80629 return retval;
80630-fail_nomem_anon_vma_fork:
80631- mpol_put(pol);
80632-fail_nomem_policy:
80633- kmem_cache_free(vm_area_cachep, tmp);
80634-fail_nomem:
80635- retval = -ENOMEM;
80636- vm_unacct_memory(charge);
80637- goto out;
80638 }
80639
80640 static inline int mm_alloc_pgd(struct mm_struct *mm)
80641@@ -691,8 +734,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
80642 return ERR_PTR(err);
80643
80644 mm = get_task_mm(task);
80645- if (mm && mm != current->mm &&
80646- !ptrace_may_access(task, mode)) {
80647+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
80648+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
80649 mmput(mm);
80650 mm = ERR_PTR(-EACCES);
80651 }
80652@@ -914,13 +957,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
80653 spin_unlock(&fs->lock);
80654 return -EAGAIN;
80655 }
80656- fs->users++;
80657+ atomic_inc(&fs->users);
80658 spin_unlock(&fs->lock);
80659 return 0;
80660 }
80661 tsk->fs = copy_fs_struct(fs);
80662 if (!tsk->fs)
80663 return -ENOMEM;
80664+ /* Carry through gr_chroot_dentry and is_chrooted instead
80665+ of recomputing it here. Already copied when the task struct
80666+ is duplicated. This allows pivot_root to not be treated as
80667+ a chroot
80668+ */
80669+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
80670+
80671 return 0;
80672 }
80673
80674@@ -1131,7 +1181,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
80675 * parts of the process environment (as per the clone
80676 * flags). The actual kick-off is left to the caller.
80677 */
80678-static struct task_struct *copy_process(unsigned long clone_flags,
80679+static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
80680 unsigned long stack_start,
80681 unsigned long stack_size,
80682 int __user *child_tidptr,
80683@@ -1200,6 +1250,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
80684 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
80685 #endif
80686 retval = -EAGAIN;
80687+
80688+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
80689+
80690 if (atomic_read(&p->real_cred->user->processes) >=
80691 task_rlimit(p, RLIMIT_NPROC)) {
80692 if (p->real_cred->user != INIT_USER &&
80693@@ -1449,6 +1502,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
80694 goto bad_fork_free_pid;
80695 }
80696
80697+ /* synchronizes with gr_set_acls()
80698+ we need to call this past the point of no return for fork()
80699+ */
80700+ gr_copy_label(p);
80701+
80702 if (likely(p->pid)) {
80703 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
80704
80705@@ -1534,6 +1592,8 @@ bad_fork_cleanup_count:
80706 bad_fork_free:
80707 free_task(p);
80708 fork_out:
80709+ gr_log_forkfail(retval);
80710+
80711 return ERR_PTR(retval);
80712 }
80713
80714@@ -1604,6 +1664,7 @@ long do_fork(unsigned long clone_flags,
80715
80716 p = copy_process(clone_flags, stack_start, stack_size,
80717 child_tidptr, NULL, trace);
80718+ add_latent_entropy();
80719 /*
80720 * Do this prior waking up the new thread - the thread pointer
80721 * might get invalid after that point, if the thread exits quickly.
80722@@ -1618,6 +1679,8 @@ long do_fork(unsigned long clone_flags,
80723 if (clone_flags & CLONE_PARENT_SETTID)
80724 put_user(nr, parent_tidptr);
80725
80726+ gr_handle_brute_check();
80727+
80728 if (clone_flags & CLONE_VFORK) {
80729 p->vfork_done = &vfork;
80730 init_completion(&vfork);
80731@@ -1734,7 +1797,7 @@ void __init proc_caches_init(void)
80732 mm_cachep = kmem_cache_create("mm_struct",
80733 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
80734 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
80735- vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
80736+ vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
80737 mmap_init();
80738 nsproxy_cache_init();
80739 }
80740@@ -1774,7 +1837,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
80741 return 0;
80742
80743 /* don't need lock here; in the worst case we'll do useless copy */
80744- if (fs->users == 1)
80745+ if (atomic_read(&fs->users) == 1)
80746 return 0;
80747
80748 *new_fsp = copy_fs_struct(fs);
80749@@ -1886,7 +1949,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
80750 fs = current->fs;
80751 spin_lock(&fs->lock);
80752 current->fs = new_fs;
80753- if (--fs->users)
80754+ gr_set_chroot_entries(current, &current->fs->root);
80755+ if (atomic_dec_return(&fs->users))
80756 new_fs = NULL;
80757 else
80758 new_fs = fs;
80759diff --git a/kernel/futex.c b/kernel/futex.c
80760index c3a1a55..e32b4a98 100644
80761--- a/kernel/futex.c
80762+++ b/kernel/futex.c
80763@@ -54,6 +54,7 @@
80764 #include <linux/mount.h>
80765 #include <linux/pagemap.h>
80766 #include <linux/syscalls.h>
80767+#include <linux/ptrace.h>
80768 #include <linux/signal.h>
80769 #include <linux/export.h>
80770 #include <linux/magic.h>
80771@@ -243,6 +244,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
80772 struct page *page, *page_head;
80773 int err, ro = 0;
80774
80775+#ifdef CONFIG_PAX_SEGMEXEC
80776+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
80777+ return -EFAULT;
80778+#endif
80779+
80780 /*
80781 * The futex address must be "naturally" aligned.
80782 */
80783@@ -441,7 +447,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
80784
80785 static int get_futex_value_locked(u32 *dest, u32 __user *from)
80786 {
80787- int ret;
80788+ unsigned long ret;
80789
80790 pagefault_disable();
80791 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
80792@@ -2734,6 +2740,7 @@ static int __init futex_init(void)
80793 {
80794 u32 curval;
80795 int i;
80796+ mm_segment_t oldfs;
80797
80798 /*
80799 * This will fail and we want it. Some arch implementations do
80800@@ -2745,8 +2752,11 @@ static int __init futex_init(void)
80801 * implementation, the non-functional ones will return
80802 * -ENOSYS.
80803 */
80804+ oldfs = get_fs();
80805+ set_fs(USER_DS);
80806 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
80807 futex_cmpxchg_enabled = 1;
80808+ set_fs(oldfs);
80809
80810 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
80811 plist_head_init(&futex_queues[i].chain);
80812diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
80813index f9f44fd..29885e4 100644
80814--- a/kernel/futex_compat.c
80815+++ b/kernel/futex_compat.c
80816@@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
80817 return 0;
80818 }
80819
80820-static void __user *futex_uaddr(struct robust_list __user *entry,
80821+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
80822 compat_long_t futex_offset)
80823 {
80824 compat_uptr_t base = ptr_to_compat(entry);
80825diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
80826index 9b22d03..6295b62 100644
80827--- a/kernel/gcov/base.c
80828+++ b/kernel/gcov/base.c
80829@@ -102,11 +102,6 @@ void gcov_enable_events(void)
80830 }
80831
80832 #ifdef CONFIG_MODULES
80833-static inline int within(void *addr, void *start, unsigned long size)
80834-{
80835- return ((addr >= start) && (addr < start + size));
80836-}
80837-
80838 /* Update list and generate events when modules are unloaded. */
80839 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
80840 void *data)
80841@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
80842 prev = NULL;
80843 /* Remove entries located in module from linked list. */
80844 for (info = gcov_info_head; info; info = info->next) {
80845- if (within(info, mod->module_core, mod->core_size)) {
80846+ if (within_module_core_rw((unsigned long)info, mod)) {
80847 if (prev)
80848 prev->next = info->next;
80849 else
80850diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
80851index 383319b..cd2b391 100644
80852--- a/kernel/hrtimer.c
80853+++ b/kernel/hrtimer.c
80854@@ -1438,7 +1438,7 @@ void hrtimer_peek_ahead_timers(void)
80855 local_irq_restore(flags);
80856 }
80857
80858-static void run_hrtimer_softirq(struct softirq_action *h)
80859+static void run_hrtimer_softirq(void)
80860 {
80861 hrtimer_peek_ahead_timers();
80862 }
80863diff --git a/kernel/irq_work.c b/kernel/irq_work.c
80864index 55fcce6..0e4cf34 100644
80865--- a/kernel/irq_work.c
80866+++ b/kernel/irq_work.c
80867@@ -189,12 +189,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
80868 return NOTIFY_OK;
80869 }
80870
80871-static struct notifier_block cpu_notify;
80872+static struct notifier_block cpu_notify = {
80873+ .notifier_call = irq_work_cpu_notify,
80874+ .priority = 0,
80875+};
80876
80877 static __init int irq_work_init_cpu_notifier(void)
80878 {
80879- cpu_notify.notifier_call = irq_work_cpu_notify;
80880- cpu_notify.priority = 0;
80881 register_cpu_notifier(&cpu_notify);
80882 return 0;
80883 }
80884diff --git a/kernel/jump_label.c b/kernel/jump_label.c
80885index 60f48fa..7f3a770 100644
80886--- a/kernel/jump_label.c
80887+++ b/kernel/jump_label.c
80888@@ -13,6 +13,7 @@
80889 #include <linux/sort.h>
80890 #include <linux/err.h>
80891 #include <linux/static_key.h>
80892+#include <linux/mm.h>
80893
80894 #ifdef HAVE_JUMP_LABEL
80895
80896@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
80897
80898 size = (((unsigned long)stop - (unsigned long)start)
80899 / sizeof(struct jump_entry));
80900+ pax_open_kernel();
80901 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
80902+ pax_close_kernel();
80903 }
80904
80905 static void jump_label_update(struct static_key *key, int enable);
80906@@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
80907 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
80908 struct jump_entry *iter;
80909
80910+ pax_open_kernel();
80911 for (iter = iter_start; iter < iter_stop; iter++) {
80912 if (within_module_init(iter->code, mod))
80913 iter->code = 0;
80914 }
80915+ pax_close_kernel();
80916 }
80917
80918 static int
80919diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
80920index 3127ad5..159d880 100644
80921--- a/kernel/kallsyms.c
80922+++ b/kernel/kallsyms.c
80923@@ -11,6 +11,9 @@
80924 * Changed the compression method from stem compression to "table lookup"
80925 * compression (see scripts/kallsyms.c for a more complete description)
80926 */
80927+#ifdef CONFIG_GRKERNSEC_HIDESYM
80928+#define __INCLUDED_BY_HIDESYM 1
80929+#endif
80930 #include <linux/kallsyms.h>
80931 #include <linux/module.h>
80932 #include <linux/init.h>
80933@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
80934
80935 static inline int is_kernel_inittext(unsigned long addr)
80936 {
80937+ if (system_state != SYSTEM_BOOTING)
80938+ return 0;
80939+
80940 if (addr >= (unsigned long)_sinittext
80941 && addr <= (unsigned long)_einittext)
80942 return 1;
80943 return 0;
80944 }
80945
80946+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
80947+#ifdef CONFIG_MODULES
80948+static inline int is_module_text(unsigned long addr)
80949+{
80950+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
80951+ return 1;
80952+
80953+ addr = ktla_ktva(addr);
80954+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
80955+}
80956+#else
80957+static inline int is_module_text(unsigned long addr)
80958+{
80959+ return 0;
80960+}
80961+#endif
80962+#endif
80963+
80964 static inline int is_kernel_text(unsigned long addr)
80965 {
80966 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
80967@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
80968
80969 static inline int is_kernel(unsigned long addr)
80970 {
80971+
80972+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
80973+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
80974+ return 1;
80975+
80976+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
80977+#else
80978 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
80979+#endif
80980+
80981 return 1;
80982 return in_gate_area_no_mm(addr);
80983 }
80984
80985 static int is_ksym_addr(unsigned long addr)
80986 {
80987+
80988+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
80989+ if (is_module_text(addr))
80990+ return 0;
80991+#endif
80992+
80993 if (all_var)
80994 return is_kernel(addr);
80995
80996@@ -480,7 +519,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
80997
80998 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
80999 {
81000- iter->name[0] = '\0';
81001 iter->nameoff = get_symbol_offset(new_pos);
81002 iter->pos = new_pos;
81003 }
81004@@ -528,6 +566,11 @@ static int s_show(struct seq_file *m, void *p)
81005 {
81006 struct kallsym_iter *iter = m->private;
81007
81008+#ifdef CONFIG_GRKERNSEC_HIDESYM
81009+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
81010+ return 0;
81011+#endif
81012+
81013 /* Some debugging symbols have no name. Ignore them. */
81014 if (!iter->name[0])
81015 return 0;
81016@@ -541,6 +584,7 @@ static int s_show(struct seq_file *m, void *p)
81017 */
81018 type = iter->exported ? toupper(iter->type) :
81019 tolower(iter->type);
81020+
81021 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
81022 type, iter->name, iter->module_name);
81023 } else
81024@@ -566,7 +610,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
81025 struct kallsym_iter *iter;
81026 int ret;
81027
81028- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
81029+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
81030 if (!iter)
81031 return -ENOMEM;
81032 reset_iter(iter, 0);
81033diff --git a/kernel/kcmp.c b/kernel/kcmp.c
81034index e30ac0f..3528cac 100644
81035--- a/kernel/kcmp.c
81036+++ b/kernel/kcmp.c
81037@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
81038 struct task_struct *task1, *task2;
81039 int ret;
81040
81041+#ifdef CONFIG_GRKERNSEC
81042+ return -ENOSYS;
81043+#endif
81044+
81045 rcu_read_lock();
81046
81047 /*
81048diff --git a/kernel/kexec.c b/kernel/kexec.c
81049index 59f7b55..4022f65 100644
81050--- a/kernel/kexec.c
81051+++ b/kernel/kexec.c
81052@@ -1041,7 +1041,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
81053 unsigned long flags)
81054 {
81055 struct compat_kexec_segment in;
81056- struct kexec_segment out, __user *ksegments;
81057+ struct kexec_segment out;
81058+ struct kexec_segment __user *ksegments;
81059 unsigned long i, result;
81060
81061 /* Don't allow clients that don't understand the native
81062diff --git a/kernel/kmod.c b/kernel/kmod.c
81063index fb32636..2fe8775 100644
81064--- a/kernel/kmod.c
81065+++ b/kernel/kmod.c
81066@@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
81067 kfree(info->argv);
81068 }
81069
81070-static int call_modprobe(char *module_name, int wait)
81071+static int call_modprobe(char *module_name, char *module_param, int wait)
81072 {
81073 struct subprocess_info *info;
81074 static char *envp[] = {
81075@@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
81076 NULL
81077 };
81078
81079- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
81080+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
81081 if (!argv)
81082 goto out;
81083
81084@@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
81085 argv[1] = "-q";
81086 argv[2] = "--";
81087 argv[3] = module_name; /* check free_modprobe_argv() */
81088- argv[4] = NULL;
81089+ argv[4] = module_param;
81090+ argv[5] = NULL;
81091
81092 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
81093 NULL, free_modprobe_argv, NULL);
81094@@ -129,9 +130,8 @@ out:
81095 * If module auto-loading support is disabled then this function
81096 * becomes a no-operation.
81097 */
81098-int __request_module(bool wait, const char *fmt, ...)
81099+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
81100 {
81101- va_list args;
81102 char module_name[MODULE_NAME_LEN];
81103 unsigned int max_modprobes;
81104 int ret;
81105@@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
81106 if (!modprobe_path[0])
81107 return 0;
81108
81109- va_start(args, fmt);
81110- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
81111- va_end(args);
81112+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
81113 if (ret >= MODULE_NAME_LEN)
81114 return -ENAMETOOLONG;
81115
81116@@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
81117 if (ret)
81118 return ret;
81119
81120+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81121+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
81122+ /* hack to workaround consolekit/udisks stupidity */
81123+ read_lock(&tasklist_lock);
81124+ if (!strcmp(current->comm, "mount") &&
81125+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
81126+ read_unlock(&tasklist_lock);
81127+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
81128+ return -EPERM;
81129+ }
81130+ read_unlock(&tasklist_lock);
81131+ }
81132+#endif
81133+
81134 /* If modprobe needs a service that is in a module, we get a recursive
81135 * loop. Limit the number of running kmod threads to max_threads/2 or
81136 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
81137@@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
81138
81139 trace_module_request(module_name, wait, _RET_IP_);
81140
81141- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
81142+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
81143
81144 atomic_dec(&kmod_concurrent);
81145 return ret;
81146 }
81147+
81148+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
81149+{
81150+ va_list args;
81151+ int ret;
81152+
81153+ va_start(args, fmt);
81154+ ret = ____request_module(wait, module_param, fmt, args);
81155+ va_end(args);
81156+
81157+ return ret;
81158+}
81159+
81160+int __request_module(bool wait, const char *fmt, ...)
81161+{
81162+ va_list args;
81163+ int ret;
81164+
81165+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81166+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
81167+ char module_param[MODULE_NAME_LEN];
81168+
81169+ memset(module_param, 0, sizeof(module_param));
81170+
81171+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
81172+
81173+ va_start(args, fmt);
81174+ ret = ____request_module(wait, module_param, fmt, args);
81175+ va_end(args);
81176+
81177+ return ret;
81178+ }
81179+#endif
81180+
81181+ va_start(args, fmt);
81182+ ret = ____request_module(wait, NULL, fmt, args);
81183+ va_end(args);
81184+
81185+ return ret;
81186+}
81187+
81188 EXPORT_SYMBOL(__request_module);
81189 #endif /* CONFIG_MODULES */
81190
81191@@ -303,7 +356,7 @@ static int wait_for_helper(void *data)
81192 *
81193 * Thus the __user pointer cast is valid here.
81194 */
81195- sys_wait4(pid, (int __user *)&ret, 0, NULL);
81196+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
81197
81198 /*
81199 * If ret is 0, either ____call_usermodehelper failed and the
81200@@ -646,7 +699,7 @@ EXPORT_SYMBOL(call_usermodehelper);
81201 static int proc_cap_handler(struct ctl_table *table, int write,
81202 void __user *buffer, size_t *lenp, loff_t *ppos)
81203 {
81204- struct ctl_table t;
81205+ ctl_table_no_const t;
81206 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
81207 kernel_cap_t new_cap;
81208 int err, i;
81209diff --git a/kernel/kprobes.c b/kernel/kprobes.c
81210index 6e33498..3133bd3 100644
81211--- a/kernel/kprobes.c
81212+++ b/kernel/kprobes.c
81213@@ -31,6 +31,9 @@
81214 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
81215 * <prasanna@in.ibm.com> added function-return probes.
81216 */
81217+#ifdef CONFIG_GRKERNSEC_HIDESYM
81218+#define __INCLUDED_BY_HIDESYM 1
81219+#endif
81220 #include <linux/kprobes.h>
81221 #include <linux/hash.h>
81222 #include <linux/init.h>
81223@@ -185,7 +188,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
81224 * kernel image and loaded module images reside. This is required
81225 * so x86_64 can correctly handle the %rip-relative fixups.
81226 */
81227- kip->insns = module_alloc(PAGE_SIZE);
81228+ kip->insns = module_alloc_exec(PAGE_SIZE);
81229 if (!kip->insns) {
81230 kfree(kip);
81231 return NULL;
81232@@ -225,7 +228,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
81233 */
81234 if (!list_is_singular(&kip->list)) {
81235 list_del(&kip->list);
81236- module_free(NULL, kip->insns);
81237+ module_free_exec(NULL, kip->insns);
81238 kfree(kip);
81239 }
81240 return 1;
81241@@ -2083,7 +2086,7 @@ static int __init init_kprobes(void)
81242 {
81243 int i, err = 0;
81244 unsigned long offset = 0, size = 0;
81245- char *modname, namebuf[128];
81246+ char *modname, namebuf[KSYM_NAME_LEN];
81247 const char *symbol_name;
81248 void *addr;
81249 struct kprobe_blackpoint *kb;
81250@@ -2168,11 +2171,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
81251 kprobe_type = "k";
81252
81253 if (sym)
81254- seq_printf(pi, "%p %s %s+0x%x %s ",
81255+ seq_printf(pi, "%pK %s %s+0x%x %s ",
81256 p->addr, kprobe_type, sym, offset,
81257 (modname ? modname : " "));
81258 else
81259- seq_printf(pi, "%p %s %p ",
81260+ seq_printf(pi, "%pK %s %pK ",
81261 p->addr, kprobe_type, p->addr);
81262
81263 if (!pp)
81264@@ -2209,7 +2212,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
81265 const char *sym = NULL;
81266 unsigned int i = *(loff_t *) v;
81267 unsigned long offset = 0;
81268- char *modname, namebuf[128];
81269+ char *modname, namebuf[KSYM_NAME_LEN];
81270
81271 head = &kprobe_table[i];
81272 preempt_disable();
81273diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
81274index 6ada93c..dce7d5d 100644
81275--- a/kernel/ksysfs.c
81276+++ b/kernel/ksysfs.c
81277@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
81278 {
81279 if (count+1 > UEVENT_HELPER_PATH_LEN)
81280 return -ENOENT;
81281+ if (!capable(CAP_SYS_ADMIN))
81282+ return -EPERM;
81283 memcpy(uevent_helper, buf, count);
81284 uevent_helper[count] = '\0';
81285 if (count && uevent_helper[count-1] == '\n')
81286@@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
81287 return count;
81288 }
81289
81290-static struct bin_attribute notes_attr = {
81291+static bin_attribute_no_const notes_attr __read_only = {
81292 .attr = {
81293 .name = "notes",
81294 .mode = S_IRUGO,
81295diff --git a/kernel/lockdep.c b/kernel/lockdep.c
81296index e16c45b..6f49c48 100644
81297--- a/kernel/lockdep.c
81298+++ b/kernel/lockdep.c
81299@@ -596,6 +596,10 @@ static int static_obj(void *obj)
81300 end = (unsigned long) &_end,
81301 addr = (unsigned long) obj;
81302
81303+#ifdef CONFIG_PAX_KERNEXEC
81304+ start = ktla_ktva(start);
81305+#endif
81306+
81307 /*
81308 * static variable?
81309 */
81310@@ -736,6 +740,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
81311 if (!static_obj(lock->key)) {
81312 debug_locks_off();
81313 printk("INFO: trying to register non-static key.\n");
81314+ printk("lock:%pS key:%pS.\n", lock, lock->key);
81315 printk("the code is fine but needs lockdep annotation.\n");
81316 printk("turning off the locking correctness validator.\n");
81317 dump_stack();
81318@@ -3080,7 +3085,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
81319 if (!class)
81320 return 0;
81321 }
81322- atomic_inc((atomic_t *)&class->ops);
81323+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
81324 if (very_verbose(class)) {
81325 printk("\nacquire class [%p] %s", class->key, class->name);
81326 if (class->name_version > 1)
81327diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
81328index b2c71c5..7b88d63 100644
81329--- a/kernel/lockdep_proc.c
81330+++ b/kernel/lockdep_proc.c
81331@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
81332 return 0;
81333 }
81334
81335- seq_printf(m, "%p", class->key);
81336+ seq_printf(m, "%pK", class->key);
81337 #ifdef CONFIG_DEBUG_LOCKDEP
81338 seq_printf(m, " OPS:%8ld", class->ops);
81339 #endif
81340@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
81341
81342 list_for_each_entry(entry, &class->locks_after, entry) {
81343 if (entry->distance == 1) {
81344- seq_printf(m, " -> [%p] ", entry->class->key);
81345+ seq_printf(m, " -> [%pK] ", entry->class->key);
81346 print_name(m, entry->class);
81347 seq_puts(m, "\n");
81348 }
81349@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
81350 if (!class->key)
81351 continue;
81352
81353- seq_printf(m, "[%p] ", class->key);
81354+ seq_printf(m, "[%pK] ", class->key);
81355 print_name(m, class);
81356 seq_puts(m, "\n");
81357 }
81358@@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
81359 if (!i)
81360 seq_line(m, '-', 40-namelen, namelen);
81361
81362- snprintf(ip, sizeof(ip), "[<%p>]",
81363+ snprintf(ip, sizeof(ip), "[<%pK>]",
81364 (void *)class->contention_point[i]);
81365 seq_printf(m, "%40s %14lu %29s %pS\n",
81366 name, stats->contention_point[i],
81367@@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
81368 if (!i)
81369 seq_line(m, '-', 40-namelen, namelen);
81370
81371- snprintf(ip, sizeof(ip), "[<%p>]",
81372+ snprintf(ip, sizeof(ip), "[<%pK>]",
81373 (void *)class->contending_point[i]);
81374 seq_printf(m, "%40s %14lu %29s %pS\n",
81375 name, stats->contending_point[i],
81376diff --git a/kernel/module.c b/kernel/module.c
81377index 2069158..71101bb 100644
81378--- a/kernel/module.c
81379+++ b/kernel/module.c
81380@@ -61,6 +61,7 @@
81381 #include <linux/pfn.h>
81382 #include <linux/bsearch.h>
81383 #include <linux/fips.h>
81384+#include <linux/grsecurity.h>
81385 #include <uapi/linux/module.h>
81386 #include "module-internal.h"
81387
81388@@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
81389
81390 /* Bounds of module allocation, for speeding __module_address.
81391 * Protected by module_mutex. */
81392-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
81393+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
81394+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
81395
81396 int register_module_notifier(struct notifier_block * nb)
81397 {
81398@@ -323,7 +325,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
81399 return true;
81400
81401 list_for_each_entry_rcu(mod, &modules, list) {
81402- struct symsearch arr[] = {
81403+ struct symsearch modarr[] = {
81404 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
81405 NOT_GPL_ONLY, false },
81406 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
81407@@ -348,7 +350,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
81408 if (mod->state == MODULE_STATE_UNFORMED)
81409 continue;
81410
81411- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
81412+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
81413 return true;
81414 }
81415 return false;
81416@@ -490,7 +492,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
81417 if (!pcpusec->sh_size)
81418 return 0;
81419
81420- if (align > PAGE_SIZE) {
81421+ if (align-1 >= PAGE_SIZE) {
81422 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
81423 mod->name, align, PAGE_SIZE);
81424 align = PAGE_SIZE;
81425@@ -1096,7 +1098,7 @@ struct module_attribute module_uevent =
81426 static ssize_t show_coresize(struct module_attribute *mattr,
81427 struct module_kobject *mk, char *buffer)
81428 {
81429- return sprintf(buffer, "%u\n", mk->mod->core_size);
81430+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
81431 }
81432
81433 static struct module_attribute modinfo_coresize =
81434@@ -1105,7 +1107,7 @@ static struct module_attribute modinfo_coresize =
81435 static ssize_t show_initsize(struct module_attribute *mattr,
81436 struct module_kobject *mk, char *buffer)
81437 {
81438- return sprintf(buffer, "%u\n", mk->mod->init_size);
81439+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
81440 }
81441
81442 static struct module_attribute modinfo_initsize =
81443@@ -1320,7 +1322,7 @@ resolve_symbol_wait(struct module *mod,
81444 */
81445 #ifdef CONFIG_SYSFS
81446
81447-#ifdef CONFIG_KALLSYMS
81448+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
81449 static inline bool sect_empty(const Elf_Shdr *sect)
81450 {
81451 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
81452@@ -1460,7 +1462,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
81453 {
81454 unsigned int notes, loaded, i;
81455 struct module_notes_attrs *notes_attrs;
81456- struct bin_attribute *nattr;
81457+ bin_attribute_no_const *nattr;
81458
81459 /* failed to create section attributes, so can't create notes */
81460 if (!mod->sect_attrs)
81461@@ -1572,7 +1574,7 @@ static void del_usage_links(struct module *mod)
81462 static int module_add_modinfo_attrs(struct module *mod)
81463 {
81464 struct module_attribute *attr;
81465- struct module_attribute *temp_attr;
81466+ module_attribute_no_const *temp_attr;
81467 int error = 0;
81468 int i;
81469
81470@@ -1786,21 +1788,21 @@ static void set_section_ro_nx(void *base,
81471
81472 static void unset_module_core_ro_nx(struct module *mod)
81473 {
81474- set_page_attributes(mod->module_core + mod->core_text_size,
81475- mod->module_core + mod->core_size,
81476+ set_page_attributes(mod->module_core_rw,
81477+ mod->module_core_rw + mod->core_size_rw,
81478 set_memory_x);
81479- set_page_attributes(mod->module_core,
81480- mod->module_core + mod->core_ro_size,
81481+ set_page_attributes(mod->module_core_rx,
81482+ mod->module_core_rx + mod->core_size_rx,
81483 set_memory_rw);
81484 }
81485
81486 static void unset_module_init_ro_nx(struct module *mod)
81487 {
81488- set_page_attributes(mod->module_init + mod->init_text_size,
81489- mod->module_init + mod->init_size,
81490+ set_page_attributes(mod->module_init_rw,
81491+ mod->module_init_rw + mod->init_size_rw,
81492 set_memory_x);
81493- set_page_attributes(mod->module_init,
81494- mod->module_init + mod->init_ro_size,
81495+ set_page_attributes(mod->module_init_rx,
81496+ mod->module_init_rx + mod->init_size_rx,
81497 set_memory_rw);
81498 }
81499
81500@@ -1813,14 +1815,14 @@ void set_all_modules_text_rw(void)
81501 list_for_each_entry_rcu(mod, &modules, list) {
81502 if (mod->state == MODULE_STATE_UNFORMED)
81503 continue;
81504- if ((mod->module_core) && (mod->core_text_size)) {
81505- set_page_attributes(mod->module_core,
81506- mod->module_core + mod->core_text_size,
81507+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
81508+ set_page_attributes(mod->module_core_rx,
81509+ mod->module_core_rx + mod->core_size_rx,
81510 set_memory_rw);
81511 }
81512- if ((mod->module_init) && (mod->init_text_size)) {
81513- set_page_attributes(mod->module_init,
81514- mod->module_init + mod->init_text_size,
81515+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
81516+ set_page_attributes(mod->module_init_rx,
81517+ mod->module_init_rx + mod->init_size_rx,
81518 set_memory_rw);
81519 }
81520 }
81521@@ -1836,14 +1838,14 @@ void set_all_modules_text_ro(void)
81522 list_for_each_entry_rcu(mod, &modules, list) {
81523 if (mod->state == MODULE_STATE_UNFORMED)
81524 continue;
81525- if ((mod->module_core) && (mod->core_text_size)) {
81526- set_page_attributes(mod->module_core,
81527- mod->module_core + mod->core_text_size,
81528+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
81529+ set_page_attributes(mod->module_core_rx,
81530+ mod->module_core_rx + mod->core_size_rx,
81531 set_memory_ro);
81532 }
81533- if ((mod->module_init) && (mod->init_text_size)) {
81534- set_page_attributes(mod->module_init,
81535- mod->module_init + mod->init_text_size,
81536+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
81537+ set_page_attributes(mod->module_init_rx,
81538+ mod->module_init_rx + mod->init_size_rx,
81539 set_memory_ro);
81540 }
81541 }
81542@@ -1894,16 +1896,19 @@ static void free_module(struct module *mod)
81543
81544 /* This may be NULL, but that's OK */
81545 unset_module_init_ro_nx(mod);
81546- module_free(mod, mod->module_init);
81547+ module_free(mod, mod->module_init_rw);
81548+ module_free_exec(mod, mod->module_init_rx);
81549 kfree(mod->args);
81550 percpu_modfree(mod);
81551
81552 /* Free lock-classes: */
81553- lockdep_free_key_range(mod->module_core, mod->core_size);
81554+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
81555+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
81556
81557 /* Finally, free the core (containing the module structure) */
81558 unset_module_core_ro_nx(mod);
81559- module_free(mod, mod->module_core);
81560+ module_free_exec(mod, mod->module_core_rx);
81561+ module_free(mod, mod->module_core_rw);
81562
81563 #ifdef CONFIG_MPU
81564 update_protections(current->mm);
81565@@ -1973,9 +1978,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
81566 int ret = 0;
81567 const struct kernel_symbol *ksym;
81568
81569+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81570+ int is_fs_load = 0;
81571+ int register_filesystem_found = 0;
81572+ char *p;
81573+
81574+ p = strstr(mod->args, "grsec_modharden_fs");
81575+ if (p) {
81576+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
81577+ /* copy \0 as well */
81578+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
81579+ is_fs_load = 1;
81580+ }
81581+#endif
81582+
81583 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
81584 const char *name = info->strtab + sym[i].st_name;
81585
81586+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81587+ /* it's a real shame this will never get ripped and copied
81588+ upstream! ;(
81589+ */
81590+ if (is_fs_load && !strcmp(name, "register_filesystem"))
81591+ register_filesystem_found = 1;
81592+#endif
81593+
81594 switch (sym[i].st_shndx) {
81595 case SHN_COMMON:
81596 /* We compiled with -fno-common. These are not
81597@@ -1996,7 +2023,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
81598 ksym = resolve_symbol_wait(mod, info, name);
81599 /* Ok if resolved. */
81600 if (ksym && !IS_ERR(ksym)) {
81601+ pax_open_kernel();
81602 sym[i].st_value = ksym->value;
81603+ pax_close_kernel();
81604 break;
81605 }
81606
81607@@ -2015,11 +2044,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
81608 secbase = (unsigned long)mod_percpu(mod);
81609 else
81610 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
81611+ pax_open_kernel();
81612 sym[i].st_value += secbase;
81613+ pax_close_kernel();
81614 break;
81615 }
81616 }
81617
81618+#ifdef CONFIG_GRKERNSEC_MODHARDEN
81619+ if (is_fs_load && !register_filesystem_found) {
81620+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
81621+ ret = -EPERM;
81622+ }
81623+#endif
81624+
81625 return ret;
81626 }
81627
81628@@ -2103,22 +2141,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
81629 || s->sh_entsize != ~0UL
81630 || strstarts(sname, ".init"))
81631 continue;
81632- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
81633+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
81634+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
81635+ else
81636+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
81637 pr_debug("\t%s\n", sname);
81638 }
81639- switch (m) {
81640- case 0: /* executable */
81641- mod->core_size = debug_align(mod->core_size);
81642- mod->core_text_size = mod->core_size;
81643- break;
81644- case 1: /* RO: text and ro-data */
81645- mod->core_size = debug_align(mod->core_size);
81646- mod->core_ro_size = mod->core_size;
81647- break;
81648- case 3: /* whole core */
81649- mod->core_size = debug_align(mod->core_size);
81650- break;
81651- }
81652 }
81653
81654 pr_debug("Init section allocation order:\n");
81655@@ -2132,23 +2160,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
81656 || s->sh_entsize != ~0UL
81657 || !strstarts(sname, ".init"))
81658 continue;
81659- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
81660- | INIT_OFFSET_MASK);
81661+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
81662+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
81663+ else
81664+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
81665+ s->sh_entsize |= INIT_OFFSET_MASK;
81666 pr_debug("\t%s\n", sname);
81667 }
81668- switch (m) {
81669- case 0: /* executable */
81670- mod->init_size = debug_align(mod->init_size);
81671- mod->init_text_size = mod->init_size;
81672- break;
81673- case 1: /* RO: text and ro-data */
81674- mod->init_size = debug_align(mod->init_size);
81675- mod->init_ro_size = mod->init_size;
81676- break;
81677- case 3: /* whole init */
81678- mod->init_size = debug_align(mod->init_size);
81679- break;
81680- }
81681 }
81682 }
81683
81684@@ -2321,7 +2339,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
81685
81686 /* Put symbol section at end of init part of module. */
81687 symsect->sh_flags |= SHF_ALLOC;
81688- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
81689+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
81690 info->index.sym) | INIT_OFFSET_MASK;
81691 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
81692
81693@@ -2338,13 +2356,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
81694 }
81695
81696 /* Append room for core symbols at end of core part. */
81697- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
81698- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
81699- mod->core_size += strtab_size;
81700+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
81701+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
81702+ mod->core_size_rx += strtab_size;
81703
81704 /* Put string table section at end of init part of module. */
81705 strsect->sh_flags |= SHF_ALLOC;
81706- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
81707+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
81708 info->index.str) | INIT_OFFSET_MASK;
81709 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
81710 }
81711@@ -2362,12 +2380,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
81712 /* Make sure we get permanent strtab: don't use info->strtab. */
81713 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
81714
81715+ pax_open_kernel();
81716+
81717 /* Set types up while we still have access to sections. */
81718 for (i = 0; i < mod->num_symtab; i++)
81719 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
81720
81721- mod->core_symtab = dst = mod->module_core + info->symoffs;
81722- mod->core_strtab = s = mod->module_core + info->stroffs;
81723+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
81724+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
81725 src = mod->symtab;
81726 for (ndst = i = 0; i < mod->num_symtab; i++) {
81727 if (i == 0 ||
81728@@ -2379,6 +2399,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
81729 }
81730 }
81731 mod->core_num_syms = ndst;
81732+
81733+ pax_close_kernel();
81734 }
81735 #else
81736 static inline void layout_symtab(struct module *mod, struct load_info *info)
81737@@ -2412,17 +2434,33 @@ void * __weak module_alloc(unsigned long size)
81738 return vmalloc_exec(size);
81739 }
81740
81741-static void *module_alloc_update_bounds(unsigned long size)
81742+static void *module_alloc_update_bounds_rw(unsigned long size)
81743 {
81744 void *ret = module_alloc(size);
81745
81746 if (ret) {
81747 mutex_lock(&module_mutex);
81748 /* Update module bounds. */
81749- if ((unsigned long)ret < module_addr_min)
81750- module_addr_min = (unsigned long)ret;
81751- if ((unsigned long)ret + size > module_addr_max)
81752- module_addr_max = (unsigned long)ret + size;
81753+ if ((unsigned long)ret < module_addr_min_rw)
81754+ module_addr_min_rw = (unsigned long)ret;
81755+ if ((unsigned long)ret + size > module_addr_max_rw)
81756+ module_addr_max_rw = (unsigned long)ret + size;
81757+ mutex_unlock(&module_mutex);
81758+ }
81759+ return ret;
81760+}
81761+
81762+static void *module_alloc_update_bounds_rx(unsigned long size)
81763+{
81764+ void *ret = module_alloc_exec(size);
81765+
81766+ if (ret) {
81767+ mutex_lock(&module_mutex);
81768+ /* Update module bounds. */
81769+ if ((unsigned long)ret < module_addr_min_rx)
81770+ module_addr_min_rx = (unsigned long)ret;
81771+ if ((unsigned long)ret + size > module_addr_max_rx)
81772+ module_addr_max_rx = (unsigned long)ret + size;
81773 mutex_unlock(&module_mutex);
81774 }
81775 return ret;
81776@@ -2698,8 +2736,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
81777 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
81778 {
81779 const char *modmagic = get_modinfo(info, "vermagic");
81780+ const char *license = get_modinfo(info, "license");
81781 int err;
81782
81783+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
81784+ if (!license || !license_is_gpl_compatible(license))
81785+ return -ENOEXEC;
81786+#endif
81787+
81788 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
81789 modmagic = NULL;
81790
81791@@ -2725,7 +2769,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
81792 }
81793
81794 /* Set up license info based on the info section */
81795- set_license(mod, get_modinfo(info, "license"));
81796+ set_license(mod, license);
81797
81798 return 0;
81799 }
81800@@ -2806,7 +2850,7 @@ static int move_module(struct module *mod, struct load_info *info)
81801 void *ptr;
81802
81803 /* Do the allocs. */
81804- ptr = module_alloc_update_bounds(mod->core_size);
81805+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
81806 /*
81807 * The pointer to this block is stored in the module structure
81808 * which is inside the block. Just mark it as not being a
81809@@ -2816,11 +2860,11 @@ static int move_module(struct module *mod, struct load_info *info)
81810 if (!ptr)
81811 return -ENOMEM;
81812
81813- memset(ptr, 0, mod->core_size);
81814- mod->module_core = ptr;
81815+ memset(ptr, 0, mod->core_size_rw);
81816+ mod->module_core_rw = ptr;
81817
81818- if (mod->init_size) {
81819- ptr = module_alloc_update_bounds(mod->init_size);
81820+ if (mod->init_size_rw) {
81821+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
81822 /*
81823 * The pointer to this block is stored in the module structure
81824 * which is inside the block. This block doesn't need to be
81825@@ -2829,13 +2873,45 @@ static int move_module(struct module *mod, struct load_info *info)
81826 */
81827 kmemleak_ignore(ptr);
81828 if (!ptr) {
81829- module_free(mod, mod->module_core);
81830+ module_free(mod, mod->module_core_rw);
81831 return -ENOMEM;
81832 }
81833- memset(ptr, 0, mod->init_size);
81834- mod->module_init = ptr;
81835+ memset(ptr, 0, mod->init_size_rw);
81836+ mod->module_init_rw = ptr;
81837 } else
81838- mod->module_init = NULL;
81839+ mod->module_init_rw = NULL;
81840+
81841+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
81842+ kmemleak_not_leak(ptr);
81843+ if (!ptr) {
81844+ if (mod->module_init_rw)
81845+ module_free(mod, mod->module_init_rw);
81846+ module_free(mod, mod->module_core_rw);
81847+ return -ENOMEM;
81848+ }
81849+
81850+ pax_open_kernel();
81851+ memset(ptr, 0, mod->core_size_rx);
81852+ pax_close_kernel();
81853+ mod->module_core_rx = ptr;
81854+
81855+ if (mod->init_size_rx) {
81856+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
81857+ kmemleak_ignore(ptr);
81858+ if (!ptr && mod->init_size_rx) {
81859+ module_free_exec(mod, mod->module_core_rx);
81860+ if (mod->module_init_rw)
81861+ module_free(mod, mod->module_init_rw);
81862+ module_free(mod, mod->module_core_rw);
81863+ return -ENOMEM;
81864+ }
81865+
81866+ pax_open_kernel();
81867+ memset(ptr, 0, mod->init_size_rx);
81868+ pax_close_kernel();
81869+ mod->module_init_rx = ptr;
81870+ } else
81871+ mod->module_init_rx = NULL;
81872
81873 /* Transfer each section which specifies SHF_ALLOC */
81874 pr_debug("final section addresses:\n");
81875@@ -2846,16 +2922,45 @@ static int move_module(struct module *mod, struct load_info *info)
81876 if (!(shdr->sh_flags & SHF_ALLOC))
81877 continue;
81878
81879- if (shdr->sh_entsize & INIT_OFFSET_MASK)
81880- dest = mod->module_init
81881- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
81882- else
81883- dest = mod->module_core + shdr->sh_entsize;
81884+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
81885+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
81886+ dest = mod->module_init_rw
81887+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
81888+ else
81889+ dest = mod->module_init_rx
81890+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
81891+ } else {
81892+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
81893+ dest = mod->module_core_rw + shdr->sh_entsize;
81894+ else
81895+ dest = mod->module_core_rx + shdr->sh_entsize;
81896+ }
81897+
81898+ if (shdr->sh_type != SHT_NOBITS) {
81899+
81900+#ifdef CONFIG_PAX_KERNEXEC
81901+#ifdef CONFIG_X86_64
81902+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
81903+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
81904+#endif
81905+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
81906+ pax_open_kernel();
81907+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
81908+ pax_close_kernel();
81909+ } else
81910+#endif
81911
81912- if (shdr->sh_type != SHT_NOBITS)
81913 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
81914+ }
81915 /* Update sh_addr to point to copy in image. */
81916- shdr->sh_addr = (unsigned long)dest;
81917+
81918+#ifdef CONFIG_PAX_KERNEXEC
81919+ if (shdr->sh_flags & SHF_EXECINSTR)
81920+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
81921+ else
81922+#endif
81923+
81924+ shdr->sh_addr = (unsigned long)dest;
81925 pr_debug("\t0x%lx %s\n",
81926 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
81927 }
81928@@ -2912,12 +3017,12 @@ static void flush_module_icache(const struct module *mod)
81929 * Do it before processing of module parameters, so the module
81930 * can provide parameter accessor functions of its own.
81931 */
81932- if (mod->module_init)
81933- flush_icache_range((unsigned long)mod->module_init,
81934- (unsigned long)mod->module_init
81935- + mod->init_size);
81936- flush_icache_range((unsigned long)mod->module_core,
81937- (unsigned long)mod->module_core + mod->core_size);
81938+ if (mod->module_init_rx)
81939+ flush_icache_range((unsigned long)mod->module_init_rx,
81940+ (unsigned long)mod->module_init_rx
81941+ + mod->init_size_rx);
81942+ flush_icache_range((unsigned long)mod->module_core_rx,
81943+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
81944
81945 set_fs(old_fs);
81946 }
81947@@ -2974,8 +3079,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
81948 static void module_deallocate(struct module *mod, struct load_info *info)
81949 {
81950 percpu_modfree(mod);
81951- module_free(mod, mod->module_init);
81952- module_free(mod, mod->module_core);
81953+ module_free_exec(mod, mod->module_init_rx);
81954+ module_free_exec(mod, mod->module_core_rx);
81955+ module_free(mod, mod->module_init_rw);
81956+ module_free(mod, mod->module_core_rw);
81957 }
81958
81959 int __weak module_finalize(const Elf_Ehdr *hdr,
81960@@ -2988,7 +3095,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
81961 static int post_relocation(struct module *mod, const struct load_info *info)
81962 {
81963 /* Sort exception table now relocations are done. */
81964+ pax_open_kernel();
81965 sort_extable(mod->extable, mod->extable + mod->num_exentries);
81966+ pax_close_kernel();
81967
81968 /* Copy relocated percpu area over. */
81969 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
81970@@ -3042,16 +3151,16 @@ static int do_init_module(struct module *mod)
81971 MODULE_STATE_COMING, mod);
81972
81973 /* Set RO and NX regions for core */
81974- set_section_ro_nx(mod->module_core,
81975- mod->core_text_size,
81976- mod->core_ro_size,
81977- mod->core_size);
81978+ set_section_ro_nx(mod->module_core_rx,
81979+ mod->core_size_rx,
81980+ mod->core_size_rx,
81981+ mod->core_size_rx);
81982
81983 /* Set RO and NX regions for init */
81984- set_section_ro_nx(mod->module_init,
81985- mod->init_text_size,
81986- mod->init_ro_size,
81987- mod->init_size);
81988+ set_section_ro_nx(mod->module_init_rx,
81989+ mod->init_size_rx,
81990+ mod->init_size_rx,
81991+ mod->init_size_rx);
81992
81993 do_mod_ctors(mod);
81994 /* Start the module */
81995@@ -3113,11 +3222,12 @@ static int do_init_module(struct module *mod)
81996 mod->strtab = mod->core_strtab;
81997 #endif
81998 unset_module_init_ro_nx(mod);
81999- module_free(mod, mod->module_init);
82000- mod->module_init = NULL;
82001- mod->init_size = 0;
82002- mod->init_ro_size = 0;
82003- mod->init_text_size = 0;
82004+ module_free(mod, mod->module_init_rw);
82005+ module_free_exec(mod, mod->module_init_rx);
82006+ mod->module_init_rw = NULL;
82007+ mod->module_init_rx = NULL;
82008+ mod->init_size_rw = 0;
82009+ mod->init_size_rx = 0;
82010 mutex_unlock(&module_mutex);
82011 wake_up_all(&module_wq);
82012
82013@@ -3261,9 +3371,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
82014 if (err)
82015 goto free_unload;
82016
82017+ /* Now copy in args */
82018+ mod->args = strndup_user(uargs, ~0UL >> 1);
82019+ if (IS_ERR(mod->args)) {
82020+ err = PTR_ERR(mod->args);
82021+ goto free_unload;
82022+ }
82023+
82024 /* Set up MODINFO_ATTR fields */
82025 setup_modinfo(mod, info);
82026
82027+#ifdef CONFIG_GRKERNSEC_MODHARDEN
82028+ {
82029+ char *p, *p2;
82030+
82031+ if (strstr(mod->args, "grsec_modharden_netdev")) {
82032+ 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);
82033+ err = -EPERM;
82034+ goto free_modinfo;
82035+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
82036+ p += sizeof("grsec_modharden_normal") - 1;
82037+ p2 = strstr(p, "_");
82038+ if (p2) {
82039+ *p2 = '\0';
82040+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
82041+ *p2 = '_';
82042+ }
82043+ err = -EPERM;
82044+ goto free_modinfo;
82045+ }
82046+ }
82047+#endif
82048+
82049 /* Fix up syms, so that st_value is a pointer to location. */
82050 err = simplify_symbols(mod, info);
82051 if (err < 0)
82052@@ -3279,13 +3418,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
82053
82054 flush_module_icache(mod);
82055
82056- /* Now copy in args */
82057- mod->args = strndup_user(uargs, ~0UL >> 1);
82058- if (IS_ERR(mod->args)) {
82059- err = PTR_ERR(mod->args);
82060- goto free_arch_cleanup;
82061- }
82062-
82063 dynamic_debug_setup(info->debug, info->num_debug);
82064
82065 /* Finally it's fully formed, ready to start executing. */
82066@@ -3320,11 +3452,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
82067 ddebug_cleanup:
82068 dynamic_debug_remove(info->debug);
82069 synchronize_sched();
82070- kfree(mod->args);
82071- free_arch_cleanup:
82072 module_arch_cleanup(mod);
82073 free_modinfo:
82074 free_modinfo(mod);
82075+ kfree(mod->args);
82076 free_unload:
82077 module_unload_free(mod);
82078 unlink_mod:
82079@@ -3407,10 +3538,16 @@ static const char *get_ksymbol(struct module *mod,
82080 unsigned long nextval;
82081
82082 /* At worse, next value is at end of module */
82083- if (within_module_init(addr, mod))
82084- nextval = (unsigned long)mod->module_init+mod->init_text_size;
82085+ if (within_module_init_rx(addr, mod))
82086+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
82087+ else if (within_module_init_rw(addr, mod))
82088+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
82089+ else if (within_module_core_rx(addr, mod))
82090+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
82091+ else if (within_module_core_rw(addr, mod))
82092+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
82093 else
82094- nextval = (unsigned long)mod->module_core+mod->core_text_size;
82095+ return NULL;
82096
82097 /* Scan for closest preceding symbol, and next symbol. (ELF
82098 starts real symbols at 1). */
82099@@ -3661,7 +3798,7 @@ static int m_show(struct seq_file *m, void *p)
82100 return 0;
82101
82102 seq_printf(m, "%s %u",
82103- mod->name, mod->init_size + mod->core_size);
82104+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
82105 print_unload_info(m, mod);
82106
82107 /* Informative for users. */
82108@@ -3670,7 +3807,7 @@ static int m_show(struct seq_file *m, void *p)
82109 mod->state == MODULE_STATE_COMING ? "Loading":
82110 "Live");
82111 /* Used by oprofile and other similar tools. */
82112- seq_printf(m, " 0x%pK", mod->module_core);
82113+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
82114
82115 /* Taints info */
82116 if (mod->taints)
82117@@ -3706,7 +3843,17 @@ static const struct file_operations proc_modules_operations = {
82118
82119 static int __init proc_modules_init(void)
82120 {
82121+#ifndef CONFIG_GRKERNSEC_HIDESYM
82122+#ifdef CONFIG_GRKERNSEC_PROC_USER
82123+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
82124+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
82125+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
82126+#else
82127 proc_create("modules", 0, NULL, &proc_modules_operations);
82128+#endif
82129+#else
82130+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
82131+#endif
82132 return 0;
82133 }
82134 module_init(proc_modules_init);
82135@@ -3767,14 +3914,14 @@ struct module *__module_address(unsigned long addr)
82136 {
82137 struct module *mod;
82138
82139- if (addr < module_addr_min || addr > module_addr_max)
82140+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
82141+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
82142 return NULL;
82143
82144 list_for_each_entry_rcu(mod, &modules, list) {
82145 if (mod->state == MODULE_STATE_UNFORMED)
82146 continue;
82147- if (within_module_core(addr, mod)
82148- || within_module_init(addr, mod))
82149+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
82150 return mod;
82151 }
82152 return NULL;
82153@@ -3809,11 +3956,20 @@ bool is_module_text_address(unsigned long addr)
82154 */
82155 struct module *__module_text_address(unsigned long addr)
82156 {
82157- struct module *mod = __module_address(addr);
82158+ struct module *mod;
82159+
82160+#ifdef CONFIG_X86_32
82161+ addr = ktla_ktva(addr);
82162+#endif
82163+
82164+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
82165+ return NULL;
82166+
82167+ mod = __module_address(addr);
82168+
82169 if (mod) {
82170 /* Make sure it's within the text section. */
82171- if (!within(addr, mod->module_init, mod->init_text_size)
82172- && !within(addr, mod->module_core, mod->core_text_size))
82173+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
82174 mod = NULL;
82175 }
82176 return mod;
82177diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
82178index 7e3443f..b2a1e6b 100644
82179--- a/kernel/mutex-debug.c
82180+++ b/kernel/mutex-debug.c
82181@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
82182 }
82183
82184 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
82185- struct thread_info *ti)
82186+ struct task_struct *task)
82187 {
82188 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
82189
82190 /* Mark the current thread as blocked on the lock: */
82191- ti->task->blocked_on = waiter;
82192+ task->blocked_on = waiter;
82193 }
82194
82195 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
82196- struct thread_info *ti)
82197+ struct task_struct *task)
82198 {
82199 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
82200- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
82201- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
82202- ti->task->blocked_on = NULL;
82203+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
82204+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
82205+ task->blocked_on = NULL;
82206
82207 list_del_init(&waiter->list);
82208 waiter->task = NULL;
82209diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
82210index 0799fd3..d06ae3b 100644
82211--- a/kernel/mutex-debug.h
82212+++ b/kernel/mutex-debug.h
82213@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
82214 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
82215 extern void debug_mutex_add_waiter(struct mutex *lock,
82216 struct mutex_waiter *waiter,
82217- struct thread_info *ti);
82218+ struct task_struct *task);
82219 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
82220- struct thread_info *ti);
82221+ struct task_struct *task);
82222 extern void debug_mutex_unlock(struct mutex *lock);
82223 extern void debug_mutex_init(struct mutex *lock, const char *name,
82224 struct lock_class_key *key);
82225diff --git a/kernel/mutex.c b/kernel/mutex.c
82226index a52ee7bb..f361f16 100644
82227--- a/kernel/mutex.c
82228+++ b/kernel/mutex.c
82229@@ -135,7 +135,7 @@ void mspin_lock(struct mspin_node **lock, struct mspin_node *node)
82230 node->locked = 1;
82231 return;
82232 }
82233- ACCESS_ONCE(prev->next) = node;
82234+ ACCESS_ONCE_RW(prev->next) = node;
82235 smp_wmb();
82236 /* Wait until the lock holder passes the lock down */
82237 while (!ACCESS_ONCE(node->locked))
82238@@ -156,7 +156,7 @@ static void mspin_unlock(struct mspin_node **lock, struct mspin_node *node)
82239 while (!(next = ACCESS_ONCE(node->next)))
82240 arch_mutex_cpu_relax();
82241 }
82242- ACCESS_ONCE(next->locked) = 1;
82243+ ACCESS_ONCE_RW(next->locked) = 1;
82244 smp_wmb();
82245 }
82246
82247@@ -514,7 +514,7 @@ slowpath:
82248 spin_lock_mutex(&lock->wait_lock, flags);
82249
82250 debug_mutex_lock_common(lock, &waiter);
82251- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
82252+ debug_mutex_add_waiter(lock, &waiter, task);
82253
82254 /* add waiting tasks to the end of the waitqueue (FIFO): */
82255 list_add_tail(&waiter.list, &lock->wait_list);
82256@@ -565,7 +565,7 @@ slowpath:
82257 done:
82258 lock_acquired(&lock->dep_map, ip);
82259 /* got the lock - rejoice! */
82260- mutex_remove_waiter(lock, &waiter, current_thread_info());
82261+ mutex_remove_waiter(lock, &waiter, task);
82262 mutex_set_owner(lock);
82263
82264 if (!__builtin_constant_p(ww_ctx == NULL)) {
82265@@ -604,7 +604,7 @@ done:
82266 return 0;
82267
82268 err:
82269- mutex_remove_waiter(lock, &waiter, task_thread_info(task));
82270+ mutex_remove_waiter(lock, &waiter, task);
82271 spin_unlock_mutex(&lock->wait_lock, flags);
82272 debug_mutex_free_waiter(&waiter);
82273 mutex_release(&lock->dep_map, 1, ip);
82274diff --git a/kernel/notifier.c b/kernel/notifier.c
82275index 2d5cc4c..d9ea600 100644
82276--- a/kernel/notifier.c
82277+++ b/kernel/notifier.c
82278@@ -5,6 +5,7 @@
82279 #include <linux/rcupdate.h>
82280 #include <linux/vmalloc.h>
82281 #include <linux/reboot.h>
82282+#include <linux/mm.h>
82283
82284 /*
82285 * Notifier list for kernel code which wants to be called
82286@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
82287 while ((*nl) != NULL) {
82288 if (n->priority > (*nl)->priority)
82289 break;
82290- nl = &((*nl)->next);
82291+ nl = (struct notifier_block **)&((*nl)->next);
82292 }
82293- n->next = *nl;
82294+ pax_open_kernel();
82295+ *(const void **)&n->next = *nl;
82296 rcu_assign_pointer(*nl, n);
82297+ pax_close_kernel();
82298 return 0;
82299 }
82300
82301@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
82302 return 0;
82303 if (n->priority > (*nl)->priority)
82304 break;
82305- nl = &((*nl)->next);
82306+ nl = (struct notifier_block **)&((*nl)->next);
82307 }
82308- n->next = *nl;
82309+ pax_open_kernel();
82310+ *(const void **)&n->next = *nl;
82311 rcu_assign_pointer(*nl, n);
82312+ pax_close_kernel();
82313 return 0;
82314 }
82315
82316@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
82317 {
82318 while ((*nl) != NULL) {
82319 if ((*nl) == n) {
82320+ pax_open_kernel();
82321 rcu_assign_pointer(*nl, n->next);
82322+ pax_close_kernel();
82323 return 0;
82324 }
82325- nl = &((*nl)->next);
82326+ nl = (struct notifier_block **)&((*nl)->next);
82327 }
82328 return -ENOENT;
82329 }
82330diff --git a/kernel/panic.c b/kernel/panic.c
82331index 8018646..b6a5b4f 100644
82332--- a/kernel/panic.c
82333+++ b/kernel/panic.c
82334@@ -403,7 +403,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
82335 disable_trace_on_warning();
82336
82337 pr_warn("------------[ cut here ]------------\n");
82338- pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
82339+ pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
82340 raw_smp_processor_id(), current->pid, file, line, caller);
82341
82342 if (args)
82343@@ -457,7 +457,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
82344 */
82345 void __stack_chk_fail(void)
82346 {
82347- panic("stack-protector: Kernel stack is corrupted in: %p\n",
82348+ dump_stack();
82349+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
82350 __builtin_return_address(0));
82351 }
82352 EXPORT_SYMBOL(__stack_chk_fail);
82353diff --git a/kernel/pid.c b/kernel/pid.c
82354index 66505c1..87af12c 100644
82355--- a/kernel/pid.c
82356+++ b/kernel/pid.c
82357@@ -33,6 +33,7 @@
82358 #include <linux/rculist.h>
82359 #include <linux/bootmem.h>
82360 #include <linux/hash.h>
82361+#include <linux/security.h>
82362 #include <linux/pid_namespace.h>
82363 #include <linux/init_task.h>
82364 #include <linux/syscalls.h>
82365@@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
82366
82367 int pid_max = PID_MAX_DEFAULT;
82368
82369-#define RESERVED_PIDS 300
82370+#define RESERVED_PIDS 500
82371
82372 int pid_max_min = RESERVED_PIDS + 1;
82373 int pid_max_max = PID_MAX_LIMIT;
82374@@ -439,10 +440,18 @@ EXPORT_SYMBOL(pid_task);
82375 */
82376 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
82377 {
82378+ struct task_struct *task;
82379+
82380 rcu_lockdep_assert(rcu_read_lock_held(),
82381 "find_task_by_pid_ns() needs rcu_read_lock()"
82382 " protection");
82383- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
82384+
82385+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
82386+
82387+ if (gr_pid_is_chrooted(task))
82388+ return NULL;
82389+
82390+ return task;
82391 }
82392
82393 struct task_struct *find_task_by_vpid(pid_t vnr)
82394@@ -450,6 +459,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
82395 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
82396 }
82397
82398+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
82399+{
82400+ rcu_lockdep_assert(rcu_read_lock_held(),
82401+ "find_task_by_pid_ns() needs rcu_read_lock()"
82402+ " protection");
82403+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
82404+}
82405+
82406 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
82407 {
82408 struct pid *pid;
82409diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
82410index 601bb36..f7e6f34 100644
82411--- a/kernel/pid_namespace.c
82412+++ b/kernel/pid_namespace.c
82413@@ -247,7 +247,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
82414 void __user *buffer, size_t *lenp, loff_t *ppos)
82415 {
82416 struct pid_namespace *pid_ns = task_active_pid_ns(current);
82417- struct ctl_table tmp = *table;
82418+ ctl_table_no_const tmp = *table;
82419
82420 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
82421 return -EPERM;
82422diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
82423index c7f31aa..2b44977 100644
82424--- a/kernel/posix-cpu-timers.c
82425+++ b/kernel/posix-cpu-timers.c
82426@@ -1521,14 +1521,14 @@ struct k_clock clock_posix_cpu = {
82427
82428 static __init int init_posix_cpu_timers(void)
82429 {
82430- struct k_clock process = {
82431+ static struct k_clock process = {
82432 .clock_getres = process_cpu_clock_getres,
82433 .clock_get = process_cpu_clock_get,
82434 .timer_create = process_cpu_timer_create,
82435 .nsleep = process_cpu_nsleep,
82436 .nsleep_restart = process_cpu_nsleep_restart,
82437 };
82438- struct k_clock thread = {
82439+ static struct k_clock thread = {
82440 .clock_getres = thread_cpu_clock_getres,
82441 .clock_get = thread_cpu_clock_get,
82442 .timer_create = thread_cpu_timer_create,
82443diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
82444index 424c2d4..679242f 100644
82445--- a/kernel/posix-timers.c
82446+++ b/kernel/posix-timers.c
82447@@ -43,6 +43,7 @@
82448 #include <linux/hash.h>
82449 #include <linux/posix-clock.h>
82450 #include <linux/posix-timers.h>
82451+#include <linux/grsecurity.h>
82452 #include <linux/syscalls.h>
82453 #include <linux/wait.h>
82454 #include <linux/workqueue.h>
82455@@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
82456 * which we beg off on and pass to do_sys_settimeofday().
82457 */
82458
82459-static struct k_clock posix_clocks[MAX_CLOCKS];
82460+static struct k_clock *posix_clocks[MAX_CLOCKS];
82461
82462 /*
82463 * These ones are defined below.
82464@@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
82465 */
82466 static __init int init_posix_timers(void)
82467 {
82468- struct k_clock clock_realtime = {
82469+ static struct k_clock clock_realtime = {
82470 .clock_getres = hrtimer_get_res,
82471 .clock_get = posix_clock_realtime_get,
82472 .clock_set = posix_clock_realtime_set,
82473@@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
82474 .timer_get = common_timer_get,
82475 .timer_del = common_timer_del,
82476 };
82477- struct k_clock clock_monotonic = {
82478+ static struct k_clock clock_monotonic = {
82479 .clock_getres = hrtimer_get_res,
82480 .clock_get = posix_ktime_get_ts,
82481 .nsleep = common_nsleep,
82482@@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
82483 .timer_get = common_timer_get,
82484 .timer_del = common_timer_del,
82485 };
82486- struct k_clock clock_monotonic_raw = {
82487+ static struct k_clock clock_monotonic_raw = {
82488 .clock_getres = hrtimer_get_res,
82489 .clock_get = posix_get_monotonic_raw,
82490 };
82491- struct k_clock clock_realtime_coarse = {
82492+ static struct k_clock clock_realtime_coarse = {
82493 .clock_getres = posix_get_coarse_res,
82494 .clock_get = posix_get_realtime_coarse,
82495 };
82496- struct k_clock clock_monotonic_coarse = {
82497+ static struct k_clock clock_monotonic_coarse = {
82498 .clock_getres = posix_get_coarse_res,
82499 .clock_get = posix_get_monotonic_coarse,
82500 };
82501- struct k_clock clock_tai = {
82502+ static struct k_clock clock_tai = {
82503 .clock_getres = hrtimer_get_res,
82504 .clock_get = posix_get_tai,
82505 .nsleep = common_nsleep,
82506@@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
82507 .timer_get = common_timer_get,
82508 .timer_del = common_timer_del,
82509 };
82510- struct k_clock clock_boottime = {
82511+ static struct k_clock clock_boottime = {
82512 .clock_getres = hrtimer_get_res,
82513 .clock_get = posix_get_boottime,
82514 .nsleep = common_nsleep,
82515@@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
82516 return;
82517 }
82518
82519- posix_clocks[clock_id] = *new_clock;
82520+ posix_clocks[clock_id] = new_clock;
82521 }
82522 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
82523
82524@@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
82525 return (id & CLOCKFD_MASK) == CLOCKFD ?
82526 &clock_posix_dynamic : &clock_posix_cpu;
82527
82528- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
82529+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
82530 return NULL;
82531- return &posix_clocks[id];
82532+ return posix_clocks[id];
82533 }
82534
82535 static int common_timer_create(struct k_itimer *new_timer)
82536@@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
82537 struct k_clock *kc = clockid_to_kclock(which_clock);
82538 struct k_itimer *new_timer;
82539 int error, new_timer_id;
82540- sigevent_t event;
82541+ sigevent_t event = { };
82542 int it_id_set = IT_ID_NOT_SET;
82543
82544 if (!kc)
82545@@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
82546 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
82547 return -EFAULT;
82548
82549+ /* only the CLOCK_REALTIME clock can be set, all other clocks
82550+ have their clock_set fptr set to a nosettime dummy function
82551+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
82552+ call common_clock_set, which calls do_sys_settimeofday, which
82553+ we hook
82554+ */
82555+
82556 return kc->clock_set(which_clock, &new_tp);
82557 }
82558
82559diff --git a/kernel/power/process.c b/kernel/power/process.c
82560index 06ec886..9dba35e 100644
82561--- a/kernel/power/process.c
82562+++ b/kernel/power/process.c
82563@@ -34,6 +34,7 @@ static int try_to_freeze_tasks(bool user_only)
82564 unsigned int elapsed_msecs;
82565 bool wakeup = false;
82566 int sleep_usecs = USEC_PER_MSEC;
82567+ bool timedout = false;
82568
82569 do_gettimeofday(&start);
82570
82571@@ -44,13 +45,20 @@ static int try_to_freeze_tasks(bool user_only)
82572
82573 while (true) {
82574 todo = 0;
82575+ if (time_after(jiffies, end_time))
82576+ timedout = true;
82577 read_lock(&tasklist_lock);
82578 do_each_thread(g, p) {
82579 if (p == current || !freeze_task(p))
82580 continue;
82581
82582- if (!freezer_should_skip(p))
82583+ if (!freezer_should_skip(p)) {
82584 todo++;
82585+ if (timedout) {
82586+ printk(KERN_ERR "Task refusing to freeze:\n");
82587+ sched_show_task(p);
82588+ }
82589+ }
82590 } while_each_thread(g, p);
82591 read_unlock(&tasklist_lock);
82592
82593@@ -59,7 +67,7 @@ static int try_to_freeze_tasks(bool user_only)
82594 todo += wq_busy;
82595 }
82596
82597- if (!todo || time_after(jiffies, end_time))
82598+ if (!todo || timedout)
82599 break;
82600
82601 if (pm_wakeup_pending()) {
82602diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
82603index 5b5a708..ec7637e 100644
82604--- a/kernel/printk/printk.c
82605+++ b/kernel/printk/printk.c
82606@@ -385,6 +385,11 @@ static int check_syslog_permissions(int type, bool from_file)
82607 if (from_file && type != SYSLOG_ACTION_OPEN)
82608 return 0;
82609
82610+#ifdef CONFIG_GRKERNSEC_DMESG
82611+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
82612+ return -EPERM;
82613+#endif
82614+
82615 if (syslog_action_restricted(type)) {
82616 if (capable(CAP_SYSLOG))
82617 return 0;
82618diff --git a/kernel/profile.c b/kernel/profile.c
82619index 6631e1e..310c266 100644
82620--- a/kernel/profile.c
82621+++ b/kernel/profile.c
82622@@ -37,7 +37,7 @@ struct profile_hit {
82623 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
82624 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
82625
82626-static atomic_t *prof_buffer;
82627+static atomic_unchecked_t *prof_buffer;
82628 static unsigned long prof_len, prof_shift;
82629
82630 int prof_on __read_mostly;
82631@@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
82632 hits[i].pc = 0;
82633 continue;
82634 }
82635- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
82636+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
82637 hits[i].hits = hits[i].pc = 0;
82638 }
82639 }
82640@@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
82641 * Add the current hit(s) and flush the write-queue out
82642 * to the global buffer:
82643 */
82644- atomic_add(nr_hits, &prof_buffer[pc]);
82645+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
82646 for (i = 0; i < NR_PROFILE_HIT; ++i) {
82647- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
82648+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
82649 hits[i].pc = hits[i].hits = 0;
82650 }
82651 out:
82652@@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
82653 {
82654 unsigned long pc;
82655 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
82656- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
82657+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
82658 }
82659 #endif /* !CONFIG_SMP */
82660
82661@@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
82662 return -EFAULT;
82663 buf++; p++; count--; read++;
82664 }
82665- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
82666+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
82667 if (copy_to_user(buf, (void *)pnt, count))
82668 return -EFAULT;
82669 read += count;
82670@@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
82671 }
82672 #endif
82673 profile_discard_flip_buffers();
82674- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
82675+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
82676 return count;
82677 }
82678
82679diff --git a/kernel/ptrace.c b/kernel/ptrace.c
82680index a146ee3..ffed4c3 100644
82681--- a/kernel/ptrace.c
82682+++ b/kernel/ptrace.c
82683@@ -326,7 +326,7 @@ static int ptrace_attach(struct task_struct *task, long request,
82684 if (seize)
82685 flags |= PT_SEIZED;
82686 rcu_read_lock();
82687- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
82688+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
82689 flags |= PT_PTRACE_CAP;
82690 rcu_read_unlock();
82691 task->ptrace = flags;
82692@@ -537,7 +537,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
82693 break;
82694 return -EIO;
82695 }
82696- if (copy_to_user(dst, buf, retval))
82697+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
82698 return -EFAULT;
82699 copied += retval;
82700 src += retval;
82701@@ -805,7 +805,7 @@ int ptrace_request(struct task_struct *child, long request,
82702 bool seized = child->ptrace & PT_SEIZED;
82703 int ret = -EIO;
82704 siginfo_t siginfo, *si;
82705- void __user *datavp = (void __user *) data;
82706+ void __user *datavp = (__force void __user *) data;
82707 unsigned long __user *datalp = datavp;
82708 unsigned long flags;
82709
82710@@ -1051,14 +1051,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
82711 goto out;
82712 }
82713
82714+ if (gr_handle_ptrace(child, request)) {
82715+ ret = -EPERM;
82716+ goto out_put_task_struct;
82717+ }
82718+
82719 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
82720 ret = ptrace_attach(child, request, addr, data);
82721 /*
82722 * Some architectures need to do book-keeping after
82723 * a ptrace attach.
82724 */
82725- if (!ret)
82726+ if (!ret) {
82727 arch_ptrace_attach(child);
82728+ gr_audit_ptrace(child);
82729+ }
82730 goto out_put_task_struct;
82731 }
82732
82733@@ -1086,7 +1093,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
82734 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
82735 if (copied != sizeof(tmp))
82736 return -EIO;
82737- return put_user(tmp, (unsigned long __user *)data);
82738+ return put_user(tmp, (__force unsigned long __user *)data);
82739 }
82740
82741 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
82742@@ -1180,7 +1187,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
82743 }
82744
82745 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
82746- compat_long_t addr, compat_long_t data)
82747+ compat_ulong_t addr, compat_ulong_t data)
82748 {
82749 struct task_struct *child;
82750 long ret;
82751@@ -1196,14 +1203,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
82752 goto out;
82753 }
82754
82755+ if (gr_handle_ptrace(child, request)) {
82756+ ret = -EPERM;
82757+ goto out_put_task_struct;
82758+ }
82759+
82760 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
82761 ret = ptrace_attach(child, request, addr, data);
82762 /*
82763 * Some architectures need to do book-keeping after
82764 * a ptrace attach.
82765 */
82766- if (!ret)
82767+ if (!ret) {
82768 arch_ptrace_attach(child);
82769+ gr_audit_ptrace(child);
82770+ }
82771 goto out_put_task_struct;
82772 }
82773
82774diff --git a/kernel/rcupdate.c b/kernel/rcupdate.c
82775index cce6ba8..7c758b1f 100644
82776--- a/kernel/rcupdate.c
82777+++ b/kernel/rcupdate.c
82778@@ -412,10 +412,10 @@ int rcu_jiffies_till_stall_check(void)
82779 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
82780 */
82781 if (till_stall_check < 3) {
82782- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
82783+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
82784 till_stall_check = 3;
82785 } else if (till_stall_check > 300) {
82786- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
82787+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
82788 till_stall_check = 300;
82789 }
82790 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
82791diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
82792index aa34411..78e5ccb 100644
82793--- a/kernel/rcutiny.c
82794+++ b/kernel/rcutiny.c
82795@@ -45,7 +45,7 @@
82796 /* Forward declarations for rcutiny_plugin.h. */
82797 struct rcu_ctrlblk;
82798 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
82799-static void rcu_process_callbacks(struct softirq_action *unused);
82800+static void rcu_process_callbacks(void);
82801 static void __call_rcu(struct rcu_head *head,
82802 void (*func)(struct rcu_head *rcu),
82803 struct rcu_ctrlblk *rcp);
82804@@ -309,7 +309,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
82805 false));
82806 }
82807
82808-static void rcu_process_callbacks(struct softirq_action *unused)
82809+static void rcu_process_callbacks(void)
82810 {
82811 __rcu_process_callbacks(&rcu_sched_ctrlblk);
82812 __rcu_process_callbacks(&rcu_bh_ctrlblk);
82813diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
82814index f4871e5..8ef5741 100644
82815--- a/kernel/rcutorture.c
82816+++ b/kernel/rcutorture.c
82817@@ -164,12 +164,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
82818 { 0 };
82819 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
82820 { 0 };
82821-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
82822-static atomic_t n_rcu_torture_alloc;
82823-static atomic_t n_rcu_torture_alloc_fail;
82824-static atomic_t n_rcu_torture_free;
82825-static atomic_t n_rcu_torture_mberror;
82826-static atomic_t n_rcu_torture_error;
82827+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
82828+static atomic_unchecked_t n_rcu_torture_alloc;
82829+static atomic_unchecked_t n_rcu_torture_alloc_fail;
82830+static atomic_unchecked_t n_rcu_torture_free;
82831+static atomic_unchecked_t n_rcu_torture_mberror;
82832+static atomic_unchecked_t n_rcu_torture_error;
82833 static long n_rcu_torture_barrier_error;
82834 static long n_rcu_torture_boost_ktrerror;
82835 static long n_rcu_torture_boost_rterror;
82836@@ -287,11 +287,11 @@ rcu_torture_alloc(void)
82837
82838 spin_lock_bh(&rcu_torture_lock);
82839 if (list_empty(&rcu_torture_freelist)) {
82840- atomic_inc(&n_rcu_torture_alloc_fail);
82841+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
82842 spin_unlock_bh(&rcu_torture_lock);
82843 return NULL;
82844 }
82845- atomic_inc(&n_rcu_torture_alloc);
82846+ atomic_inc_unchecked(&n_rcu_torture_alloc);
82847 p = rcu_torture_freelist.next;
82848 list_del_init(p);
82849 spin_unlock_bh(&rcu_torture_lock);
82850@@ -304,7 +304,7 @@ rcu_torture_alloc(void)
82851 static void
82852 rcu_torture_free(struct rcu_torture *p)
82853 {
82854- atomic_inc(&n_rcu_torture_free);
82855+ atomic_inc_unchecked(&n_rcu_torture_free);
82856 spin_lock_bh(&rcu_torture_lock);
82857 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
82858 spin_unlock_bh(&rcu_torture_lock);
82859@@ -424,7 +424,7 @@ rcu_torture_cb(struct rcu_head *p)
82860 i = rp->rtort_pipe_count;
82861 if (i > RCU_TORTURE_PIPE_LEN)
82862 i = RCU_TORTURE_PIPE_LEN;
82863- atomic_inc(&rcu_torture_wcount[i]);
82864+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
82865 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
82866 rp->rtort_mbtest = 0;
82867 rcu_torture_free(rp);
82868@@ -472,7 +472,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
82869 i = rp->rtort_pipe_count;
82870 if (i > RCU_TORTURE_PIPE_LEN)
82871 i = RCU_TORTURE_PIPE_LEN;
82872- atomic_inc(&rcu_torture_wcount[i]);
82873+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
82874 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
82875 rp->rtort_mbtest = 0;
82876 list_del(&rp->rtort_free);
82877@@ -952,7 +952,7 @@ rcu_torture_writer(void *arg)
82878 i = old_rp->rtort_pipe_count;
82879 if (i > RCU_TORTURE_PIPE_LEN)
82880 i = RCU_TORTURE_PIPE_LEN;
82881- atomic_inc(&rcu_torture_wcount[i]);
82882+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
82883 old_rp->rtort_pipe_count++;
82884 cur_ops->deferred_free(old_rp);
82885 }
82886@@ -1038,7 +1038,7 @@ static void rcu_torture_timer(unsigned long unused)
82887 return;
82888 }
82889 if (p->rtort_mbtest == 0)
82890- atomic_inc(&n_rcu_torture_mberror);
82891+ atomic_inc_unchecked(&n_rcu_torture_mberror);
82892 spin_lock(&rand_lock);
82893 cur_ops->read_delay(&rand);
82894 n_rcu_torture_timers++;
82895@@ -1108,7 +1108,7 @@ rcu_torture_reader(void *arg)
82896 continue;
82897 }
82898 if (p->rtort_mbtest == 0)
82899- atomic_inc(&n_rcu_torture_mberror);
82900+ atomic_inc_unchecked(&n_rcu_torture_mberror);
82901 cur_ops->read_delay(&rand);
82902 preempt_disable();
82903 pipe_count = p->rtort_pipe_count;
82904@@ -1171,11 +1171,11 @@ rcu_torture_printk(char *page)
82905 rcu_torture_current,
82906 rcu_torture_current_version,
82907 list_empty(&rcu_torture_freelist),
82908- atomic_read(&n_rcu_torture_alloc),
82909- atomic_read(&n_rcu_torture_alloc_fail),
82910- atomic_read(&n_rcu_torture_free));
82911+ atomic_read_unchecked(&n_rcu_torture_alloc),
82912+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
82913+ atomic_read_unchecked(&n_rcu_torture_free));
82914 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
82915- atomic_read(&n_rcu_torture_mberror),
82916+ atomic_read_unchecked(&n_rcu_torture_mberror),
82917 n_rcu_torture_boost_ktrerror,
82918 n_rcu_torture_boost_rterror);
82919 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
82920@@ -1194,14 +1194,14 @@ rcu_torture_printk(char *page)
82921 n_barrier_attempts,
82922 n_rcu_torture_barrier_error);
82923 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
82924- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
82925+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
82926 n_rcu_torture_barrier_error != 0 ||
82927 n_rcu_torture_boost_ktrerror != 0 ||
82928 n_rcu_torture_boost_rterror != 0 ||
82929 n_rcu_torture_boost_failure != 0 ||
82930 i > 1) {
82931 cnt += sprintf(&page[cnt], "!!! ");
82932- atomic_inc(&n_rcu_torture_error);
82933+ atomic_inc_unchecked(&n_rcu_torture_error);
82934 WARN_ON_ONCE(1);
82935 }
82936 cnt += sprintf(&page[cnt], "Reader Pipe: ");
82937@@ -1215,7 +1215,7 @@ rcu_torture_printk(char *page)
82938 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
82939 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
82940 cnt += sprintf(&page[cnt], " %d",
82941- atomic_read(&rcu_torture_wcount[i]));
82942+ atomic_read_unchecked(&rcu_torture_wcount[i]));
82943 }
82944 cnt += sprintf(&page[cnt], "\n");
82945 if (cur_ops->stats)
82946@@ -1924,7 +1924,7 @@ rcu_torture_cleanup(void)
82947
82948 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
82949
82950- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
82951+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
82952 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
82953 else if (n_online_successes != n_online_attempts ||
82954 n_offline_successes != n_offline_attempts)
82955@@ -1992,18 +1992,18 @@ rcu_torture_init(void)
82956
82957 rcu_torture_current = NULL;
82958 rcu_torture_current_version = 0;
82959- atomic_set(&n_rcu_torture_alloc, 0);
82960- atomic_set(&n_rcu_torture_alloc_fail, 0);
82961- atomic_set(&n_rcu_torture_free, 0);
82962- atomic_set(&n_rcu_torture_mberror, 0);
82963- atomic_set(&n_rcu_torture_error, 0);
82964+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
82965+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
82966+ atomic_set_unchecked(&n_rcu_torture_free, 0);
82967+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
82968+ atomic_set_unchecked(&n_rcu_torture_error, 0);
82969 n_rcu_torture_barrier_error = 0;
82970 n_rcu_torture_boost_ktrerror = 0;
82971 n_rcu_torture_boost_rterror = 0;
82972 n_rcu_torture_boost_failure = 0;
82973 n_rcu_torture_boosts = 0;
82974 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
82975- atomic_set(&rcu_torture_wcount[i], 0);
82976+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
82977 for_each_possible_cpu(cpu) {
82978 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
82979 per_cpu(rcu_torture_count, cpu)[i] = 0;
82980diff --git a/kernel/rcutree.c b/kernel/rcutree.c
82981index 068de3a..df7da65 100644
82982--- a/kernel/rcutree.c
82983+++ b/kernel/rcutree.c
82984@@ -358,9 +358,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
82985 rcu_prepare_for_idle(smp_processor_id());
82986 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
82987 smp_mb__before_atomic_inc(); /* See above. */
82988- atomic_inc(&rdtp->dynticks);
82989+ atomic_inc_unchecked(&rdtp->dynticks);
82990 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
82991- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
82992+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
82993
82994 /*
82995 * It is illegal to enter an extended quiescent state while
82996@@ -496,10 +496,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
82997 int user)
82998 {
82999 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
83000- atomic_inc(&rdtp->dynticks);
83001+ atomic_inc_unchecked(&rdtp->dynticks);
83002 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
83003 smp_mb__after_atomic_inc(); /* See above. */
83004- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
83005+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
83006 rcu_cleanup_after_idle(smp_processor_id());
83007 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
83008 if (!user && !is_idle_task(current)) {
83009@@ -638,14 +638,14 @@ void rcu_nmi_enter(void)
83010 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
83011
83012 if (rdtp->dynticks_nmi_nesting == 0 &&
83013- (atomic_read(&rdtp->dynticks) & 0x1))
83014+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
83015 return;
83016 rdtp->dynticks_nmi_nesting++;
83017 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
83018- atomic_inc(&rdtp->dynticks);
83019+ atomic_inc_unchecked(&rdtp->dynticks);
83020 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
83021 smp_mb__after_atomic_inc(); /* See above. */
83022- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
83023+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
83024 }
83025
83026 /**
83027@@ -664,9 +664,9 @@ void rcu_nmi_exit(void)
83028 return;
83029 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
83030 smp_mb__before_atomic_inc(); /* See above. */
83031- atomic_inc(&rdtp->dynticks);
83032+ atomic_inc_unchecked(&rdtp->dynticks);
83033 smp_mb__after_atomic_inc(); /* Force delay to next write. */
83034- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
83035+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
83036 }
83037
83038 /**
83039@@ -680,7 +680,7 @@ int rcu_is_cpu_idle(void)
83040 int ret;
83041
83042 preempt_disable();
83043- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
83044+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
83045 preempt_enable();
83046 return ret;
83047 }
83048@@ -748,7 +748,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
83049 */
83050 static int dyntick_save_progress_counter(struct rcu_data *rdp)
83051 {
83052- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
83053+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
83054 return (rdp->dynticks_snap & 0x1) == 0;
83055 }
83056
83057@@ -763,7 +763,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
83058 unsigned int curr;
83059 unsigned int snap;
83060
83061- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
83062+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
83063 snap = (unsigned int)rdp->dynticks_snap;
83064
83065 /*
83066@@ -1351,9 +1351,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
83067 rdp = this_cpu_ptr(rsp->rda);
83068 rcu_preempt_check_blocked_tasks(rnp);
83069 rnp->qsmask = rnp->qsmaskinit;
83070- ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
83071+ ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
83072 WARN_ON_ONCE(rnp->completed != rsp->completed);
83073- ACCESS_ONCE(rnp->completed) = rsp->completed;
83074+ ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
83075 if (rnp == rdp->mynode)
83076 __note_gp_changes(rsp, rnp, rdp);
83077 rcu_preempt_boost_start_gp(rnp);
83078@@ -1435,7 +1435,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
83079 */
83080 rcu_for_each_node_breadth_first(rsp, rnp) {
83081 raw_spin_lock_irq(&rnp->lock);
83082- ACCESS_ONCE(rnp->completed) = rsp->gpnum;
83083+ ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
83084 rdp = this_cpu_ptr(rsp->rda);
83085 if (rnp == rdp->mynode)
83086 __note_gp_changes(rsp, rnp, rdp);
83087@@ -1765,7 +1765,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
83088 rsp->qlen += rdp->qlen;
83089 rdp->n_cbs_orphaned += rdp->qlen;
83090 rdp->qlen_lazy = 0;
83091- ACCESS_ONCE(rdp->qlen) = 0;
83092+ ACCESS_ONCE_RW(rdp->qlen) = 0;
83093 }
83094
83095 /*
83096@@ -2011,7 +2011,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
83097 }
83098 smp_mb(); /* List handling before counting for rcu_barrier(). */
83099 rdp->qlen_lazy -= count_lazy;
83100- ACCESS_ONCE(rdp->qlen) -= count;
83101+ ACCESS_ONCE_RW(rdp->qlen) -= count;
83102 rdp->n_cbs_invoked += count;
83103
83104 /* Reinstate batch limit if we have worked down the excess. */
83105@@ -2202,7 +2202,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
83106 /*
83107 * Do RCU core processing for the current CPU.
83108 */
83109-static void rcu_process_callbacks(struct softirq_action *unused)
83110+static void rcu_process_callbacks(void)
83111 {
83112 struct rcu_state *rsp;
83113
83114@@ -2325,7 +2325,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
83115 local_irq_restore(flags);
83116 return;
83117 }
83118- ACCESS_ONCE(rdp->qlen)++;
83119+ ACCESS_ONCE_RW(rdp->qlen)++;
83120 if (lazy)
83121 rdp->qlen_lazy++;
83122 else
83123@@ -2534,11 +2534,11 @@ void synchronize_sched_expedited(void)
83124 * counter wrap on a 32-bit system. Quite a few more CPUs would of
83125 * course be required on a 64-bit system.
83126 */
83127- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
83128+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
83129 (ulong)atomic_long_read(&rsp->expedited_done) +
83130 ULONG_MAX / 8)) {
83131 synchronize_sched();
83132- atomic_long_inc(&rsp->expedited_wrap);
83133+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
83134 return;
83135 }
83136
83137@@ -2546,7 +2546,7 @@ void synchronize_sched_expedited(void)
83138 * Take a ticket. Note that atomic_inc_return() implies a
83139 * full memory barrier.
83140 */
83141- snap = atomic_long_inc_return(&rsp->expedited_start);
83142+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
83143 firstsnap = snap;
83144 get_online_cpus();
83145 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
83146@@ -2559,14 +2559,14 @@ void synchronize_sched_expedited(void)
83147 synchronize_sched_expedited_cpu_stop,
83148 NULL) == -EAGAIN) {
83149 put_online_cpus();
83150- atomic_long_inc(&rsp->expedited_tryfail);
83151+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
83152
83153 /* Check to see if someone else did our work for us. */
83154 s = atomic_long_read(&rsp->expedited_done);
83155 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
83156 /* ensure test happens before caller kfree */
83157 smp_mb__before_atomic_inc(); /* ^^^ */
83158- atomic_long_inc(&rsp->expedited_workdone1);
83159+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
83160 return;
83161 }
83162
83163@@ -2575,7 +2575,7 @@ void synchronize_sched_expedited(void)
83164 udelay(trycount * num_online_cpus());
83165 } else {
83166 wait_rcu_gp(call_rcu_sched);
83167- atomic_long_inc(&rsp->expedited_normal);
83168+ atomic_long_inc_unchecked(&rsp->expedited_normal);
83169 return;
83170 }
83171
83172@@ -2584,7 +2584,7 @@ void synchronize_sched_expedited(void)
83173 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
83174 /* ensure test happens before caller kfree */
83175 smp_mb__before_atomic_inc(); /* ^^^ */
83176- atomic_long_inc(&rsp->expedited_workdone2);
83177+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
83178 return;
83179 }
83180
83181@@ -2596,10 +2596,10 @@ void synchronize_sched_expedited(void)
83182 * period works for us.
83183 */
83184 get_online_cpus();
83185- snap = atomic_long_read(&rsp->expedited_start);
83186+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
83187 smp_mb(); /* ensure read is before try_stop_cpus(). */
83188 }
83189- atomic_long_inc(&rsp->expedited_stoppedcpus);
83190+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
83191
83192 /*
83193 * Everyone up to our most recent fetch is covered by our grace
83194@@ -2608,16 +2608,16 @@ void synchronize_sched_expedited(void)
83195 * than we did already did their update.
83196 */
83197 do {
83198- atomic_long_inc(&rsp->expedited_done_tries);
83199+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
83200 s = atomic_long_read(&rsp->expedited_done);
83201 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
83202 /* ensure test happens before caller kfree */
83203 smp_mb__before_atomic_inc(); /* ^^^ */
83204- atomic_long_inc(&rsp->expedited_done_lost);
83205+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
83206 break;
83207 }
83208 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
83209- atomic_long_inc(&rsp->expedited_done_exit);
83210+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
83211
83212 put_online_cpus();
83213 }
83214@@ -2799,7 +2799,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
83215 * ACCESS_ONCE() to prevent the compiler from speculating
83216 * the increment to precede the early-exit check.
83217 */
83218- ACCESS_ONCE(rsp->n_barrier_done)++;
83219+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
83220 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
83221 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
83222 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
83223@@ -2849,7 +2849,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
83224
83225 /* Increment ->n_barrier_done to prevent duplicate work. */
83226 smp_mb(); /* Keep increment after above mechanism. */
83227- ACCESS_ONCE(rsp->n_barrier_done)++;
83228+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
83229 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
83230 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
83231 smp_mb(); /* Keep increment before caller's subsequent code. */
83232@@ -2894,10 +2894,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
83233 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
83234 init_callback_list(rdp);
83235 rdp->qlen_lazy = 0;
83236- ACCESS_ONCE(rdp->qlen) = 0;
83237+ ACCESS_ONCE_RW(rdp->qlen) = 0;
83238 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
83239 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
83240- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
83241+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
83242 rdp->cpu = cpu;
83243 rdp->rsp = rsp;
83244 rcu_boot_init_nocb_percpu_data(rdp);
83245@@ -2930,8 +2930,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
83246 rdp->blimit = blimit;
83247 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
83248 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
83249- atomic_set(&rdp->dynticks->dynticks,
83250- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
83251+ atomic_set_unchecked(&rdp->dynticks->dynticks,
83252+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
83253 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
83254
83255 /* Add CPU to rcu_node bitmasks. */
83256diff --git a/kernel/rcutree.h b/kernel/rcutree.h
83257index b383258..2440c1e 100644
83258--- a/kernel/rcutree.h
83259+++ b/kernel/rcutree.h
83260@@ -87,7 +87,7 @@ struct rcu_dynticks {
83261 long long dynticks_nesting; /* Track irq/process nesting level. */
83262 /* Process level is worth LLONG_MAX/2. */
83263 int dynticks_nmi_nesting; /* Track NMI nesting level. */
83264- atomic_t dynticks; /* Even value for idle, else odd. */
83265+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
83266 #ifdef CONFIG_RCU_FAST_NO_HZ
83267 bool all_lazy; /* Are all CPU's CBs lazy? */
83268 unsigned long nonlazy_posted;
83269@@ -419,17 +419,17 @@ struct rcu_state {
83270 /* _rcu_barrier(). */
83271 /* End of fields guarded by barrier_mutex. */
83272
83273- atomic_long_t expedited_start; /* Starting ticket. */
83274- atomic_long_t expedited_done; /* Done ticket. */
83275- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
83276- atomic_long_t expedited_tryfail; /* # acquisition failures. */
83277- atomic_long_t expedited_workdone1; /* # done by others #1. */
83278- atomic_long_t expedited_workdone2; /* # done by others #2. */
83279- atomic_long_t expedited_normal; /* # fallbacks to normal. */
83280- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
83281- atomic_long_t expedited_done_tries; /* # tries to update _done. */
83282- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
83283- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
83284+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
83285+ atomic_long_t expedited_done; /* Done ticket. */
83286+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
83287+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
83288+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
83289+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
83290+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
83291+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
83292+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
83293+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
83294+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
83295
83296 unsigned long jiffies_force_qs; /* Time at which to invoke */
83297 /* force_quiescent_state(). */
83298diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
83299index 769e12e..7b2139b 100644
83300--- a/kernel/rcutree_plugin.h
83301+++ b/kernel/rcutree_plugin.h
83302@@ -902,7 +902,7 @@ void synchronize_rcu_expedited(void)
83303
83304 /* Clean up and exit. */
83305 smp_mb(); /* ensure expedited GP seen before counter increment. */
83306- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
83307+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
83308 unlock_mb_ret:
83309 mutex_unlock(&sync_rcu_preempt_exp_mutex);
83310 mb_ret:
83311@@ -1476,7 +1476,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
83312 free_cpumask_var(cm);
83313 }
83314
83315-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
83316+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
83317 .store = &rcu_cpu_kthread_task,
83318 .thread_should_run = rcu_cpu_kthread_should_run,
83319 .thread_fn = rcu_cpu_kthread,
83320@@ -1941,7 +1941,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
83321 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
83322 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
83323 cpu, ticks_value, ticks_title,
83324- atomic_read(&rdtp->dynticks) & 0xfff,
83325+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
83326 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
83327 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
83328 fast_no_hz);
83329@@ -2104,7 +2104,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
83330
83331 /* Enqueue the callback on the nocb list and update counts. */
83332 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
83333- ACCESS_ONCE(*old_rhpp) = rhp;
83334+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
83335 atomic_long_add(rhcount, &rdp->nocb_q_count);
83336 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
83337
83338@@ -2244,12 +2244,12 @@ static int rcu_nocb_kthread(void *arg)
83339 * Extract queued callbacks, update counts, and wait
83340 * for a grace period to elapse.
83341 */
83342- ACCESS_ONCE(rdp->nocb_head) = NULL;
83343+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
83344 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
83345 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
83346 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
83347- ACCESS_ONCE(rdp->nocb_p_count) += c;
83348- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
83349+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
83350+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
83351 rcu_nocb_wait_gp(rdp);
83352
83353 /* Each pass through the following loop invokes a callback. */
83354@@ -2271,8 +2271,8 @@ static int rcu_nocb_kthread(void *arg)
83355 list = next;
83356 }
83357 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
83358- ACCESS_ONCE(rdp->nocb_p_count) -= c;
83359- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
83360+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
83361+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
83362 rdp->n_nocbs_invoked += c;
83363 }
83364 return 0;
83365@@ -2299,7 +2299,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
83366 t = kthread_run(rcu_nocb_kthread, rdp,
83367 "rcuo%c/%d", rsp->abbr, cpu);
83368 BUG_ON(IS_ERR(t));
83369- ACCESS_ONCE(rdp->nocb_kthread) = t;
83370+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
83371 }
83372 }
83373
83374diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
83375index cf6c174..a8f4b50 100644
83376--- a/kernel/rcutree_trace.c
83377+++ b/kernel/rcutree_trace.c
83378@@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
83379 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
83380 rdp->passed_quiesce, rdp->qs_pending);
83381 seq_printf(m, " dt=%d/%llx/%d df=%lu",
83382- atomic_read(&rdp->dynticks->dynticks),
83383+ atomic_read_unchecked(&rdp->dynticks->dynticks),
83384 rdp->dynticks->dynticks_nesting,
83385 rdp->dynticks->dynticks_nmi_nesting,
83386 rdp->dynticks_fqs);
83387@@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
83388 struct rcu_state *rsp = (struct rcu_state *)m->private;
83389
83390 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",
83391- atomic_long_read(&rsp->expedited_start),
83392+ atomic_long_read_unchecked(&rsp->expedited_start),
83393 atomic_long_read(&rsp->expedited_done),
83394- atomic_long_read(&rsp->expedited_wrap),
83395- atomic_long_read(&rsp->expedited_tryfail),
83396- atomic_long_read(&rsp->expedited_workdone1),
83397- atomic_long_read(&rsp->expedited_workdone2),
83398- atomic_long_read(&rsp->expedited_normal),
83399- atomic_long_read(&rsp->expedited_stoppedcpus),
83400- atomic_long_read(&rsp->expedited_done_tries),
83401- atomic_long_read(&rsp->expedited_done_lost),
83402- atomic_long_read(&rsp->expedited_done_exit));
83403+ atomic_long_read_unchecked(&rsp->expedited_wrap),
83404+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
83405+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
83406+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
83407+ atomic_long_read_unchecked(&rsp->expedited_normal),
83408+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
83409+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
83410+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
83411+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
83412 return 0;
83413 }
83414
83415diff --git a/kernel/resource.c b/kernel/resource.c
83416index 3f285dc..5755f62 100644
83417--- a/kernel/resource.c
83418+++ b/kernel/resource.c
83419@@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
83420
83421 static int __init ioresources_init(void)
83422 {
83423+#ifdef CONFIG_GRKERNSEC_PROC_ADD
83424+#ifdef CONFIG_GRKERNSEC_PROC_USER
83425+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
83426+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
83427+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
83428+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
83429+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
83430+#endif
83431+#else
83432 proc_create("ioports", 0, NULL, &proc_ioports_operations);
83433 proc_create("iomem", 0, NULL, &proc_iomem_operations);
83434+#endif
83435 return 0;
83436 }
83437 __initcall(ioresources_init);
83438diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
83439index 1d96dd0..994ff19 100644
83440--- a/kernel/rtmutex-tester.c
83441+++ b/kernel/rtmutex-tester.c
83442@@ -22,7 +22,7 @@
83443 #define MAX_RT_TEST_MUTEXES 8
83444
83445 static spinlock_t rttest_lock;
83446-static atomic_t rttest_event;
83447+static atomic_unchecked_t rttest_event;
83448
83449 struct test_thread_data {
83450 int opcode;
83451@@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83452
83453 case RTTEST_LOCKCONT:
83454 td->mutexes[td->opdata] = 1;
83455- td->event = atomic_add_return(1, &rttest_event);
83456+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83457 return 0;
83458
83459 case RTTEST_RESET:
83460@@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83461 return 0;
83462
83463 case RTTEST_RESETEVENT:
83464- atomic_set(&rttest_event, 0);
83465+ atomic_set_unchecked(&rttest_event, 0);
83466 return 0;
83467
83468 default:
83469@@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83470 return ret;
83471
83472 td->mutexes[id] = 1;
83473- td->event = atomic_add_return(1, &rttest_event);
83474+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83475 rt_mutex_lock(&mutexes[id]);
83476- td->event = atomic_add_return(1, &rttest_event);
83477+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83478 td->mutexes[id] = 4;
83479 return 0;
83480
83481@@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83482 return ret;
83483
83484 td->mutexes[id] = 1;
83485- td->event = atomic_add_return(1, &rttest_event);
83486+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83487 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
83488- td->event = atomic_add_return(1, &rttest_event);
83489+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83490 td->mutexes[id] = ret ? 0 : 4;
83491 return ret ? -EINTR : 0;
83492
83493@@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
83494 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
83495 return ret;
83496
83497- td->event = atomic_add_return(1, &rttest_event);
83498+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83499 rt_mutex_unlock(&mutexes[id]);
83500- td->event = atomic_add_return(1, &rttest_event);
83501+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83502 td->mutexes[id] = 0;
83503 return 0;
83504
83505@@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
83506 break;
83507
83508 td->mutexes[dat] = 2;
83509- td->event = atomic_add_return(1, &rttest_event);
83510+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83511 break;
83512
83513 default:
83514@@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
83515 return;
83516
83517 td->mutexes[dat] = 3;
83518- td->event = atomic_add_return(1, &rttest_event);
83519+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83520 break;
83521
83522 case RTTEST_LOCKNOWAIT:
83523@@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
83524 return;
83525
83526 td->mutexes[dat] = 1;
83527- td->event = atomic_add_return(1, &rttest_event);
83528+ td->event = atomic_add_return_unchecked(1, &rttest_event);
83529 return;
83530
83531 default:
83532diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
83533index 4a07353..66b5291 100644
83534--- a/kernel/sched/auto_group.c
83535+++ b/kernel/sched/auto_group.c
83536@@ -11,7 +11,7 @@
83537
83538 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
83539 static struct autogroup autogroup_default;
83540-static atomic_t autogroup_seq_nr;
83541+static atomic_unchecked_t autogroup_seq_nr;
83542
83543 void __init autogroup_init(struct task_struct *init_task)
83544 {
83545@@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
83546
83547 kref_init(&ag->kref);
83548 init_rwsem(&ag->lock);
83549- ag->id = atomic_inc_return(&autogroup_seq_nr);
83550+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
83551 ag->tg = tg;
83552 #ifdef CONFIG_RT_GROUP_SCHED
83553 /*
83554diff --git a/kernel/sched/core.c b/kernel/sched/core.c
83555index 05c39f0..442e6fe 100644
83556--- a/kernel/sched/core.c
83557+++ b/kernel/sched/core.c
83558@@ -2885,7 +2885,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
83559 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
83560 * or number of jiffies left till timeout) if completed.
83561 */
83562-long __sched
83563+long __sched __intentional_overflow(-1)
83564 wait_for_completion_interruptible_timeout(struct completion *x,
83565 unsigned long timeout)
83566 {
83567@@ -2902,7 +2902,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
83568 *
83569 * Return: -ERESTARTSYS if interrupted, 0 if completed.
83570 */
83571-int __sched wait_for_completion_killable(struct completion *x)
83572+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
83573 {
83574 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
83575 if (t == -ERESTARTSYS)
83576@@ -2923,7 +2923,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
83577 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
83578 * or number of jiffies left till timeout) if completed.
83579 */
83580-long __sched
83581+long __sched __intentional_overflow(-1)
83582 wait_for_completion_killable_timeout(struct completion *x,
83583 unsigned long timeout)
83584 {
83585@@ -3149,6 +3149,8 @@ int can_nice(const struct task_struct *p, const int nice)
83586 /* convert nice value [19,-20] to rlimit style value [1,40] */
83587 int nice_rlim = 20 - nice;
83588
83589+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
83590+
83591 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
83592 capable(CAP_SYS_NICE));
83593 }
83594@@ -3182,7 +3184,8 @@ SYSCALL_DEFINE1(nice, int, increment)
83595 if (nice > 19)
83596 nice = 19;
83597
83598- if (increment < 0 && !can_nice(current, nice))
83599+ if (increment < 0 && (!can_nice(current, nice) ||
83600+ gr_handle_chroot_nice()))
83601 return -EPERM;
83602
83603 retval = security_task_setnice(current, nice);
83604@@ -3344,6 +3347,7 @@ recheck:
83605 unsigned long rlim_rtprio =
83606 task_rlimit(p, RLIMIT_RTPRIO);
83607
83608+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
83609 /* can't set/change the rt policy */
83610 if (policy != p->policy && !rlim_rtprio)
83611 return -EPERM;
83612@@ -4473,7 +4477,7 @@ static void migrate_tasks(unsigned int dead_cpu)
83613
83614 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
83615
83616-static struct ctl_table sd_ctl_dir[] = {
83617+static ctl_table_no_const sd_ctl_dir[] __read_only = {
83618 {
83619 .procname = "sched_domain",
83620 .mode = 0555,
83621@@ -4490,17 +4494,17 @@ static struct ctl_table sd_ctl_root[] = {
83622 {}
83623 };
83624
83625-static struct ctl_table *sd_alloc_ctl_entry(int n)
83626+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
83627 {
83628- struct ctl_table *entry =
83629+ ctl_table_no_const *entry =
83630 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
83631
83632 return entry;
83633 }
83634
83635-static void sd_free_ctl_entry(struct ctl_table **tablep)
83636+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
83637 {
83638- struct ctl_table *entry;
83639+ ctl_table_no_const *entry;
83640
83641 /*
83642 * In the intermediate directories, both the child directory and
83643@@ -4508,22 +4512,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
83644 * will always be set. In the lowest directory the names are
83645 * static strings and all have proc handlers.
83646 */
83647- for (entry = *tablep; entry->mode; entry++) {
83648- if (entry->child)
83649- sd_free_ctl_entry(&entry->child);
83650+ for (entry = tablep; entry->mode; entry++) {
83651+ if (entry->child) {
83652+ sd_free_ctl_entry(entry->child);
83653+ pax_open_kernel();
83654+ entry->child = NULL;
83655+ pax_close_kernel();
83656+ }
83657 if (entry->proc_handler == NULL)
83658 kfree(entry->procname);
83659 }
83660
83661- kfree(*tablep);
83662- *tablep = NULL;
83663+ kfree(tablep);
83664 }
83665
83666 static int min_load_idx = 0;
83667 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
83668
83669 static void
83670-set_table_entry(struct ctl_table *entry,
83671+set_table_entry(ctl_table_no_const *entry,
83672 const char *procname, void *data, int maxlen,
83673 umode_t mode, proc_handler *proc_handler,
83674 bool load_idx)
83675@@ -4543,7 +4550,7 @@ set_table_entry(struct ctl_table *entry,
83676 static struct ctl_table *
83677 sd_alloc_ctl_domain_table(struct sched_domain *sd)
83678 {
83679- struct ctl_table *table = sd_alloc_ctl_entry(13);
83680+ ctl_table_no_const *table = sd_alloc_ctl_entry(13);
83681
83682 if (table == NULL)
83683 return NULL;
83684@@ -4578,9 +4585,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
83685 return table;
83686 }
83687
83688-static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
83689+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
83690 {
83691- struct ctl_table *entry, *table;
83692+ ctl_table_no_const *entry, *table;
83693 struct sched_domain *sd;
83694 int domain_num = 0, i;
83695 char buf[32];
83696@@ -4607,11 +4614,13 @@ static struct ctl_table_header *sd_sysctl_header;
83697 static void register_sched_domain_sysctl(void)
83698 {
83699 int i, cpu_num = num_possible_cpus();
83700- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
83701+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
83702 char buf[32];
83703
83704 WARN_ON(sd_ctl_dir[0].child);
83705+ pax_open_kernel();
83706 sd_ctl_dir[0].child = entry;
83707+ pax_close_kernel();
83708
83709 if (entry == NULL)
83710 return;
83711@@ -4634,8 +4643,12 @@ static void unregister_sched_domain_sysctl(void)
83712 if (sd_sysctl_header)
83713 unregister_sysctl_table(sd_sysctl_header);
83714 sd_sysctl_header = NULL;
83715- if (sd_ctl_dir[0].child)
83716- sd_free_ctl_entry(&sd_ctl_dir[0].child);
83717+ if (sd_ctl_dir[0].child) {
83718+ sd_free_ctl_entry(sd_ctl_dir[0].child);
83719+ pax_open_kernel();
83720+ sd_ctl_dir[0].child = NULL;
83721+ pax_close_kernel();
83722+ }
83723 }
83724 #else
83725 static void register_sched_domain_sysctl(void)
83726diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
83727index 68f1609..640ba13 100644
83728--- a/kernel/sched/fair.c
83729+++ b/kernel/sched/fair.c
83730@@ -869,7 +869,7 @@ void task_numa_fault(int node, int pages, bool migrated)
83731
83732 static void reset_ptenuma_scan(struct task_struct *p)
83733 {
83734- ACCESS_ONCE(p->mm->numa_scan_seq)++;
83735+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
83736 p->mm->numa_scan_offset = 0;
83737 }
83738
83739@@ -5727,7 +5727,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
83740 * run_rebalance_domains is triggered when needed from the scheduler tick.
83741 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
83742 */
83743-static void run_rebalance_domains(struct softirq_action *h)
83744+static void run_rebalance_domains(void)
83745 {
83746 int this_cpu = smp_processor_id();
83747 struct rq *this_rq = cpu_rq(this_cpu);
83748diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
83749index ef0a7b2..1b728c1 100644
83750--- a/kernel/sched/sched.h
83751+++ b/kernel/sched/sched.h
83752@@ -1004,7 +1004,7 @@ struct sched_class {
83753 #ifdef CONFIG_FAIR_GROUP_SCHED
83754 void (*task_move_group) (struct task_struct *p, int on_rq);
83755 #endif
83756-};
83757+} __do_const;
83758
83759 #define sched_class_highest (&stop_sched_class)
83760 #define for_each_class(class) \
83761diff --git a/kernel/signal.c b/kernel/signal.c
83762index 50e4107..08bcb94 100644
83763--- a/kernel/signal.c
83764+++ b/kernel/signal.c
83765@@ -51,12 +51,12 @@ static struct kmem_cache *sigqueue_cachep;
83766
83767 int print_fatal_signals __read_mostly;
83768
83769-static void __user *sig_handler(struct task_struct *t, int sig)
83770+static __sighandler_t sig_handler(struct task_struct *t, int sig)
83771 {
83772 return t->sighand->action[sig - 1].sa.sa_handler;
83773 }
83774
83775-static int sig_handler_ignored(void __user *handler, int sig)
83776+static int sig_handler_ignored(__sighandler_t handler, int sig)
83777 {
83778 /* Is it explicitly or implicitly ignored? */
83779 return handler == SIG_IGN ||
83780@@ -65,7 +65,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
83781
83782 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
83783 {
83784- void __user *handler;
83785+ __sighandler_t handler;
83786
83787 handler = sig_handler(t, sig);
83788
83789@@ -369,6 +369,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
83790 atomic_inc(&user->sigpending);
83791 rcu_read_unlock();
83792
83793+ if (!override_rlimit)
83794+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
83795+
83796 if (override_rlimit ||
83797 atomic_read(&user->sigpending) <=
83798 task_rlimit(t, RLIMIT_SIGPENDING)) {
83799@@ -496,7 +499,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
83800
83801 int unhandled_signal(struct task_struct *tsk, int sig)
83802 {
83803- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
83804+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
83805 if (is_global_init(tsk))
83806 return 1;
83807 if (handler != SIG_IGN && handler != SIG_DFL)
83808@@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
83809 }
83810 }
83811
83812+ /* allow glibc communication via tgkill to other threads in our
83813+ thread group */
83814+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
83815+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
83816+ && gr_handle_signal(t, sig))
83817+ return -EPERM;
83818+
83819 return security_task_kill(t, info, sig, 0);
83820 }
83821
83822@@ -1199,7 +1209,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
83823 return send_signal(sig, info, p, 1);
83824 }
83825
83826-static int
83827+int
83828 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
83829 {
83830 return send_signal(sig, info, t, 0);
83831@@ -1236,6 +1246,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
83832 unsigned long int flags;
83833 int ret, blocked, ignored;
83834 struct k_sigaction *action;
83835+ int is_unhandled = 0;
83836
83837 spin_lock_irqsave(&t->sighand->siglock, flags);
83838 action = &t->sighand->action[sig-1];
83839@@ -1250,9 +1261,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
83840 }
83841 if (action->sa.sa_handler == SIG_DFL)
83842 t->signal->flags &= ~SIGNAL_UNKILLABLE;
83843+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
83844+ is_unhandled = 1;
83845 ret = specific_send_sig_info(sig, info, t);
83846 spin_unlock_irqrestore(&t->sighand->siglock, flags);
83847
83848+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
83849+ normal operation */
83850+ if (is_unhandled) {
83851+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
83852+ gr_handle_crash(t, sig);
83853+ }
83854+
83855 return ret;
83856 }
83857
83858@@ -1319,8 +1339,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
83859 ret = check_kill_permission(sig, info, p);
83860 rcu_read_unlock();
83861
83862- if (!ret && sig)
83863+ if (!ret && sig) {
83864 ret = do_send_sig_info(sig, info, p, true);
83865+ if (!ret)
83866+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
83867+ }
83868
83869 return ret;
83870 }
83871@@ -2926,7 +2949,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
83872 int error = -ESRCH;
83873
83874 rcu_read_lock();
83875- p = find_task_by_vpid(pid);
83876+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
83877+ /* allow glibc communication via tgkill to other threads in our
83878+ thread group */
83879+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
83880+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
83881+ p = find_task_by_vpid_unrestricted(pid);
83882+ else
83883+#endif
83884+ p = find_task_by_vpid(pid);
83885 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
83886 error = check_kill_permission(sig, info, p);
83887 /*
83888@@ -3219,6 +3250,16 @@ int __save_altstack(stack_t __user *uss, unsigned long sp)
83889 __put_user(t->sas_ss_size, &uss->ss_size);
83890 }
83891
83892+#ifdef CONFIG_X86
83893+void __save_altstack_ex(stack_t __user *uss, unsigned long sp)
83894+{
83895+ struct task_struct *t = current;
83896+ put_user_ex((void __user *)t->sas_ss_sp, &uss->ss_sp);
83897+ put_user_ex(sas_ss_flags(sp), &uss->ss_flags);
83898+ put_user_ex(t->sas_ss_size, &uss->ss_size);
83899+}
83900+#endif
83901+
83902 #ifdef CONFIG_COMPAT
83903 COMPAT_SYSCALL_DEFINE2(sigaltstack,
83904 const compat_stack_t __user *, uss_ptr,
83905@@ -3240,8 +3281,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
83906 }
83907 seg = get_fs();
83908 set_fs(KERNEL_DS);
83909- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
83910- (stack_t __force __user *) &uoss,
83911+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
83912+ (stack_t __force_user *) &uoss,
83913 compat_user_stack_pointer());
83914 set_fs(seg);
83915 if (ret >= 0 && uoss_ptr) {
83916@@ -3268,6 +3309,16 @@ int __compat_save_altstack(compat_stack_t __user *uss, unsigned long sp)
83917 __put_user(sas_ss_flags(sp), &uss->ss_flags) |
83918 __put_user(t->sas_ss_size, &uss->ss_size);
83919 }
83920+
83921+#ifdef CONFIG_X86
83922+void __compat_save_altstack_ex(compat_stack_t __user *uss, unsigned long sp)
83923+{
83924+ struct task_struct *t = current;
83925+ put_user_ex(ptr_to_compat((void __user *)t->sas_ss_sp), &uss->ss_sp);
83926+ put_user_ex(sas_ss_flags(sp), &uss->ss_flags);
83927+ put_user_ex(t->sas_ss_size, &uss->ss_size);
83928+}
83929+#endif
83930 #endif
83931
83932 #ifdef __ARCH_WANT_SYS_SIGPENDING
83933diff --git a/kernel/smpboot.c b/kernel/smpboot.c
83934index eb89e18..a4e6792 100644
83935--- a/kernel/smpboot.c
83936+++ b/kernel/smpboot.c
83937@@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
83938 }
83939 smpboot_unpark_thread(plug_thread, cpu);
83940 }
83941- list_add(&plug_thread->list, &hotplug_threads);
83942+ pax_list_add(&plug_thread->list, &hotplug_threads);
83943 out:
83944 mutex_unlock(&smpboot_threads_lock);
83945 return ret;
83946@@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
83947 {
83948 get_online_cpus();
83949 mutex_lock(&smpboot_threads_lock);
83950- list_del(&plug_thread->list);
83951+ pax_list_del(&plug_thread->list);
83952 smpboot_destroy_threads(plug_thread);
83953 mutex_unlock(&smpboot_threads_lock);
83954 put_online_cpus();
83955diff --git a/kernel/softirq.c b/kernel/softirq.c
83956index be3d351..9e4d5f2 100644
83957--- a/kernel/softirq.c
83958+++ b/kernel/softirq.c
83959@@ -53,11 +53,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
83960 EXPORT_SYMBOL(irq_stat);
83961 #endif
83962
83963-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
83964+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
83965
83966 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
83967
83968-char *softirq_to_name[NR_SOFTIRQS] = {
83969+const char * const softirq_to_name[NR_SOFTIRQS] = {
83970 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
83971 "TASKLET", "SCHED", "HRTIMER", "RCU"
83972 };
83973@@ -248,7 +248,7 @@ restart:
83974 kstat_incr_softirqs_this_cpu(vec_nr);
83975
83976 trace_softirq_entry(vec_nr);
83977- h->action(h);
83978+ h->action();
83979 trace_softirq_exit(vec_nr);
83980 if (unlikely(prev_count != preempt_count())) {
83981 printk(KERN_ERR "huh, entered softirq %u %s %p"
83982@@ -403,7 +403,7 @@ void __raise_softirq_irqoff(unsigned int nr)
83983 or_softirq_pending(1UL << nr);
83984 }
83985
83986-void open_softirq(int nr, void (*action)(struct softirq_action *))
83987+void __init open_softirq(int nr, void (*action)(void))
83988 {
83989 softirq_vec[nr].action = action;
83990 }
83991@@ -459,7 +459,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
83992
83993 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
83994
83995-static void tasklet_action(struct softirq_action *a)
83996+static void tasklet_action(void)
83997 {
83998 struct tasklet_struct *list;
83999
84000@@ -494,7 +494,7 @@ static void tasklet_action(struct softirq_action *a)
84001 }
84002 }
84003
84004-static void tasklet_hi_action(struct softirq_action *a)
84005+static void tasklet_hi_action(void)
84006 {
84007 struct tasklet_struct *list;
84008
84009@@ -849,7 +849,7 @@ static struct notifier_block cpu_nfb = {
84010 .notifier_call = cpu_callback
84011 };
84012
84013-static struct smp_hotplug_thread softirq_threads = {
84014+static struct smp_hotplug_thread softirq_threads __read_only = {
84015 .store = &ksoftirqd,
84016 .thread_should_run = ksoftirqd_should_run,
84017 .thread_fn = run_ksoftirqd,
84018diff --git a/kernel/srcu.c b/kernel/srcu.c
84019index 01d5ccb..cdcbee6 100644
84020--- a/kernel/srcu.c
84021+++ b/kernel/srcu.c
84022@@ -300,9 +300,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
84023
84024 idx = ACCESS_ONCE(sp->completed) & 0x1;
84025 preempt_disable();
84026- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
84027+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
84028 smp_mb(); /* B */ /* Avoid leaking the critical section. */
84029- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
84030+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
84031 preempt_enable();
84032 return idx;
84033 }
84034diff --git a/kernel/sys.c b/kernel/sys.c
84035index 771129b..dc0c7e3 100644
84036--- a/kernel/sys.c
84037+++ b/kernel/sys.c
84038@@ -149,6 +149,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
84039 error = -EACCES;
84040 goto out;
84041 }
84042+
84043+ if (gr_handle_chroot_setpriority(p, niceval)) {
84044+ error = -EACCES;
84045+ goto out;
84046+ }
84047+
84048 no_nice = security_task_setnice(p, niceval);
84049 if (no_nice) {
84050 error = no_nice;
84051@@ -352,6 +358,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
84052 goto error;
84053 }
84054
84055+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
84056+ goto error;
84057+
84058 if (rgid != (gid_t) -1 ||
84059 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
84060 new->sgid = new->egid;
84061@@ -387,6 +396,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
84062 old = current_cred();
84063
84064 retval = -EPERM;
84065+
84066+ if (gr_check_group_change(kgid, kgid, kgid))
84067+ goto error;
84068+
84069 if (nsown_capable(CAP_SETGID))
84070 new->gid = new->egid = new->sgid = new->fsgid = kgid;
84071 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
84072@@ -404,7 +417,7 @@ error:
84073 /*
84074 * change the user struct in a credentials set to match the new UID
84075 */
84076-static int set_user(struct cred *new)
84077+int set_user(struct cred *new)
84078 {
84079 struct user_struct *new_user;
84080
84081@@ -484,6 +497,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
84082 goto error;
84083 }
84084
84085+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
84086+ goto error;
84087+
84088 if (!uid_eq(new->uid, old->uid)) {
84089 retval = set_user(new);
84090 if (retval < 0)
84091@@ -534,6 +550,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
84092 old = current_cred();
84093
84094 retval = -EPERM;
84095+
84096+ if (gr_check_crash_uid(kuid))
84097+ goto error;
84098+ if (gr_check_user_change(kuid, kuid, kuid))
84099+ goto error;
84100+
84101 if (nsown_capable(CAP_SETUID)) {
84102 new->suid = new->uid = kuid;
84103 if (!uid_eq(kuid, old->uid)) {
84104@@ -603,6 +625,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
84105 goto error;
84106 }
84107
84108+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
84109+ goto error;
84110+
84111 if (ruid != (uid_t) -1) {
84112 new->uid = kruid;
84113 if (!uid_eq(kruid, old->uid)) {
84114@@ -685,6 +710,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
84115 goto error;
84116 }
84117
84118+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
84119+ goto error;
84120+
84121 if (rgid != (gid_t) -1)
84122 new->gid = krgid;
84123 if (egid != (gid_t) -1)
84124@@ -746,12 +774,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
84125 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
84126 nsown_capable(CAP_SETUID)) {
84127 if (!uid_eq(kuid, old->fsuid)) {
84128+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
84129+ goto error;
84130+
84131 new->fsuid = kuid;
84132 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
84133 goto change_okay;
84134 }
84135 }
84136
84137+error:
84138 abort_creds(new);
84139 return old_fsuid;
84140
84141@@ -784,12 +816,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
84142 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
84143 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
84144 nsown_capable(CAP_SETGID)) {
84145+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
84146+ goto error;
84147+
84148 if (!gid_eq(kgid, old->fsgid)) {
84149 new->fsgid = kgid;
84150 goto change_okay;
84151 }
84152 }
84153
84154+error:
84155 abort_creds(new);
84156 return old_fsgid;
84157
84158@@ -1169,19 +1205,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
84159 return -EFAULT;
84160
84161 down_read(&uts_sem);
84162- error = __copy_to_user(&name->sysname, &utsname()->sysname,
84163+ error = __copy_to_user(name->sysname, &utsname()->sysname,
84164 __OLD_UTS_LEN);
84165 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
84166- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
84167+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
84168 __OLD_UTS_LEN);
84169 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
84170- error |= __copy_to_user(&name->release, &utsname()->release,
84171+ error |= __copy_to_user(name->release, &utsname()->release,
84172 __OLD_UTS_LEN);
84173 error |= __put_user(0, name->release + __OLD_UTS_LEN);
84174- error |= __copy_to_user(&name->version, &utsname()->version,
84175+ error |= __copy_to_user(name->version, &utsname()->version,
84176 __OLD_UTS_LEN);
84177 error |= __put_user(0, name->version + __OLD_UTS_LEN);
84178- error |= __copy_to_user(&name->machine, &utsname()->machine,
84179+ error |= __copy_to_user(name->machine, &utsname()->machine,
84180 __OLD_UTS_LEN);
84181 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
84182 up_read(&uts_sem);
84183@@ -1383,6 +1419,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
84184 */
84185 new_rlim->rlim_cur = 1;
84186 }
84187+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
84188+ is changed to a lower value. Since tasks can be created by the same
84189+ user in between this limit change and an execve by this task, force
84190+ a recheck only for this task by setting PF_NPROC_EXCEEDED
84191+ */
84192+ if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
84193+ tsk->flags |= PF_NPROC_EXCEEDED;
84194 }
84195 if (!retval) {
84196 if (old_rlim)
84197diff --git a/kernel/sysctl.c b/kernel/sysctl.c
84198index 07f6fc4..65fb3d4 100644
84199--- a/kernel/sysctl.c
84200+++ b/kernel/sysctl.c
84201@@ -93,7 +93,6 @@
84202
84203
84204 #if defined(CONFIG_SYSCTL)
84205-
84206 /* External variables not in a header file. */
84207 extern int sysctl_overcommit_memory;
84208 extern int sysctl_overcommit_ratio;
84209@@ -119,17 +118,18 @@ extern int blk_iopoll_enabled;
84210
84211 /* Constants used for minimum and maximum */
84212 #ifdef CONFIG_LOCKUP_DETECTOR
84213-static int sixty = 60;
84214+static int sixty __read_only = 60;
84215 #endif
84216
84217-static int zero;
84218-static int __maybe_unused one = 1;
84219-static int __maybe_unused two = 2;
84220-static int __maybe_unused three = 3;
84221-static unsigned long one_ul = 1;
84222-static int one_hundred = 100;
84223+static int neg_one __read_only = -1;
84224+static int zero __read_only = 0;
84225+static int __maybe_unused one __read_only = 1;
84226+static int __maybe_unused two __read_only = 2;
84227+static int __maybe_unused three __read_only = 3;
84228+static unsigned long one_ul __read_only = 1;
84229+static int one_hundred __read_only = 100;
84230 #ifdef CONFIG_PRINTK
84231-static int ten_thousand = 10000;
84232+static int ten_thousand __read_only = 10000;
84233 #endif
84234
84235 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
84236@@ -176,10 +176,8 @@ static int proc_taint(struct ctl_table *table, int write,
84237 void __user *buffer, size_t *lenp, loff_t *ppos);
84238 #endif
84239
84240-#ifdef CONFIG_PRINTK
84241 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
84242 void __user *buffer, size_t *lenp, loff_t *ppos);
84243-#endif
84244
84245 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
84246 void __user *buffer, size_t *lenp, loff_t *ppos);
84247@@ -210,6 +208,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
84248
84249 #endif
84250
84251+extern struct ctl_table grsecurity_table[];
84252+
84253 static struct ctl_table kern_table[];
84254 static struct ctl_table vm_table[];
84255 static struct ctl_table fs_table[];
84256@@ -224,6 +224,20 @@ extern struct ctl_table epoll_table[];
84257 int sysctl_legacy_va_layout;
84258 #endif
84259
84260+#ifdef CONFIG_PAX_SOFTMODE
84261+static ctl_table pax_table[] = {
84262+ {
84263+ .procname = "softmode",
84264+ .data = &pax_softmode,
84265+ .maxlen = sizeof(unsigned int),
84266+ .mode = 0600,
84267+ .proc_handler = &proc_dointvec,
84268+ },
84269+
84270+ { }
84271+};
84272+#endif
84273+
84274 /* The default sysctl tables: */
84275
84276 static struct ctl_table sysctl_base_table[] = {
84277@@ -272,6 +286,22 @@ static int max_extfrag_threshold = 1000;
84278 #endif
84279
84280 static struct ctl_table kern_table[] = {
84281+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
84282+ {
84283+ .procname = "grsecurity",
84284+ .mode = 0500,
84285+ .child = grsecurity_table,
84286+ },
84287+#endif
84288+
84289+#ifdef CONFIG_PAX_SOFTMODE
84290+ {
84291+ .procname = "pax",
84292+ .mode = 0500,
84293+ .child = pax_table,
84294+ },
84295+#endif
84296+
84297 {
84298 .procname = "sched_child_runs_first",
84299 .data = &sysctl_sched_child_runs_first,
84300@@ -613,7 +643,7 @@ static struct ctl_table kern_table[] = {
84301 .data = &modprobe_path,
84302 .maxlen = KMOD_PATH_LEN,
84303 .mode = 0644,
84304- .proc_handler = proc_dostring,
84305+ .proc_handler = proc_dostring_modpriv,
84306 },
84307 {
84308 .procname = "modules_disabled",
84309@@ -780,16 +810,20 @@ static struct ctl_table kern_table[] = {
84310 .extra1 = &zero,
84311 .extra2 = &one,
84312 },
84313+#endif
84314 {
84315 .procname = "kptr_restrict",
84316 .data = &kptr_restrict,
84317 .maxlen = sizeof(int),
84318 .mode = 0644,
84319 .proc_handler = proc_dointvec_minmax_sysadmin,
84320+#ifdef CONFIG_GRKERNSEC_HIDESYM
84321+ .extra1 = &two,
84322+#else
84323 .extra1 = &zero,
84324+#endif
84325 .extra2 = &two,
84326 },
84327-#endif
84328 {
84329 .procname = "ngroups_max",
84330 .data = &ngroups_max,
84331@@ -1031,10 +1065,17 @@ static struct ctl_table kern_table[] = {
84332 */
84333 {
84334 .procname = "perf_event_paranoid",
84335- .data = &sysctl_perf_event_paranoid,
84336- .maxlen = sizeof(sysctl_perf_event_paranoid),
84337+ .data = &sysctl_perf_event_legitimately_concerned,
84338+ .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
84339 .mode = 0644,
84340- .proc_handler = proc_dointvec,
84341+ /* go ahead, be a hero */
84342+ .proc_handler = proc_dointvec_minmax_sysadmin,
84343+ .extra1 = &neg_one,
84344+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
84345+ .extra2 = &three,
84346+#else
84347+ .extra2 = &two,
84348+#endif
84349 },
84350 {
84351 .procname = "perf_event_mlock_kb",
84352@@ -1297,6 +1338,13 @@ static struct ctl_table vm_table[] = {
84353 .proc_handler = proc_dointvec_minmax,
84354 .extra1 = &zero,
84355 },
84356+ {
84357+ .procname = "heap_stack_gap",
84358+ .data = &sysctl_heap_stack_gap,
84359+ .maxlen = sizeof(sysctl_heap_stack_gap),
84360+ .mode = 0644,
84361+ .proc_handler = proc_doulongvec_minmax,
84362+ },
84363 #else
84364 {
84365 .procname = "nr_trim_pages",
84366@@ -1761,6 +1809,16 @@ int proc_dostring(struct ctl_table *table, int write,
84367 buffer, lenp, ppos);
84368 }
84369
84370+int proc_dostring_modpriv(struct ctl_table *table, int write,
84371+ void __user *buffer, size_t *lenp, loff_t *ppos)
84372+{
84373+ if (write && !capable(CAP_SYS_MODULE))
84374+ return -EPERM;
84375+
84376+ return _proc_do_string(table->data, table->maxlen, write,
84377+ buffer, lenp, ppos);
84378+}
84379+
84380 static size_t proc_skip_spaces(char **buf)
84381 {
84382 size_t ret;
84383@@ -1866,6 +1924,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
84384 len = strlen(tmp);
84385 if (len > *size)
84386 len = *size;
84387+ if (len > sizeof(tmp))
84388+ len = sizeof(tmp);
84389 if (copy_to_user(*buf, tmp, len))
84390 return -EFAULT;
84391 *size -= len;
84392@@ -2030,7 +2090,7 @@ int proc_dointvec(struct ctl_table *table, int write,
84393 static int proc_taint(struct ctl_table *table, int write,
84394 void __user *buffer, size_t *lenp, loff_t *ppos)
84395 {
84396- struct ctl_table t;
84397+ ctl_table_no_const t;
84398 unsigned long tmptaint = get_taint();
84399 int err;
84400
84401@@ -2058,7 +2118,6 @@ static int proc_taint(struct ctl_table *table, int write,
84402 return err;
84403 }
84404
84405-#ifdef CONFIG_PRINTK
84406 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
84407 void __user *buffer, size_t *lenp, loff_t *ppos)
84408 {
84409@@ -2067,7 +2126,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
84410
84411 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
84412 }
84413-#endif
84414
84415 struct do_proc_dointvec_minmax_conv_param {
84416 int *min;
84417@@ -2214,8 +2272,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
84418 *i = val;
84419 } else {
84420 val = convdiv * (*i) / convmul;
84421- if (!first)
84422+ if (!first) {
84423 err = proc_put_char(&buffer, &left, '\t');
84424+ if (err)
84425+ break;
84426+ }
84427 err = proc_put_long(&buffer, &left, val, false);
84428 if (err)
84429 break;
84430@@ -2611,6 +2672,12 @@ int proc_dostring(struct ctl_table *table, int write,
84431 return -ENOSYS;
84432 }
84433
84434+int proc_dostring_modpriv(struct ctl_table *table, int write,
84435+ void __user *buffer, size_t *lenp, loff_t *ppos)
84436+{
84437+ return -ENOSYS;
84438+}
84439+
84440 int proc_dointvec(struct ctl_table *table, int write,
84441 void __user *buffer, size_t *lenp, loff_t *ppos)
84442 {
84443@@ -2667,5 +2734,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
84444 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
84445 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
84446 EXPORT_SYMBOL(proc_dostring);
84447+EXPORT_SYMBOL(proc_dostring_modpriv);
84448 EXPORT_SYMBOL(proc_doulongvec_minmax);
84449 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
84450diff --git a/kernel/taskstats.c b/kernel/taskstats.c
84451index 145bb4d..b2aa969 100644
84452--- a/kernel/taskstats.c
84453+++ b/kernel/taskstats.c
84454@@ -28,9 +28,12 @@
84455 #include <linux/fs.h>
84456 #include <linux/file.h>
84457 #include <linux/pid_namespace.h>
84458+#include <linux/grsecurity.h>
84459 #include <net/genetlink.h>
84460 #include <linux/atomic.h>
84461
84462+extern int gr_is_taskstats_denied(int pid);
84463+
84464 /*
84465 * Maximum length of a cpumask that can be specified in
84466 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
84467@@ -570,6 +573,9 @@ err:
84468
84469 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
84470 {
84471+ if (gr_is_taskstats_denied(current->pid))
84472+ return -EACCES;
84473+
84474 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
84475 return cmd_attr_register_cpumask(info);
84476 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
84477diff --git a/kernel/time.c b/kernel/time.c
84478index 7c7964c..784a599 100644
84479--- a/kernel/time.c
84480+++ b/kernel/time.c
84481@@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
84482 return error;
84483
84484 if (tz) {
84485+ /* we log in do_settimeofday called below, so don't log twice
84486+ */
84487+ if (!tv)
84488+ gr_log_timechange();
84489+
84490 sys_tz = *tz;
84491 update_vsyscall_tz();
84492 if (firsttime) {
84493@@ -502,7 +507,7 @@ EXPORT_SYMBOL(usecs_to_jiffies);
84494 * The >> (NSEC_JIFFIE_SC - SEC_JIFFIE_SC) converts the scaled nsec
84495 * value to a scaled second value.
84496 */
84497-unsigned long
84498+unsigned long __intentional_overflow(-1)
84499 timespec_to_jiffies(const struct timespec *value)
84500 {
84501 unsigned long sec = value->tv_sec;
84502diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
84503index eec50fc..65e5df6 100644
84504--- a/kernel/time/alarmtimer.c
84505+++ b/kernel/time/alarmtimer.c
84506@@ -795,7 +795,7 @@ static int __init alarmtimer_init(void)
84507 struct platform_device *pdev;
84508 int error = 0;
84509 int i;
84510- struct k_clock alarm_clock = {
84511+ static struct k_clock alarm_clock = {
84512 .clock_getres = alarm_clock_getres,
84513 .clock_get = alarm_clock_get,
84514 .timer_create = alarm_timer_create,
84515diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
84516index 48b9fff..9e07e5f 100644
84517--- a/kernel/time/timekeeping.c
84518+++ b/kernel/time/timekeeping.c
84519@@ -15,6 +15,7 @@
84520 #include <linux/init.h>
84521 #include <linux/mm.h>
84522 #include <linux/sched.h>
84523+#include <linux/grsecurity.h>
84524 #include <linux/syscore_ops.h>
84525 #include <linux/clocksource.h>
84526 #include <linux/jiffies.h>
84527@@ -500,6 +501,8 @@ int do_settimeofday(const struct timespec *tv)
84528 if (!timespec_valid_strict(tv))
84529 return -EINVAL;
84530
84531+ gr_log_timechange();
84532+
84533 raw_spin_lock_irqsave(&timekeeper_lock, flags);
84534 write_seqcount_begin(&timekeeper_seq);
84535
84536diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
84537index 61ed862..3b52c65 100644
84538--- a/kernel/time/timer_list.c
84539+++ b/kernel/time/timer_list.c
84540@@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
84541
84542 static void print_name_offset(struct seq_file *m, void *sym)
84543 {
84544+#ifdef CONFIG_GRKERNSEC_HIDESYM
84545+ SEQ_printf(m, "<%p>", NULL);
84546+#else
84547 char symname[KSYM_NAME_LEN];
84548
84549 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
84550 SEQ_printf(m, "<%pK>", sym);
84551 else
84552 SEQ_printf(m, "%s", symname);
84553+#endif
84554 }
84555
84556 static void
84557@@ -119,7 +123,11 @@ next_one:
84558 static void
84559 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
84560 {
84561+#ifdef CONFIG_GRKERNSEC_HIDESYM
84562+ SEQ_printf(m, " .base: %p\n", NULL);
84563+#else
84564 SEQ_printf(m, " .base: %pK\n", base);
84565+#endif
84566 SEQ_printf(m, " .index: %d\n",
84567 base->index);
84568 SEQ_printf(m, " .resolution: %Lu nsecs\n",
84569@@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
84570 {
84571 struct proc_dir_entry *pe;
84572
84573+#ifdef CONFIG_GRKERNSEC_PROC_ADD
84574+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
84575+#else
84576 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
84577+#endif
84578 if (!pe)
84579 return -ENOMEM;
84580 return 0;
84581diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
84582index 0b537f2..40d6c20 100644
84583--- a/kernel/time/timer_stats.c
84584+++ b/kernel/time/timer_stats.c
84585@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
84586 static unsigned long nr_entries;
84587 static struct entry entries[MAX_ENTRIES];
84588
84589-static atomic_t overflow_count;
84590+static atomic_unchecked_t overflow_count;
84591
84592 /*
84593 * The entries are in a hash-table, for fast lookup:
84594@@ -140,7 +140,7 @@ static void reset_entries(void)
84595 nr_entries = 0;
84596 memset(entries, 0, sizeof(entries));
84597 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
84598- atomic_set(&overflow_count, 0);
84599+ atomic_set_unchecked(&overflow_count, 0);
84600 }
84601
84602 static struct entry *alloc_entry(void)
84603@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
84604 if (likely(entry))
84605 entry->count++;
84606 else
84607- atomic_inc(&overflow_count);
84608+ atomic_inc_unchecked(&overflow_count);
84609
84610 out_unlock:
84611 raw_spin_unlock_irqrestore(lock, flags);
84612@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
84613
84614 static void print_name_offset(struct seq_file *m, unsigned long addr)
84615 {
84616+#ifdef CONFIG_GRKERNSEC_HIDESYM
84617+ seq_printf(m, "<%p>", NULL);
84618+#else
84619 char symname[KSYM_NAME_LEN];
84620
84621 if (lookup_symbol_name(addr, symname) < 0)
84622- seq_printf(m, "<%p>", (void *)addr);
84623+ seq_printf(m, "<%pK>", (void *)addr);
84624 else
84625 seq_printf(m, "%s", symname);
84626+#endif
84627 }
84628
84629 static int tstats_show(struct seq_file *m, void *v)
84630@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
84631
84632 seq_puts(m, "Timer Stats Version: v0.2\n");
84633 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
84634- if (atomic_read(&overflow_count))
84635+ if (atomic_read_unchecked(&overflow_count))
84636 seq_printf(m, "Overflow: %d entries\n",
84637- atomic_read(&overflow_count));
84638+ atomic_read_unchecked(&overflow_count));
84639
84640 for (i = 0; i < nr_entries; i++) {
84641 entry = entries + i;
84642@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
84643 {
84644 struct proc_dir_entry *pe;
84645
84646+#ifdef CONFIG_GRKERNSEC_PROC_ADD
84647+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
84648+#else
84649 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
84650+#endif
84651 if (!pe)
84652 return -ENOMEM;
84653 return 0;
84654diff --git a/kernel/timer.c b/kernel/timer.c
84655index 4296d13..8998609 100644
84656--- a/kernel/timer.c
84657+++ b/kernel/timer.c
84658@@ -1366,7 +1366,7 @@ void update_process_times(int user_tick)
84659 /*
84660 * This function runs timers and the timer-tq in bottom half context.
84661 */
84662-static void run_timer_softirq(struct softirq_action *h)
84663+static void run_timer_softirq(void)
84664 {
84665 struct tvec_base *base = __this_cpu_read(tvec_bases);
84666
84667@@ -1429,7 +1429,7 @@ static void process_timeout(unsigned long __data)
84668 *
84669 * In all cases the return value is guaranteed to be non-negative.
84670 */
84671-signed long __sched schedule_timeout(signed long timeout)
84672+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
84673 {
84674 struct timer_list timer;
84675 unsigned long expire;
84676diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
84677index b8b8560..75b1a09 100644
84678--- a/kernel/trace/blktrace.c
84679+++ b/kernel/trace/blktrace.c
84680@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
84681 struct blk_trace *bt = filp->private_data;
84682 char buf[16];
84683
84684- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
84685+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
84686
84687 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
84688 }
84689@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
84690 return 1;
84691
84692 bt = buf->chan->private_data;
84693- atomic_inc(&bt->dropped);
84694+ atomic_inc_unchecked(&bt->dropped);
84695 return 0;
84696 }
84697
84698@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
84699
84700 bt->dir = dir;
84701 bt->dev = dev;
84702- atomic_set(&bt->dropped, 0);
84703+ atomic_set_unchecked(&bt->dropped, 0);
84704
84705 ret = -EIO;
84706 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
84707diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
84708index a6d098c..bb8cf65 100644
84709--- a/kernel/trace/ftrace.c
84710+++ b/kernel/trace/ftrace.c
84711@@ -1950,12 +1950,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
84712 if (unlikely(ftrace_disabled))
84713 return 0;
84714
84715+ ret = ftrace_arch_code_modify_prepare();
84716+ FTRACE_WARN_ON(ret);
84717+ if (ret)
84718+ return 0;
84719+
84720 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
84721+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
84722 if (ret) {
84723 ftrace_bug(ret, ip);
84724- return 0;
84725 }
84726- return 1;
84727+ return ret ? 0 : 1;
84728 }
84729
84730 /*
84731@@ -4028,8 +4033,10 @@ static int ftrace_process_locs(struct module *mod,
84732 if (!count)
84733 return 0;
84734
84735+ pax_open_kernel();
84736 sort(start, count, sizeof(*start),
84737 ftrace_cmp_ips, ftrace_swap_ips);
84738+ pax_close_kernel();
84739
84740 start_pg = ftrace_allocate_pages(count);
84741 if (!start_pg)
84742@@ -4752,8 +4759,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
84743 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
84744
84745 static int ftrace_graph_active;
84746-static struct notifier_block ftrace_suspend_notifier;
84747-
84748 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
84749 {
84750 return 0;
84751@@ -4897,6 +4902,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
84752 return NOTIFY_DONE;
84753 }
84754
84755+static struct notifier_block ftrace_suspend_notifier = {
84756+ .notifier_call = ftrace_suspend_notifier_call
84757+};
84758+
84759 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
84760 trace_func_graph_ent_t entryfunc)
84761 {
84762@@ -4910,7 +4919,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
84763 goto out;
84764 }
84765
84766- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
84767 register_pm_notifier(&ftrace_suspend_notifier);
84768
84769 ftrace_graph_active++;
84770diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
84771index cc2f66f..05edd54 100644
84772--- a/kernel/trace/ring_buffer.c
84773+++ b/kernel/trace/ring_buffer.c
84774@@ -352,9 +352,9 @@ struct buffer_data_page {
84775 */
84776 struct buffer_page {
84777 struct list_head list; /* list of buffer pages */
84778- local_t write; /* index for next write */
84779+ local_unchecked_t write; /* index for next write */
84780 unsigned read; /* index for next read */
84781- local_t entries; /* entries on this page */
84782+ local_unchecked_t entries; /* entries on this page */
84783 unsigned long real_end; /* real end of data */
84784 struct buffer_data_page *page; /* Actual data page */
84785 };
84786@@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
84787 unsigned long last_overrun;
84788 local_t entries_bytes;
84789 local_t entries;
84790- local_t overrun;
84791- local_t commit_overrun;
84792+ local_unchecked_t overrun;
84793+ local_unchecked_t commit_overrun;
84794 local_t dropped_events;
84795 local_t committing;
84796 local_t commits;
84797@@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
84798 *
84799 * We add a counter to the write field to denote this.
84800 */
84801- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
84802- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
84803+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
84804+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
84805
84806 /*
84807 * Just make sure we have seen our old_write and synchronize
84808@@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
84809 * cmpxchg to only update if an interrupt did not already
84810 * do it for us. If the cmpxchg fails, we don't care.
84811 */
84812- (void)local_cmpxchg(&next_page->write, old_write, val);
84813- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
84814+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
84815+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
84816
84817 /*
84818 * No need to worry about races with clearing out the commit.
84819@@ -1386,12 +1386,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
84820
84821 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
84822 {
84823- return local_read(&bpage->entries) & RB_WRITE_MASK;
84824+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
84825 }
84826
84827 static inline unsigned long rb_page_write(struct buffer_page *bpage)
84828 {
84829- return local_read(&bpage->write) & RB_WRITE_MASK;
84830+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
84831 }
84832
84833 static int
84834@@ -1486,7 +1486,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
84835 * bytes consumed in ring buffer from here.
84836 * Increment overrun to account for the lost events.
84837 */
84838- local_add(page_entries, &cpu_buffer->overrun);
84839+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
84840 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
84841 }
84842
84843@@ -2064,7 +2064,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
84844 * it is our responsibility to update
84845 * the counters.
84846 */
84847- local_add(entries, &cpu_buffer->overrun);
84848+ local_add_unchecked(entries, &cpu_buffer->overrun);
84849 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
84850
84851 /*
84852@@ -2214,7 +2214,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
84853 if (tail == BUF_PAGE_SIZE)
84854 tail_page->real_end = 0;
84855
84856- local_sub(length, &tail_page->write);
84857+ local_sub_unchecked(length, &tail_page->write);
84858 return;
84859 }
84860
84861@@ -2249,7 +2249,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
84862 rb_event_set_padding(event);
84863
84864 /* Set the write back to the previous setting */
84865- local_sub(length, &tail_page->write);
84866+ local_sub_unchecked(length, &tail_page->write);
84867 return;
84868 }
84869
84870@@ -2261,7 +2261,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
84871
84872 /* Set write to end of buffer */
84873 length = (tail + length) - BUF_PAGE_SIZE;
84874- local_sub(length, &tail_page->write);
84875+ local_sub_unchecked(length, &tail_page->write);
84876 }
84877
84878 /*
84879@@ -2287,7 +2287,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
84880 * about it.
84881 */
84882 if (unlikely(next_page == commit_page)) {
84883- local_inc(&cpu_buffer->commit_overrun);
84884+ local_inc_unchecked(&cpu_buffer->commit_overrun);
84885 goto out_reset;
84886 }
84887
84888@@ -2343,7 +2343,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
84889 cpu_buffer->tail_page) &&
84890 (cpu_buffer->commit_page ==
84891 cpu_buffer->reader_page))) {
84892- local_inc(&cpu_buffer->commit_overrun);
84893+ local_inc_unchecked(&cpu_buffer->commit_overrun);
84894 goto out_reset;
84895 }
84896 }
84897@@ -2391,7 +2391,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
84898 length += RB_LEN_TIME_EXTEND;
84899
84900 tail_page = cpu_buffer->tail_page;
84901- write = local_add_return(length, &tail_page->write);
84902+ write = local_add_return_unchecked(length, &tail_page->write);
84903
84904 /* set write to only the index of the write */
84905 write &= RB_WRITE_MASK;
84906@@ -2408,7 +2408,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
84907 kmemcheck_annotate_bitfield(event, bitfield);
84908 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
84909
84910- local_inc(&tail_page->entries);
84911+ local_inc_unchecked(&tail_page->entries);
84912
84913 /*
84914 * If this is the first commit on the page, then update
84915@@ -2441,7 +2441,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
84916
84917 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
84918 unsigned long write_mask =
84919- local_read(&bpage->write) & ~RB_WRITE_MASK;
84920+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
84921 unsigned long event_length = rb_event_length(event);
84922 /*
84923 * This is on the tail page. It is possible that
84924@@ -2451,7 +2451,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
84925 */
84926 old_index += write_mask;
84927 new_index += write_mask;
84928- index = local_cmpxchg(&bpage->write, old_index, new_index);
84929+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
84930 if (index == old_index) {
84931 /* update counters */
84932 local_sub(event_length, &cpu_buffer->entries_bytes);
84933@@ -2843,7 +2843,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
84934
84935 /* Do the likely case first */
84936 if (likely(bpage->page == (void *)addr)) {
84937- local_dec(&bpage->entries);
84938+ local_dec_unchecked(&bpage->entries);
84939 return;
84940 }
84941
84942@@ -2855,7 +2855,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
84943 start = bpage;
84944 do {
84945 if (bpage->page == (void *)addr) {
84946- local_dec(&bpage->entries);
84947+ local_dec_unchecked(&bpage->entries);
84948 return;
84949 }
84950 rb_inc_page(cpu_buffer, &bpage);
84951@@ -3139,7 +3139,7 @@ static inline unsigned long
84952 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
84953 {
84954 return local_read(&cpu_buffer->entries) -
84955- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
84956+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
84957 }
84958
84959 /**
84960@@ -3228,7 +3228,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
84961 return 0;
84962
84963 cpu_buffer = buffer->buffers[cpu];
84964- ret = local_read(&cpu_buffer->overrun);
84965+ ret = local_read_unchecked(&cpu_buffer->overrun);
84966
84967 return ret;
84968 }
84969@@ -3251,7 +3251,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
84970 return 0;
84971
84972 cpu_buffer = buffer->buffers[cpu];
84973- ret = local_read(&cpu_buffer->commit_overrun);
84974+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
84975
84976 return ret;
84977 }
84978@@ -3336,7 +3336,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
84979 /* if you care about this being correct, lock the buffer */
84980 for_each_buffer_cpu(buffer, cpu) {
84981 cpu_buffer = buffer->buffers[cpu];
84982- overruns += local_read(&cpu_buffer->overrun);
84983+ overruns += local_read_unchecked(&cpu_buffer->overrun);
84984 }
84985
84986 return overruns;
84987@@ -3512,8 +3512,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
84988 /*
84989 * Reset the reader page to size zero.
84990 */
84991- local_set(&cpu_buffer->reader_page->write, 0);
84992- local_set(&cpu_buffer->reader_page->entries, 0);
84993+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
84994+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
84995 local_set(&cpu_buffer->reader_page->page->commit, 0);
84996 cpu_buffer->reader_page->real_end = 0;
84997
84998@@ -3547,7 +3547,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
84999 * want to compare with the last_overrun.
85000 */
85001 smp_mb();
85002- overwrite = local_read(&(cpu_buffer->overrun));
85003+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
85004
85005 /*
85006 * Here's the tricky part.
85007@@ -4117,8 +4117,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
85008
85009 cpu_buffer->head_page
85010 = list_entry(cpu_buffer->pages, struct buffer_page, list);
85011- local_set(&cpu_buffer->head_page->write, 0);
85012- local_set(&cpu_buffer->head_page->entries, 0);
85013+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
85014+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
85015 local_set(&cpu_buffer->head_page->page->commit, 0);
85016
85017 cpu_buffer->head_page->read = 0;
85018@@ -4128,14 +4128,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
85019
85020 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
85021 INIT_LIST_HEAD(&cpu_buffer->new_pages);
85022- local_set(&cpu_buffer->reader_page->write, 0);
85023- local_set(&cpu_buffer->reader_page->entries, 0);
85024+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
85025+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
85026 local_set(&cpu_buffer->reader_page->page->commit, 0);
85027 cpu_buffer->reader_page->read = 0;
85028
85029 local_set(&cpu_buffer->entries_bytes, 0);
85030- local_set(&cpu_buffer->overrun, 0);
85031- local_set(&cpu_buffer->commit_overrun, 0);
85032+ local_set_unchecked(&cpu_buffer->overrun, 0);
85033+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
85034 local_set(&cpu_buffer->dropped_events, 0);
85035 local_set(&cpu_buffer->entries, 0);
85036 local_set(&cpu_buffer->committing, 0);
85037@@ -4540,8 +4540,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
85038 rb_init_page(bpage);
85039 bpage = reader->page;
85040 reader->page = *data_page;
85041- local_set(&reader->write, 0);
85042- local_set(&reader->entries, 0);
85043+ local_set_unchecked(&reader->write, 0);
85044+ local_set_unchecked(&reader->entries, 0);
85045 reader->read = 0;
85046 *data_page = bpage;
85047
85048diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
85049index 496f94d..754aeea 100644
85050--- a/kernel/trace/trace.c
85051+++ b/kernel/trace/trace.c
85052@@ -3335,7 +3335,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
85053 return 0;
85054 }
85055
85056-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
85057+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
85058 {
85059 /* do nothing if flag is already set */
85060 if (!!(trace_flags & mask) == !!enabled)
85061diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
85062index afaae41..64871f8 100644
85063--- a/kernel/trace/trace.h
85064+++ b/kernel/trace/trace.h
85065@@ -1025,7 +1025,7 @@ extern const char *__stop___trace_bprintk_fmt[];
85066 void trace_printk_init_buffers(void);
85067 void trace_printk_start_comm(void);
85068 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
85069-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
85070+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
85071
85072 /*
85073 * Normal trace_printk() and friends allocates special buffers
85074diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
85075index 26dc348..8708ca7 100644
85076--- a/kernel/trace/trace_clock.c
85077+++ b/kernel/trace/trace_clock.c
85078@@ -123,7 +123,7 @@ u64 notrace trace_clock_global(void)
85079 return now;
85080 }
85081
85082-static atomic64_t trace_counter;
85083+static atomic64_unchecked_t trace_counter;
85084
85085 /*
85086 * trace_clock_counter(): simply an atomic counter.
85087@@ -132,5 +132,5 @@ static atomic64_t trace_counter;
85088 */
85089 u64 notrace trace_clock_counter(void)
85090 {
85091- return atomic64_add_return(1, &trace_counter);
85092+ return atomic64_inc_return_unchecked(&trace_counter);
85093 }
85094diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
85095index 29a7ebc..eb473cf 100644
85096--- a/kernel/trace/trace_events.c
85097+++ b/kernel/trace/trace_events.c
85098@@ -1778,10 +1778,6 @@ static LIST_HEAD(ftrace_module_file_list);
85099 struct ftrace_module_file_ops {
85100 struct list_head list;
85101 struct module *mod;
85102- struct file_operations id;
85103- struct file_operations enable;
85104- struct file_operations format;
85105- struct file_operations filter;
85106 };
85107
85108 static struct ftrace_module_file_ops *
85109@@ -1822,17 +1818,12 @@ trace_create_file_ops(struct module *mod)
85110
85111 file_ops->mod = mod;
85112
85113- file_ops->id = ftrace_event_id_fops;
85114- file_ops->id.owner = mod;
85115-
85116- file_ops->enable = ftrace_enable_fops;
85117- file_ops->enable.owner = mod;
85118-
85119- file_ops->filter = ftrace_event_filter_fops;
85120- file_ops->filter.owner = mod;
85121-
85122- file_ops->format = ftrace_event_format_fops;
85123- file_ops->format.owner = mod;
85124+ pax_open_kernel();
85125+ mod->trace_id.owner = mod;
85126+ mod->trace_enable.owner = mod;
85127+ mod->trace_filter.owner = mod;
85128+ mod->trace_format.owner = mod;
85129+ pax_close_kernel();
85130
85131 list_add(&file_ops->list, &ftrace_module_file_list);
85132
85133@@ -1925,8 +1916,8 @@ __trace_add_new_mod_event(struct ftrace_event_call *call,
85134 struct ftrace_module_file_ops *file_ops)
85135 {
85136 return __trace_add_new_event(call, tr,
85137- &file_ops->id, &file_ops->enable,
85138- &file_ops->filter, &file_ops->format);
85139+ &file_ops->mod->trace_id, &file_ops->mod->trace_enable,
85140+ &file_ops->mod->trace_filter, &file_ops->mod->trace_format);
85141 }
85142
85143 #else
85144diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
85145index b3dcfb2..ebee344 100644
85146--- a/kernel/trace/trace_mmiotrace.c
85147+++ b/kernel/trace/trace_mmiotrace.c
85148@@ -24,7 +24,7 @@ struct header_iter {
85149 static struct trace_array *mmio_trace_array;
85150 static bool overrun_detected;
85151 static unsigned long prev_overruns;
85152-static atomic_t dropped_count;
85153+static atomic_unchecked_t dropped_count;
85154
85155 static void mmio_reset_data(struct trace_array *tr)
85156 {
85157@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
85158
85159 static unsigned long count_overruns(struct trace_iterator *iter)
85160 {
85161- unsigned long cnt = atomic_xchg(&dropped_count, 0);
85162+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
85163 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
85164
85165 if (over > prev_overruns)
85166@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
85167 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
85168 sizeof(*entry), 0, pc);
85169 if (!event) {
85170- atomic_inc(&dropped_count);
85171+ atomic_inc_unchecked(&dropped_count);
85172 return;
85173 }
85174 entry = ring_buffer_event_data(event);
85175@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
85176 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
85177 sizeof(*entry), 0, pc);
85178 if (!event) {
85179- atomic_inc(&dropped_count);
85180+ atomic_inc_unchecked(&dropped_count);
85181 return;
85182 }
85183 entry = ring_buffer_event_data(event);
85184diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
85185index 34e7cba..6f9a729 100644
85186--- a/kernel/trace/trace_output.c
85187+++ b/kernel/trace/trace_output.c
85188@@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
85189
85190 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
85191 if (!IS_ERR(p)) {
85192- p = mangle_path(s->buffer + s->len, p, "\n");
85193+ p = mangle_path(s->buffer + s->len, p, "\n\\");
85194 if (p) {
85195 s->len = p - s->buffer;
85196 return 1;
85197@@ -893,14 +893,16 @@ int register_ftrace_event(struct trace_event *event)
85198 goto out;
85199 }
85200
85201+ pax_open_kernel();
85202 if (event->funcs->trace == NULL)
85203- event->funcs->trace = trace_nop_print;
85204+ *(void **)&event->funcs->trace = trace_nop_print;
85205 if (event->funcs->raw == NULL)
85206- event->funcs->raw = trace_nop_print;
85207+ *(void **)&event->funcs->raw = trace_nop_print;
85208 if (event->funcs->hex == NULL)
85209- event->funcs->hex = trace_nop_print;
85210+ *(void **)&event->funcs->hex = trace_nop_print;
85211 if (event->funcs->binary == NULL)
85212- event->funcs->binary = trace_nop_print;
85213+ *(void **)&event->funcs->binary = trace_nop_print;
85214+ pax_close_kernel();
85215
85216 key = event->type & (EVENT_HASHSIZE - 1);
85217
85218diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
85219index b20428c..4845a10 100644
85220--- a/kernel/trace/trace_stack.c
85221+++ b/kernel/trace/trace_stack.c
85222@@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
85223 return;
85224
85225 /* we do not handle interrupt stacks yet */
85226- if (!object_is_on_stack(stack))
85227+ if (!object_starts_on_stack(stack))
85228 return;
85229
85230 local_irq_save(flags);
85231diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
85232index 9064b91..1f5d2f8 100644
85233--- a/kernel/user_namespace.c
85234+++ b/kernel/user_namespace.c
85235@@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
85236 !kgid_has_mapping(parent_ns, group))
85237 return -EPERM;
85238
85239+#ifdef CONFIG_GRKERNSEC
85240+ /*
85241+ * This doesn't really inspire confidence:
85242+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
85243+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
85244+ * Increases kernel attack surface in areas developers
85245+ * previously cared little about ("low importance due
85246+ * to requiring "root" capability")
85247+ * To be removed when this code receives *proper* review
85248+ */
85249+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
85250+ !capable(CAP_SETGID))
85251+ return -EPERM;
85252+#endif
85253+
85254 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
85255 if (!ns)
85256 return -ENOMEM;
85257@@ -862,7 +877,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
85258 if (atomic_read(&current->mm->mm_users) > 1)
85259 return -EINVAL;
85260
85261- if (current->fs->users != 1)
85262+ if (atomic_read(&current->fs->users) != 1)
85263 return -EINVAL;
85264
85265 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
85266diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
85267index 4f69f9a..7c6f8f8 100644
85268--- a/kernel/utsname_sysctl.c
85269+++ b/kernel/utsname_sysctl.c
85270@@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
85271 static int proc_do_uts_string(ctl_table *table, int write,
85272 void __user *buffer, size_t *lenp, loff_t *ppos)
85273 {
85274- struct ctl_table uts_table;
85275+ ctl_table_no_const uts_table;
85276 int r;
85277 memcpy(&uts_table, table, sizeof(uts_table));
85278 uts_table.data = get_uts(table, write);
85279diff --git a/kernel/watchdog.c b/kernel/watchdog.c
85280index 1241d8c..d5cfc28 100644
85281--- a/kernel/watchdog.c
85282+++ b/kernel/watchdog.c
85283@@ -475,7 +475,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
85284 static void watchdog_nmi_disable(unsigned int cpu) { return; }
85285 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
85286
85287-static struct smp_hotplug_thread watchdog_threads = {
85288+static struct smp_hotplug_thread watchdog_threads __read_only = {
85289 .store = &softlockup_watchdog,
85290 .thread_should_run = watchdog_should_run,
85291 .thread_fn = watchdog,
85292diff --git a/kernel/workqueue.c b/kernel/workqueue.c
85293index e93f7b9..989fcd7 100644
85294--- a/kernel/workqueue.c
85295+++ b/kernel/workqueue.c
85296@@ -4627,7 +4627,7 @@ static void rebind_workers(struct worker_pool *pool)
85297 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
85298 worker_flags |= WORKER_REBOUND;
85299 worker_flags &= ~WORKER_UNBOUND;
85300- ACCESS_ONCE(worker->flags) = worker_flags;
85301+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
85302 }
85303
85304 spin_unlock_irq(&pool->lock);
85305diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
85306index 1501aa5..e771896 100644
85307--- a/lib/Kconfig.debug
85308+++ b/lib/Kconfig.debug
85309@@ -836,7 +836,7 @@ config DEBUG_MUTEXES
85310
85311 config DEBUG_WW_MUTEX_SLOWPATH
85312 bool "Wait/wound mutex debugging: Slowpath testing"
85313- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
85314+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
85315 select DEBUG_LOCK_ALLOC
85316 select DEBUG_SPINLOCK
85317 select DEBUG_MUTEXES
85318@@ -849,7 +849,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
85319
85320 config DEBUG_LOCK_ALLOC
85321 bool "Lock debugging: detect incorrect freeing of live locks"
85322- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
85323+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
85324 select DEBUG_SPINLOCK
85325 select DEBUG_MUTEXES
85326 select LOCKDEP
85327@@ -863,7 +863,7 @@ config DEBUG_LOCK_ALLOC
85328
85329 config PROVE_LOCKING
85330 bool "Lock debugging: prove locking correctness"
85331- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
85332+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
85333 select LOCKDEP
85334 select DEBUG_SPINLOCK
85335 select DEBUG_MUTEXES
85336@@ -914,7 +914,7 @@ config LOCKDEP
85337
85338 config LOCK_STAT
85339 bool "Lock usage statistics"
85340- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
85341+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
85342 select LOCKDEP
85343 select DEBUG_SPINLOCK
85344 select DEBUG_MUTEXES
85345@@ -1357,6 +1357,7 @@ config LATENCYTOP
85346 depends on DEBUG_KERNEL
85347 depends on STACKTRACE_SUPPORT
85348 depends on PROC_FS
85349+ depends on !GRKERNSEC_HIDESYM
85350 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
85351 select KALLSYMS
85352 select KALLSYMS_ALL
85353@@ -1373,7 +1374,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
85354 config DEBUG_STRICT_USER_COPY_CHECKS
85355 bool "Strict user copy size checks"
85356 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
85357- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
85358+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
85359 help
85360 Enabling this option turns a certain set of sanity checks for user
85361 copy operations into compile time failures.
85362@@ -1483,7 +1484,7 @@ endmenu # runtime tests
85363
85364 config PROVIDE_OHCI1394_DMA_INIT
85365 bool "Remote debugging over FireWire early on boot"
85366- depends on PCI && X86
85367+ depends on PCI && X86 && !GRKERNSEC
85368 help
85369 If you want to debug problems which hang or crash the kernel early
85370 on boot and the crashing machine has a FireWire port, you can use
85371@@ -1512,7 +1513,7 @@ config PROVIDE_OHCI1394_DMA_INIT
85372
85373 config FIREWIRE_OHCI_REMOTE_DMA
85374 bool "Remote debugging over FireWire with firewire-ohci"
85375- depends on FIREWIRE_OHCI
85376+ depends on FIREWIRE_OHCI && !GRKERNSEC
85377 help
85378 This option lets you use the FireWire bus for remote debugging
85379 with help of the firewire-ohci driver. It enables unfiltered
85380diff --git a/lib/Makefile b/lib/Makefile
85381index 7baccfd..3ceb95f 100644
85382--- a/lib/Makefile
85383+++ b/lib/Makefile
85384@@ -50,7 +50,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
85385
85386 obj-$(CONFIG_BTREE) += btree.o
85387 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
85388-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
85389+obj-y += list_debug.o
85390 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
85391
85392 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
85393diff --git a/lib/bitmap.c b/lib/bitmap.c
85394index 06f7e4f..f3cf2b0 100644
85395--- a/lib/bitmap.c
85396+++ b/lib/bitmap.c
85397@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
85398 {
85399 int c, old_c, totaldigits, ndigits, nchunks, nbits;
85400 u32 chunk;
85401- const char __user __force *ubuf = (const char __user __force *)buf;
85402+ const char __user *ubuf = (const char __force_user *)buf;
85403
85404 bitmap_zero(maskp, nmaskbits);
85405
85406@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
85407 {
85408 if (!access_ok(VERIFY_READ, ubuf, ulen))
85409 return -EFAULT;
85410- return __bitmap_parse((const char __force *)ubuf,
85411+ return __bitmap_parse((const char __force_kernel *)ubuf,
85412 ulen, 1, maskp, nmaskbits);
85413
85414 }
85415@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
85416 {
85417 unsigned a, b;
85418 int c, old_c, totaldigits;
85419- const char __user __force *ubuf = (const char __user __force *)buf;
85420+ const char __user *ubuf = (const char __force_user *)buf;
85421 int exp_digit, in_range;
85422
85423 totaldigits = c = 0;
85424@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
85425 {
85426 if (!access_ok(VERIFY_READ, ubuf, ulen))
85427 return -EFAULT;
85428- return __bitmap_parselist((const char __force *)ubuf,
85429+ return __bitmap_parselist((const char __force_kernel *)ubuf,
85430 ulen, 1, maskp, nmaskbits);
85431 }
85432 EXPORT_SYMBOL(bitmap_parselist_user);
85433diff --git a/lib/bug.c b/lib/bug.c
85434index 1686034..a9c00c8 100644
85435--- a/lib/bug.c
85436+++ b/lib/bug.c
85437@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
85438 return BUG_TRAP_TYPE_NONE;
85439
85440 bug = find_bug(bugaddr);
85441+ if (!bug)
85442+ return BUG_TRAP_TYPE_NONE;
85443
85444 file = NULL;
85445 line = 0;
85446diff --git a/lib/debugobjects.c b/lib/debugobjects.c
85447index 37061ed..da83f48 100644
85448--- a/lib/debugobjects.c
85449+++ b/lib/debugobjects.c
85450@@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
85451 if (limit > 4)
85452 return;
85453
85454- is_on_stack = object_is_on_stack(addr);
85455+ is_on_stack = object_starts_on_stack(addr);
85456 if (is_on_stack == onstack)
85457 return;
85458
85459diff --git a/lib/devres.c b/lib/devres.c
85460index 8235331..5881053 100644
85461--- a/lib/devres.c
85462+++ b/lib/devres.c
85463@@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
85464 void devm_iounmap(struct device *dev, void __iomem *addr)
85465 {
85466 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
85467- (void *)addr));
85468+ (void __force *)addr));
85469 iounmap(addr);
85470 }
85471 EXPORT_SYMBOL(devm_iounmap);
85472@@ -224,7 +224,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
85473 {
85474 ioport_unmap(addr);
85475 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
85476- devm_ioport_map_match, (void *)addr));
85477+ devm_ioport_map_match, (void __force *)addr));
85478 }
85479 EXPORT_SYMBOL(devm_ioport_unmap);
85480 #endif /* CONFIG_HAS_IOPORT */
85481diff --git a/lib/div64.c b/lib/div64.c
85482index a163b6c..9618fa5 100644
85483--- a/lib/div64.c
85484+++ b/lib/div64.c
85485@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
85486 EXPORT_SYMBOL(__div64_32);
85487
85488 #ifndef div_s64_rem
85489-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
85490+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
85491 {
85492 u64 quotient;
85493
85494@@ -90,7 +90,7 @@ EXPORT_SYMBOL(div_s64_rem);
85495 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
85496 */
85497 #ifndef div64_u64
85498-u64 div64_u64(u64 dividend, u64 divisor)
85499+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
85500 {
85501 u32 high = divisor >> 32;
85502 u64 quot;
85503diff --git a/lib/dma-debug.c b/lib/dma-debug.c
85504index d87a17a..ac0d79a 100644
85505--- a/lib/dma-debug.c
85506+++ b/lib/dma-debug.c
85507@@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
85508
85509 void dma_debug_add_bus(struct bus_type *bus)
85510 {
85511- struct notifier_block *nb;
85512+ notifier_block_no_const *nb;
85513
85514 if (global_disable)
85515 return;
85516@@ -945,7 +945,7 @@ static void check_unmap(struct dma_debug_entry *ref)
85517
85518 static void check_for_stack(struct device *dev, void *addr)
85519 {
85520- if (object_is_on_stack(addr))
85521+ if (object_starts_on_stack(addr))
85522 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
85523 "stack [addr=%p]\n", addr);
85524 }
85525diff --git a/lib/inflate.c b/lib/inflate.c
85526index 013a761..c28f3fc 100644
85527--- a/lib/inflate.c
85528+++ b/lib/inflate.c
85529@@ -269,7 +269,7 @@ static void free(void *where)
85530 malloc_ptr = free_mem_ptr;
85531 }
85532 #else
85533-#define malloc(a) kmalloc(a, GFP_KERNEL)
85534+#define malloc(a) kmalloc((a), GFP_KERNEL)
85535 #define free(a) kfree(a)
85536 #endif
85537
85538diff --git a/lib/ioremap.c b/lib/ioremap.c
85539index 0c9216c..863bd89 100644
85540--- a/lib/ioremap.c
85541+++ b/lib/ioremap.c
85542@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
85543 unsigned long next;
85544
85545 phys_addr -= addr;
85546- pmd = pmd_alloc(&init_mm, pud, addr);
85547+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
85548 if (!pmd)
85549 return -ENOMEM;
85550 do {
85551@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
85552 unsigned long next;
85553
85554 phys_addr -= addr;
85555- pud = pud_alloc(&init_mm, pgd, addr);
85556+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
85557 if (!pud)
85558 return -ENOMEM;
85559 do {
85560diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
85561index bd2bea9..6b3c95e 100644
85562--- a/lib/is_single_threaded.c
85563+++ b/lib/is_single_threaded.c
85564@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
85565 struct task_struct *p, *t;
85566 bool ret;
85567
85568+ if (!mm)
85569+ return true;
85570+
85571 if (atomic_read(&task->signal->live) != 1)
85572 return false;
85573
85574diff --git a/lib/kobject.c b/lib/kobject.c
85575index 4a1f33d..2f3ca75 100644
85576--- a/lib/kobject.c
85577+++ b/lib/kobject.c
85578@@ -859,9 +859,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
85579
85580
85581 static DEFINE_SPINLOCK(kobj_ns_type_lock);
85582-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
85583+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
85584
85585-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
85586+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
85587 {
85588 enum kobj_ns_type type = ops->type;
85589 int error;
85590diff --git a/lib/list_debug.c b/lib/list_debug.c
85591index c24c2f7..06e070b 100644
85592--- a/lib/list_debug.c
85593+++ b/lib/list_debug.c
85594@@ -11,7 +11,9 @@
85595 #include <linux/bug.h>
85596 #include <linux/kernel.h>
85597 #include <linux/rculist.h>
85598+#include <linux/mm.h>
85599
85600+#ifdef CONFIG_DEBUG_LIST
85601 /*
85602 * Insert a new entry between two known consecutive entries.
85603 *
85604@@ -19,21 +21,32 @@
85605 * the prev/next entries already!
85606 */
85607
85608-void __list_add(struct list_head *new,
85609- struct list_head *prev,
85610- struct list_head *next)
85611+static bool __list_add_debug(struct list_head *new,
85612+ struct list_head *prev,
85613+ struct list_head *next)
85614 {
85615- WARN(next->prev != prev,
85616+ if (WARN(next->prev != prev,
85617 "list_add corruption. next->prev should be "
85618 "prev (%p), but was %p. (next=%p).\n",
85619- prev, next->prev, next);
85620- WARN(prev->next != next,
85621+ prev, next->prev, next) ||
85622+ WARN(prev->next != next,
85623 "list_add corruption. prev->next should be "
85624 "next (%p), but was %p. (prev=%p).\n",
85625- next, prev->next, prev);
85626- WARN(new == prev || new == next,
85627- "list_add double add: new=%p, prev=%p, next=%p.\n",
85628- new, prev, next);
85629+ next, prev->next, prev) ||
85630+ WARN(new == prev || new == next,
85631+ "list_add double add: new=%p, prev=%p, next=%p.\n",
85632+ new, prev, next))
85633+ return false;
85634+ return true;
85635+}
85636+
85637+void __list_add(struct list_head *new,
85638+ struct list_head *prev,
85639+ struct list_head *next)
85640+{
85641+ if (!__list_add_debug(new, prev, next))
85642+ return;
85643+
85644 next->prev = new;
85645 new->next = next;
85646 new->prev = prev;
85647@@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
85648 }
85649 EXPORT_SYMBOL(__list_add);
85650
85651-void __list_del_entry(struct list_head *entry)
85652+static bool __list_del_entry_debug(struct list_head *entry)
85653 {
85654 struct list_head *prev, *next;
85655
85656@@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
85657 WARN(next->prev != entry,
85658 "list_del corruption. next->prev should be %p, "
85659 "but was %p\n", entry, next->prev))
85660+ return false;
85661+ return true;
85662+}
85663+
85664+void __list_del_entry(struct list_head *entry)
85665+{
85666+ if (!__list_del_entry_debug(entry))
85667 return;
85668
85669- __list_del(prev, next);
85670+ __list_del(entry->prev, entry->next);
85671 }
85672 EXPORT_SYMBOL(__list_del_entry);
85673
85674@@ -86,15 +106,85 @@ EXPORT_SYMBOL(list_del);
85675 void __list_add_rcu(struct list_head *new,
85676 struct list_head *prev, struct list_head *next)
85677 {
85678- WARN(next->prev != prev,
85679- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
85680- prev, next->prev, next);
85681- WARN(prev->next != next,
85682- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
85683- next, prev->next, prev);
85684+ if (!__list_add_debug(new, prev, next))
85685+ return;
85686+
85687 new->next = next;
85688 new->prev = prev;
85689 rcu_assign_pointer(list_next_rcu(prev), new);
85690 next->prev = new;
85691 }
85692 EXPORT_SYMBOL(__list_add_rcu);
85693+#endif
85694+
85695+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
85696+{
85697+#ifdef CONFIG_DEBUG_LIST
85698+ if (!__list_add_debug(new, prev, next))
85699+ return;
85700+#endif
85701+
85702+ pax_open_kernel();
85703+ next->prev = new;
85704+ new->next = next;
85705+ new->prev = prev;
85706+ prev->next = new;
85707+ pax_close_kernel();
85708+}
85709+EXPORT_SYMBOL(__pax_list_add);
85710+
85711+void pax_list_del(struct list_head *entry)
85712+{
85713+#ifdef CONFIG_DEBUG_LIST
85714+ if (!__list_del_entry_debug(entry))
85715+ return;
85716+#endif
85717+
85718+ pax_open_kernel();
85719+ __list_del(entry->prev, entry->next);
85720+ entry->next = LIST_POISON1;
85721+ entry->prev = LIST_POISON2;
85722+ pax_close_kernel();
85723+}
85724+EXPORT_SYMBOL(pax_list_del);
85725+
85726+void pax_list_del_init(struct list_head *entry)
85727+{
85728+ pax_open_kernel();
85729+ __list_del(entry->prev, entry->next);
85730+ INIT_LIST_HEAD(entry);
85731+ pax_close_kernel();
85732+}
85733+EXPORT_SYMBOL(pax_list_del_init);
85734+
85735+void __pax_list_add_rcu(struct list_head *new,
85736+ struct list_head *prev, struct list_head *next)
85737+{
85738+#ifdef CONFIG_DEBUG_LIST
85739+ if (!__list_add_debug(new, prev, next))
85740+ return;
85741+#endif
85742+
85743+ pax_open_kernel();
85744+ new->next = next;
85745+ new->prev = prev;
85746+ rcu_assign_pointer(list_next_rcu(prev), new);
85747+ next->prev = new;
85748+ pax_close_kernel();
85749+}
85750+EXPORT_SYMBOL(__pax_list_add_rcu);
85751+
85752+void pax_list_del_rcu(struct list_head *entry)
85753+{
85754+#ifdef CONFIG_DEBUG_LIST
85755+ if (!__list_del_entry_debug(entry))
85756+ return;
85757+#endif
85758+
85759+ pax_open_kernel();
85760+ __list_del(entry->prev, entry->next);
85761+ entry->next = LIST_POISON1;
85762+ entry->prev = LIST_POISON2;
85763+ pax_close_kernel();
85764+}
85765+EXPORT_SYMBOL(pax_list_del_rcu);
85766diff --git a/lib/radix-tree.c b/lib/radix-tree.c
85767index e796429..6e38f9f 100644
85768--- a/lib/radix-tree.c
85769+++ b/lib/radix-tree.c
85770@@ -92,7 +92,7 @@ struct radix_tree_preload {
85771 int nr;
85772 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
85773 };
85774-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
85775+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
85776
85777 static inline void *ptr_to_indirect(void *ptr)
85778 {
85779diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
85780index bb2b201..46abaf9 100644
85781--- a/lib/strncpy_from_user.c
85782+++ b/lib/strncpy_from_user.c
85783@@ -21,7 +21,7 @@
85784 */
85785 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
85786 {
85787- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
85788+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
85789 long res = 0;
85790
85791 /*
85792diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
85793index a28df52..3d55877 100644
85794--- a/lib/strnlen_user.c
85795+++ b/lib/strnlen_user.c
85796@@ -26,7 +26,7 @@
85797 */
85798 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
85799 {
85800- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
85801+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
85802 long align, res = 0;
85803 unsigned long c;
85804
85805diff --git a/lib/swiotlb.c b/lib/swiotlb.c
85806index d23762e..e21eab2 100644
85807--- a/lib/swiotlb.c
85808+++ b/lib/swiotlb.c
85809@@ -664,7 +664,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
85810
85811 void
85812 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
85813- dma_addr_t dev_addr)
85814+ dma_addr_t dev_addr, struct dma_attrs *attrs)
85815 {
85816 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
85817
85818diff --git a/lib/usercopy.c b/lib/usercopy.c
85819index 4f5b1dd..7cab418 100644
85820--- a/lib/usercopy.c
85821+++ b/lib/usercopy.c
85822@@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
85823 WARN(1, "Buffer overflow detected!\n");
85824 }
85825 EXPORT_SYMBOL(copy_from_user_overflow);
85826+
85827+void copy_to_user_overflow(void)
85828+{
85829+ WARN(1, "Buffer overflow detected!\n");
85830+}
85831+EXPORT_SYMBOL(copy_to_user_overflow);
85832diff --git a/lib/vsprintf.c b/lib/vsprintf.c
85833index 739a363..aa668d7 100644
85834--- a/lib/vsprintf.c
85835+++ b/lib/vsprintf.c
85836@@ -16,6 +16,9 @@
85837 * - scnprintf and vscnprintf
85838 */
85839
85840+#ifdef CONFIG_GRKERNSEC_HIDESYM
85841+#define __INCLUDED_BY_HIDESYM 1
85842+#endif
85843 #include <stdarg.h>
85844 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
85845 #include <linux/types.h>
85846@@ -1078,7 +1081,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
85847 return number(buf, end, *(const netdev_features_t *)addr, spec);
85848 }
85849
85850+#ifdef CONFIG_GRKERNSEC_HIDESYM
85851+int kptr_restrict __read_mostly = 2;
85852+#else
85853 int kptr_restrict __read_mostly;
85854+#endif
85855
85856 /*
85857 * Show a '%p' thing. A kernel extension is that the '%p' is followed
85858@@ -1091,6 +1098,7 @@ int kptr_restrict __read_mostly;
85859 * - 'f' For simple symbolic function names without offset
85860 * - 'S' For symbolic direct pointers with offset
85861 * - 's' For symbolic direct pointers without offset
85862+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
85863 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
85864 * - 'B' For backtraced symbolic direct pointers with offset
85865 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
85866@@ -1155,12 +1163,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
85867
85868 if (!ptr && *fmt != 'K') {
85869 /*
85870- * Print (null) with the same width as a pointer so it makes
85871+ * Print (nil) with the same width as a pointer so it makes
85872 * tabular output look nice.
85873 */
85874 if (spec.field_width == -1)
85875 spec.field_width = default_width;
85876- return string(buf, end, "(null)", spec);
85877+ return string(buf, end, "(nil)", spec);
85878 }
85879
85880 switch (*fmt) {
85881@@ -1170,6 +1178,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
85882 /* Fallthrough */
85883 case 'S':
85884 case 's':
85885+#ifdef CONFIG_GRKERNSEC_HIDESYM
85886+ break;
85887+#else
85888+ return symbol_string(buf, end, ptr, spec, fmt);
85889+#endif
85890+ case 'A':
85891 case 'B':
85892 return symbol_string(buf, end, ptr, spec, fmt);
85893 case 'R':
85894@@ -1225,6 +1239,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
85895 va_end(va);
85896 return buf;
85897 }
85898+ case 'P':
85899+ break;
85900 case 'K':
85901 /*
85902 * %pK cannot be used in IRQ context because its test
85903@@ -1254,6 +1270,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
85904 return number(buf, end,
85905 (unsigned long long) *((phys_addr_t *)ptr), spec);
85906 }
85907+
85908+#ifdef CONFIG_GRKERNSEC_HIDESYM
85909+ /* 'P' = approved pointers to copy to userland,
85910+ as in the /proc/kallsyms case, as we make it display nothing
85911+ for non-root users, and the real contents for root users
85912+ Also ignore 'K' pointers, since we force their NULLing for non-root users
85913+ above
85914+ */
85915+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
85916+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
85917+ dump_stack();
85918+ ptr = NULL;
85919+ }
85920+#endif
85921+
85922 spec.flags |= SMALL;
85923 if (spec.field_width == -1) {
85924 spec.field_width = default_width;
85925@@ -1977,11 +2008,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
85926 typeof(type) value; \
85927 if (sizeof(type) == 8) { \
85928 args = PTR_ALIGN(args, sizeof(u32)); \
85929- *(u32 *)&value = *(u32 *)args; \
85930- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
85931+ *(u32 *)&value = *(const u32 *)args; \
85932+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
85933 } else { \
85934 args = PTR_ALIGN(args, sizeof(type)); \
85935- value = *(typeof(type) *)args; \
85936+ value = *(const typeof(type) *)args; \
85937 } \
85938 args += sizeof(type); \
85939 value; \
85940@@ -2044,7 +2075,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
85941 case FORMAT_TYPE_STR: {
85942 const char *str_arg = args;
85943 args += strlen(str_arg) + 1;
85944- str = string(str, end, (char *)str_arg, spec);
85945+ str = string(str, end, str_arg, spec);
85946 break;
85947 }
85948
85949diff --git a/localversion-grsec b/localversion-grsec
85950new file mode 100644
85951index 0000000..7cd6065
85952--- /dev/null
85953+++ b/localversion-grsec
85954@@ -0,0 +1 @@
85955+-grsec
85956diff --git a/mm/Kconfig b/mm/Kconfig
85957index 8028dcc..9a2dbe7 100644
85958--- a/mm/Kconfig
85959+++ b/mm/Kconfig
85960@@ -317,10 +317,10 @@ config KSM
85961 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
85962
85963 config DEFAULT_MMAP_MIN_ADDR
85964- int "Low address space to protect from user allocation"
85965+ int "Low address space to protect from user allocation"
85966 depends on MMU
85967- default 4096
85968- help
85969+ default 65536
85970+ help
85971 This is the portion of low virtual memory which should be protected
85972 from userspace allocation. Keeping a user from writing to low pages
85973 can help reduce the impact of kernel NULL pointer bugs.
85974@@ -351,7 +351,7 @@ config MEMORY_FAILURE
85975
85976 config HWPOISON_INJECT
85977 tristate "HWPoison pages injector"
85978- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
85979+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
85980 select PROC_PAGE_MONITOR
85981
85982 config NOMMU_INITIAL_TRIM_EXCESS
85983diff --git a/mm/backing-dev.c b/mm/backing-dev.c
85984index e04454c..ca5be3e 100644
85985--- a/mm/backing-dev.c
85986+++ b/mm/backing-dev.c
85987@@ -12,7 +12,7 @@
85988 #include <linux/device.h>
85989 #include <trace/events/writeback.h>
85990
85991-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
85992+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
85993
85994 struct backing_dev_info default_backing_dev_info = {
85995 .name = "default",
85996@@ -522,7 +522,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
85997 return err;
85998
85999 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
86000- atomic_long_inc_return(&bdi_seq));
86001+ atomic_long_inc_return_unchecked(&bdi_seq));
86002 if (err) {
86003 bdi_destroy(bdi);
86004 return err;
86005diff --git a/mm/filemap.c b/mm/filemap.c
86006index 4b51ac1..5aa90ff 100644
86007--- a/mm/filemap.c
86008+++ b/mm/filemap.c
86009@@ -1766,7 +1766,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
86010 struct address_space *mapping = file->f_mapping;
86011
86012 if (!mapping->a_ops->readpage)
86013- return -ENOEXEC;
86014+ return -ENODEV;
86015 file_accessed(file);
86016 vma->vm_ops = &generic_file_vm_ops;
86017 return 0;
86018@@ -1948,7 +1948,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
86019
86020 while (bytes) {
86021 char __user *buf = iov->iov_base + base;
86022- int copy = min(bytes, iov->iov_len - base);
86023+ size_t copy = min(bytes, iov->iov_len - base);
86024
86025 base = 0;
86026 left = __copy_from_user_inatomic(vaddr, buf, copy);
86027@@ -1977,7 +1977,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
86028 BUG_ON(!in_atomic());
86029 kaddr = kmap_atomic(page);
86030 if (likely(i->nr_segs == 1)) {
86031- int left;
86032+ size_t left;
86033 char __user *buf = i->iov->iov_base + i->iov_offset;
86034 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
86035 copied = bytes - left;
86036@@ -2005,7 +2005,7 @@ size_t iov_iter_copy_from_user(struct page *page,
86037
86038 kaddr = kmap(page);
86039 if (likely(i->nr_segs == 1)) {
86040- int left;
86041+ size_t left;
86042 char __user *buf = i->iov->iov_base + i->iov_offset;
86043 left = __copy_from_user(kaddr + offset, buf, bytes);
86044 copied = bytes - left;
86045@@ -2035,7 +2035,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
86046 * zero-length segments (without overruning the iovec).
86047 */
86048 while (bytes || unlikely(i->count && !iov->iov_len)) {
86049- int copy;
86050+ size_t copy;
86051
86052 copy = min(bytes, iov->iov_len - base);
86053 BUG_ON(!i->count || i->count < copy);
86054@@ -2106,6 +2106,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
86055 *pos = i_size_read(inode);
86056
86057 if (limit != RLIM_INFINITY) {
86058+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
86059 if (*pos >= limit) {
86060 send_sig(SIGXFSZ, current, 0);
86061 return -EFBIG;
86062diff --git a/mm/fremap.c b/mm/fremap.c
86063index 5bff081..d8189a9 100644
86064--- a/mm/fremap.c
86065+++ b/mm/fremap.c
86066@@ -163,6 +163,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
86067 retry:
86068 vma = find_vma(mm, start);
86069
86070+#ifdef CONFIG_PAX_SEGMEXEC
86071+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
86072+ goto out;
86073+#endif
86074+
86075 /*
86076 * Make sure the vma is shared, that it supports prefaulting,
86077 * and that the remapped range is valid and fully within
86078diff --git a/mm/highmem.c b/mm/highmem.c
86079index b32b70c..e512eb0 100644
86080--- a/mm/highmem.c
86081+++ b/mm/highmem.c
86082@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
86083 * So no dangers, even with speculative execution.
86084 */
86085 page = pte_page(pkmap_page_table[i]);
86086+ pax_open_kernel();
86087 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
86088-
86089+ pax_close_kernel();
86090 set_page_address(page, NULL);
86091 need_flush = 1;
86092 }
86093@@ -198,9 +199,11 @@ start:
86094 }
86095 }
86096 vaddr = PKMAP_ADDR(last_pkmap_nr);
86097+
86098+ pax_open_kernel();
86099 set_pte_at(&init_mm, vaddr,
86100 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
86101-
86102+ pax_close_kernel();
86103 pkmap_count[last_pkmap_nr] = 1;
86104 set_page_address(page, (void *)vaddr);
86105
86106diff --git a/mm/hugetlb.c b/mm/hugetlb.c
86107index b60f330..ee7de7e 100644
86108--- a/mm/hugetlb.c
86109+++ b/mm/hugetlb.c
86110@@ -2022,15 +2022,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
86111 struct hstate *h = &default_hstate;
86112 unsigned long tmp;
86113 int ret;
86114+ ctl_table_no_const hugetlb_table;
86115
86116 tmp = h->max_huge_pages;
86117
86118 if (write && h->order >= MAX_ORDER)
86119 return -EINVAL;
86120
86121- table->data = &tmp;
86122- table->maxlen = sizeof(unsigned long);
86123- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
86124+ hugetlb_table = *table;
86125+ hugetlb_table.data = &tmp;
86126+ hugetlb_table.maxlen = sizeof(unsigned long);
86127+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
86128 if (ret)
86129 goto out;
86130
86131@@ -2087,15 +2089,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
86132 struct hstate *h = &default_hstate;
86133 unsigned long tmp;
86134 int ret;
86135+ ctl_table_no_const hugetlb_table;
86136
86137 tmp = h->nr_overcommit_huge_pages;
86138
86139 if (write && h->order >= MAX_ORDER)
86140 return -EINVAL;
86141
86142- table->data = &tmp;
86143- table->maxlen = sizeof(unsigned long);
86144- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
86145+ hugetlb_table = *table;
86146+ hugetlb_table.data = &tmp;
86147+ hugetlb_table.maxlen = sizeof(unsigned long);
86148+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
86149 if (ret)
86150 goto out;
86151
86152@@ -2545,6 +2549,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
86153 return 1;
86154 }
86155
86156+#ifdef CONFIG_PAX_SEGMEXEC
86157+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
86158+{
86159+ struct mm_struct *mm = vma->vm_mm;
86160+ struct vm_area_struct *vma_m;
86161+ unsigned long address_m;
86162+ pte_t *ptep_m;
86163+
86164+ vma_m = pax_find_mirror_vma(vma);
86165+ if (!vma_m)
86166+ return;
86167+
86168+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
86169+ address_m = address + SEGMEXEC_TASK_SIZE;
86170+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
86171+ get_page(page_m);
86172+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
86173+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
86174+}
86175+#endif
86176+
86177 /*
86178 * Hugetlb_cow() should be called with page lock of the original hugepage held.
86179 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
86180@@ -2663,6 +2688,11 @@ retry_avoidcopy:
86181 make_huge_pte(vma, new_page, 1));
86182 page_remove_rmap(old_page);
86183 hugepage_add_new_anon_rmap(new_page, vma, address);
86184+
86185+#ifdef CONFIG_PAX_SEGMEXEC
86186+ pax_mirror_huge_pte(vma, address, new_page);
86187+#endif
86188+
86189 /* Make the old page be freed below */
86190 new_page = old_page;
86191 }
86192@@ -2821,6 +2851,10 @@ retry:
86193 && (vma->vm_flags & VM_SHARED)));
86194 set_huge_pte_at(mm, address, ptep, new_pte);
86195
86196+#ifdef CONFIG_PAX_SEGMEXEC
86197+ pax_mirror_huge_pte(vma, address, page);
86198+#endif
86199+
86200 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
86201 /* Optimization, do the COW without a second fault */
86202 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
86203@@ -2850,6 +2884,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86204 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
86205 struct hstate *h = hstate_vma(vma);
86206
86207+#ifdef CONFIG_PAX_SEGMEXEC
86208+ struct vm_area_struct *vma_m;
86209+#endif
86210+
86211 address &= huge_page_mask(h);
86212
86213 ptep = huge_pte_offset(mm, address);
86214@@ -2863,6 +2901,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86215 VM_FAULT_SET_HINDEX(hstate_index(h));
86216 }
86217
86218+#ifdef CONFIG_PAX_SEGMEXEC
86219+ vma_m = pax_find_mirror_vma(vma);
86220+ if (vma_m) {
86221+ unsigned long address_m;
86222+
86223+ if (vma->vm_start > vma_m->vm_start) {
86224+ address_m = address;
86225+ address -= SEGMEXEC_TASK_SIZE;
86226+ vma = vma_m;
86227+ h = hstate_vma(vma);
86228+ } else
86229+ address_m = address + SEGMEXEC_TASK_SIZE;
86230+
86231+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
86232+ return VM_FAULT_OOM;
86233+ address_m &= HPAGE_MASK;
86234+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
86235+ }
86236+#endif
86237+
86238 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
86239 if (!ptep)
86240 return VM_FAULT_OOM;
86241diff --git a/mm/internal.h b/mm/internal.h
86242index 4390ac6..fc60373c 100644
86243--- a/mm/internal.h
86244+++ b/mm/internal.h
86245@@ -95,6 +95,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
86246 * in mm/page_alloc.c
86247 */
86248 extern void __free_pages_bootmem(struct page *page, unsigned int order);
86249+extern void free_compound_page(struct page *page);
86250 extern void prep_compound_page(struct page *page, unsigned long order);
86251 #ifdef CONFIG_MEMORY_FAILURE
86252 extern bool is_free_buddy_page(struct page *page);
86253@@ -350,7 +351,7 @@ extern u32 hwpoison_filter_enable;
86254
86255 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
86256 unsigned long, unsigned long,
86257- unsigned long, unsigned long);
86258+ unsigned long, unsigned long) __intentional_overflow(-1);
86259
86260 extern void set_pageblock_order(void);
86261 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
86262diff --git a/mm/kmemleak.c b/mm/kmemleak.c
86263index c8d7f31..2dbeffd 100644
86264--- a/mm/kmemleak.c
86265+++ b/mm/kmemleak.c
86266@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
86267
86268 for (i = 0; i < object->trace_len; i++) {
86269 void *ptr = (void *)object->trace[i];
86270- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
86271+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
86272 }
86273 }
86274
86275@@ -1851,7 +1851,7 @@ static int __init kmemleak_late_init(void)
86276 return -ENOMEM;
86277 }
86278
86279- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
86280+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
86281 &kmemleak_fops);
86282 if (!dentry)
86283 pr_warning("Failed to create the debugfs kmemleak file\n");
86284diff --git a/mm/maccess.c b/mm/maccess.c
86285index d53adf9..03a24bf 100644
86286--- a/mm/maccess.c
86287+++ b/mm/maccess.c
86288@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
86289 set_fs(KERNEL_DS);
86290 pagefault_disable();
86291 ret = __copy_from_user_inatomic(dst,
86292- (__force const void __user *)src, size);
86293+ (const void __force_user *)src, size);
86294 pagefault_enable();
86295 set_fs(old_fs);
86296
86297@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
86298
86299 set_fs(KERNEL_DS);
86300 pagefault_disable();
86301- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
86302+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
86303 pagefault_enable();
86304 set_fs(old_fs);
86305
86306diff --git a/mm/madvise.c b/mm/madvise.c
86307index 7055883..aafb1ed 100644
86308--- a/mm/madvise.c
86309+++ b/mm/madvise.c
86310@@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
86311 pgoff_t pgoff;
86312 unsigned long new_flags = vma->vm_flags;
86313
86314+#ifdef CONFIG_PAX_SEGMEXEC
86315+ struct vm_area_struct *vma_m;
86316+#endif
86317+
86318 switch (behavior) {
86319 case MADV_NORMAL:
86320 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
86321@@ -126,6 +130,13 @@ success:
86322 /*
86323 * vm_flags is protected by the mmap_sem held in write mode.
86324 */
86325+
86326+#ifdef CONFIG_PAX_SEGMEXEC
86327+ vma_m = pax_find_mirror_vma(vma);
86328+ if (vma_m)
86329+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
86330+#endif
86331+
86332 vma->vm_flags = new_flags;
86333
86334 out:
86335@@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
86336 struct vm_area_struct ** prev,
86337 unsigned long start, unsigned long end)
86338 {
86339+
86340+#ifdef CONFIG_PAX_SEGMEXEC
86341+ struct vm_area_struct *vma_m;
86342+#endif
86343+
86344 *prev = vma;
86345 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
86346 return -EINVAL;
86347@@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
86348 zap_page_range(vma, start, end - start, &details);
86349 } else
86350 zap_page_range(vma, start, end - start, NULL);
86351+
86352+#ifdef CONFIG_PAX_SEGMEXEC
86353+ vma_m = pax_find_mirror_vma(vma);
86354+ if (vma_m) {
86355+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
86356+ struct zap_details details = {
86357+ .nonlinear_vma = vma_m,
86358+ .last_index = ULONG_MAX,
86359+ };
86360+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
86361+ } else
86362+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
86363+ }
86364+#endif
86365+
86366 return 0;
86367 }
86368
86369@@ -485,6 +516,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
86370 if (end < start)
86371 return error;
86372
86373+#ifdef CONFIG_PAX_SEGMEXEC
86374+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
86375+ if (end > SEGMEXEC_TASK_SIZE)
86376+ return error;
86377+ } else
86378+#endif
86379+
86380+ if (end > TASK_SIZE)
86381+ return error;
86382+
86383 error = 0;
86384 if (end == start)
86385 return error;
86386diff --git a/mm/memory-failure.c b/mm/memory-failure.c
86387index 2c13aa7..64cbc3f 100644
86388--- a/mm/memory-failure.c
86389+++ b/mm/memory-failure.c
86390@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
86391
86392 int sysctl_memory_failure_recovery __read_mostly = 1;
86393
86394-atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
86395+atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
86396
86397 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
86398
86399@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
86400 pfn, t->comm, t->pid);
86401 si.si_signo = SIGBUS;
86402 si.si_errno = 0;
86403- si.si_addr = (void *)addr;
86404+ si.si_addr = (void __user *)addr;
86405 #ifdef __ARCH_SI_TRAPNO
86406 si.si_trapno = trapno;
86407 #endif
86408@@ -760,7 +760,7 @@ static struct page_state {
86409 unsigned long res;
86410 char *msg;
86411 int (*action)(struct page *p, unsigned long pfn);
86412-} error_states[] = {
86413+} __do_const error_states[] = {
86414 { reserved, reserved, "reserved kernel", me_kernel },
86415 /*
86416 * free pages are specially detected outside this table:
86417@@ -1051,7 +1051,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
86418 nr_pages = 1 << compound_order(hpage);
86419 else /* normal page or thp */
86420 nr_pages = 1;
86421- atomic_long_add(nr_pages, &num_poisoned_pages);
86422+ atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
86423
86424 /*
86425 * We need/can do nothing about count=0 pages.
86426@@ -1081,7 +1081,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
86427 if (!PageHWPoison(hpage)
86428 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
86429 || (p != hpage && TestSetPageHWPoison(hpage))) {
86430- atomic_long_sub(nr_pages, &num_poisoned_pages);
86431+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
86432 return 0;
86433 }
86434 set_page_hwpoison_huge_page(hpage);
86435@@ -1148,7 +1148,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
86436 }
86437 if (hwpoison_filter(p)) {
86438 if (TestClearPageHWPoison(p))
86439- atomic_long_sub(nr_pages, &num_poisoned_pages);
86440+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
86441 unlock_page(hpage);
86442 put_page(hpage);
86443 return 0;
86444@@ -1350,7 +1350,7 @@ int unpoison_memory(unsigned long pfn)
86445 return 0;
86446 }
86447 if (TestClearPageHWPoison(p))
86448- atomic_long_sub(nr_pages, &num_poisoned_pages);
86449+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
86450 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
86451 return 0;
86452 }
86453@@ -1364,7 +1364,7 @@ int unpoison_memory(unsigned long pfn)
86454 */
86455 if (TestClearPageHWPoison(page)) {
86456 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
86457- atomic_long_sub(nr_pages, &num_poisoned_pages);
86458+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
86459 freeit = 1;
86460 if (PageHuge(page))
86461 clear_page_hwpoison_huge_page(page);
86462@@ -1491,7 +1491,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
86463 } else {
86464 set_page_hwpoison_huge_page(hpage);
86465 dequeue_hwpoisoned_huge_page(hpage);
86466- atomic_long_add(1 << compound_trans_order(hpage),
86467+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
86468 &num_poisoned_pages);
86469 }
86470 return ret;
86471@@ -1551,11 +1551,11 @@ int soft_offline_page(struct page *page, int flags)
86472 if (PageHuge(page)) {
86473 set_page_hwpoison_huge_page(hpage);
86474 dequeue_hwpoisoned_huge_page(hpage);
86475- atomic_long_add(1 << compound_trans_order(hpage),
86476+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
86477 &num_poisoned_pages);
86478 } else {
86479 SetPageHWPoison(page);
86480- atomic_long_inc(&num_poisoned_pages);
86481+ atomic_long_inc_unchecked(&num_poisoned_pages);
86482 }
86483 }
86484 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
86485@@ -1595,7 +1595,7 @@ static int __soft_offline_page(struct page *page, int flags)
86486 put_page(page);
86487 pr_info("soft_offline: %#lx: invalidated\n", pfn);
86488 SetPageHWPoison(page);
86489- atomic_long_inc(&num_poisoned_pages);
86490+ atomic_long_inc_unchecked(&num_poisoned_pages);
86491 return 0;
86492 }
86493
86494@@ -1640,7 +1640,7 @@ static int __soft_offline_page(struct page *page, int flags)
86495 if (!is_free_buddy_page(page))
86496 pr_info("soft offline: %#lx: page leaked\n",
86497 pfn);
86498- atomic_long_inc(&num_poisoned_pages);
86499+ atomic_long_inc_unchecked(&num_poisoned_pages);
86500 }
86501 } else {
86502 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
86503diff --git a/mm/memory.c b/mm/memory.c
86504index af84bc0..2ed0816 100644
86505--- a/mm/memory.c
86506+++ b/mm/memory.c
86507@@ -426,6 +426,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
86508 free_pte_range(tlb, pmd, addr);
86509 } while (pmd++, addr = next, addr != end);
86510
86511+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
86512 start &= PUD_MASK;
86513 if (start < floor)
86514 return;
86515@@ -440,6 +441,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
86516 pmd = pmd_offset(pud, start);
86517 pud_clear(pud);
86518 pmd_free_tlb(tlb, pmd, start);
86519+#endif
86520+
86521 }
86522
86523 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
86524@@ -459,6 +462,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
86525 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
86526 } while (pud++, addr = next, addr != end);
86527
86528+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
86529 start &= PGDIR_MASK;
86530 if (start < floor)
86531 return;
86532@@ -473,6 +477,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
86533 pud = pud_offset(pgd, start);
86534 pgd_clear(pgd);
86535 pud_free_tlb(tlb, pud, start);
86536+#endif
86537+
86538 }
86539
86540 /*
86541@@ -1645,12 +1651,6 @@ no_page_table:
86542 return page;
86543 }
86544
86545-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
86546-{
86547- return stack_guard_page_start(vma, addr) ||
86548- stack_guard_page_end(vma, addr+PAGE_SIZE);
86549-}
86550-
86551 /**
86552 * __get_user_pages() - pin user pages in memory
86553 * @tsk: task_struct of target task
86554@@ -1737,10 +1737,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
86555
86556 i = 0;
86557
86558- do {
86559+ while (nr_pages) {
86560 struct vm_area_struct *vma;
86561
86562- vma = find_extend_vma(mm, start);
86563+ vma = find_vma(mm, start);
86564 if (!vma && in_gate_area(mm, start)) {
86565 unsigned long pg = start & PAGE_MASK;
86566 pgd_t *pgd;
86567@@ -1789,7 +1789,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
86568 goto next_page;
86569 }
86570
86571- if (!vma ||
86572+ if (!vma || start < vma->vm_start ||
86573 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
86574 !(vm_flags & vma->vm_flags))
86575 return i ? : -EFAULT;
86576@@ -1818,11 +1818,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
86577 int ret;
86578 unsigned int fault_flags = 0;
86579
86580- /* For mlock, just skip the stack guard page. */
86581- if (foll_flags & FOLL_MLOCK) {
86582- if (stack_guard_page(vma, start))
86583- goto next_page;
86584- }
86585 if (foll_flags & FOLL_WRITE)
86586 fault_flags |= FAULT_FLAG_WRITE;
86587 if (nonblocking)
86588@@ -1902,7 +1897,7 @@ next_page:
86589 start += page_increm * PAGE_SIZE;
86590 nr_pages -= page_increm;
86591 } while (nr_pages && start < vma->vm_end);
86592- } while (nr_pages);
86593+ }
86594 return i;
86595 }
86596 EXPORT_SYMBOL(__get_user_pages);
86597@@ -2109,6 +2104,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
86598 page_add_file_rmap(page);
86599 set_pte_at(mm, addr, pte, mk_pte(page, prot));
86600
86601+#ifdef CONFIG_PAX_SEGMEXEC
86602+ pax_mirror_file_pte(vma, addr, page, ptl);
86603+#endif
86604+
86605 retval = 0;
86606 pte_unmap_unlock(pte, ptl);
86607 return retval;
86608@@ -2153,9 +2152,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
86609 if (!page_count(page))
86610 return -EINVAL;
86611 if (!(vma->vm_flags & VM_MIXEDMAP)) {
86612+
86613+#ifdef CONFIG_PAX_SEGMEXEC
86614+ struct vm_area_struct *vma_m;
86615+#endif
86616+
86617 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
86618 BUG_ON(vma->vm_flags & VM_PFNMAP);
86619 vma->vm_flags |= VM_MIXEDMAP;
86620+
86621+#ifdef CONFIG_PAX_SEGMEXEC
86622+ vma_m = pax_find_mirror_vma(vma);
86623+ if (vma_m)
86624+ vma_m->vm_flags |= VM_MIXEDMAP;
86625+#endif
86626+
86627 }
86628 return insert_page(vma, addr, page, vma->vm_page_prot);
86629 }
86630@@ -2238,6 +2249,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
86631 unsigned long pfn)
86632 {
86633 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
86634+ BUG_ON(vma->vm_mirror);
86635
86636 if (addr < vma->vm_start || addr >= vma->vm_end)
86637 return -EFAULT;
86638@@ -2485,7 +2497,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
86639
86640 BUG_ON(pud_huge(*pud));
86641
86642- pmd = pmd_alloc(mm, pud, addr);
86643+ pmd = (mm == &init_mm) ?
86644+ pmd_alloc_kernel(mm, pud, addr) :
86645+ pmd_alloc(mm, pud, addr);
86646 if (!pmd)
86647 return -ENOMEM;
86648 do {
86649@@ -2505,7 +2519,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
86650 unsigned long next;
86651 int err;
86652
86653- pud = pud_alloc(mm, pgd, addr);
86654+ pud = (mm == &init_mm) ?
86655+ pud_alloc_kernel(mm, pgd, addr) :
86656+ pud_alloc(mm, pgd, addr);
86657 if (!pud)
86658 return -ENOMEM;
86659 do {
86660@@ -2593,6 +2609,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
86661 copy_user_highpage(dst, src, va, vma);
86662 }
86663
86664+#ifdef CONFIG_PAX_SEGMEXEC
86665+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
86666+{
86667+ struct mm_struct *mm = vma->vm_mm;
86668+ spinlock_t *ptl;
86669+ pte_t *pte, entry;
86670+
86671+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
86672+ entry = *pte;
86673+ if (!pte_present(entry)) {
86674+ if (!pte_none(entry)) {
86675+ BUG_ON(pte_file(entry));
86676+ free_swap_and_cache(pte_to_swp_entry(entry));
86677+ pte_clear_not_present_full(mm, address, pte, 0);
86678+ }
86679+ } else {
86680+ struct page *page;
86681+
86682+ flush_cache_page(vma, address, pte_pfn(entry));
86683+ entry = ptep_clear_flush(vma, address, pte);
86684+ BUG_ON(pte_dirty(entry));
86685+ page = vm_normal_page(vma, address, entry);
86686+ if (page) {
86687+ update_hiwater_rss(mm);
86688+ if (PageAnon(page))
86689+ dec_mm_counter_fast(mm, MM_ANONPAGES);
86690+ else
86691+ dec_mm_counter_fast(mm, MM_FILEPAGES);
86692+ page_remove_rmap(page);
86693+ page_cache_release(page);
86694+ }
86695+ }
86696+ pte_unmap_unlock(pte, ptl);
86697+}
86698+
86699+/* PaX: if vma is mirrored, synchronize the mirror's PTE
86700+ *
86701+ * the ptl of the lower mapped page is held on entry and is not released on exit
86702+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
86703+ */
86704+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
86705+{
86706+ struct mm_struct *mm = vma->vm_mm;
86707+ unsigned long address_m;
86708+ spinlock_t *ptl_m;
86709+ struct vm_area_struct *vma_m;
86710+ pmd_t *pmd_m;
86711+ pte_t *pte_m, entry_m;
86712+
86713+ BUG_ON(!page_m || !PageAnon(page_m));
86714+
86715+ vma_m = pax_find_mirror_vma(vma);
86716+ if (!vma_m)
86717+ return;
86718+
86719+ BUG_ON(!PageLocked(page_m));
86720+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
86721+ address_m = address + SEGMEXEC_TASK_SIZE;
86722+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
86723+ pte_m = pte_offset_map(pmd_m, address_m);
86724+ ptl_m = pte_lockptr(mm, pmd_m);
86725+ if (ptl != ptl_m) {
86726+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
86727+ if (!pte_none(*pte_m))
86728+ goto out;
86729+ }
86730+
86731+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
86732+ page_cache_get(page_m);
86733+ page_add_anon_rmap(page_m, vma_m, address_m);
86734+ inc_mm_counter_fast(mm, MM_ANONPAGES);
86735+ set_pte_at(mm, address_m, pte_m, entry_m);
86736+ update_mmu_cache(vma_m, address_m, pte_m);
86737+out:
86738+ if (ptl != ptl_m)
86739+ spin_unlock(ptl_m);
86740+ pte_unmap(pte_m);
86741+ unlock_page(page_m);
86742+}
86743+
86744+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
86745+{
86746+ struct mm_struct *mm = vma->vm_mm;
86747+ unsigned long address_m;
86748+ spinlock_t *ptl_m;
86749+ struct vm_area_struct *vma_m;
86750+ pmd_t *pmd_m;
86751+ pte_t *pte_m, entry_m;
86752+
86753+ BUG_ON(!page_m || PageAnon(page_m));
86754+
86755+ vma_m = pax_find_mirror_vma(vma);
86756+ if (!vma_m)
86757+ return;
86758+
86759+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
86760+ address_m = address + SEGMEXEC_TASK_SIZE;
86761+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
86762+ pte_m = pte_offset_map(pmd_m, address_m);
86763+ ptl_m = pte_lockptr(mm, pmd_m);
86764+ if (ptl != ptl_m) {
86765+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
86766+ if (!pte_none(*pte_m))
86767+ goto out;
86768+ }
86769+
86770+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
86771+ page_cache_get(page_m);
86772+ page_add_file_rmap(page_m);
86773+ inc_mm_counter_fast(mm, MM_FILEPAGES);
86774+ set_pte_at(mm, address_m, pte_m, entry_m);
86775+ update_mmu_cache(vma_m, address_m, pte_m);
86776+out:
86777+ if (ptl != ptl_m)
86778+ spin_unlock(ptl_m);
86779+ pte_unmap(pte_m);
86780+}
86781+
86782+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
86783+{
86784+ struct mm_struct *mm = vma->vm_mm;
86785+ unsigned long address_m;
86786+ spinlock_t *ptl_m;
86787+ struct vm_area_struct *vma_m;
86788+ pmd_t *pmd_m;
86789+ pte_t *pte_m, entry_m;
86790+
86791+ vma_m = pax_find_mirror_vma(vma);
86792+ if (!vma_m)
86793+ return;
86794+
86795+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
86796+ address_m = address + SEGMEXEC_TASK_SIZE;
86797+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
86798+ pte_m = pte_offset_map(pmd_m, address_m);
86799+ ptl_m = pte_lockptr(mm, pmd_m);
86800+ if (ptl != ptl_m) {
86801+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
86802+ if (!pte_none(*pte_m))
86803+ goto out;
86804+ }
86805+
86806+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
86807+ set_pte_at(mm, address_m, pte_m, entry_m);
86808+out:
86809+ if (ptl != ptl_m)
86810+ spin_unlock(ptl_m);
86811+ pte_unmap(pte_m);
86812+}
86813+
86814+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
86815+{
86816+ struct page *page_m;
86817+ pte_t entry;
86818+
86819+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
86820+ goto out;
86821+
86822+ entry = *pte;
86823+ page_m = vm_normal_page(vma, address, entry);
86824+ if (!page_m)
86825+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
86826+ else if (PageAnon(page_m)) {
86827+ if (pax_find_mirror_vma(vma)) {
86828+ pte_unmap_unlock(pte, ptl);
86829+ lock_page(page_m);
86830+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
86831+ if (pte_same(entry, *pte))
86832+ pax_mirror_anon_pte(vma, address, page_m, ptl);
86833+ else
86834+ unlock_page(page_m);
86835+ }
86836+ } else
86837+ pax_mirror_file_pte(vma, address, page_m, ptl);
86838+
86839+out:
86840+ pte_unmap_unlock(pte, ptl);
86841+}
86842+#endif
86843+
86844 /*
86845 * This routine handles present pages, when users try to write
86846 * to a shared page. It is done by copying the page to a new address
86847@@ -2809,6 +3005,12 @@ gotten:
86848 */
86849 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
86850 if (likely(pte_same(*page_table, orig_pte))) {
86851+
86852+#ifdef CONFIG_PAX_SEGMEXEC
86853+ if (pax_find_mirror_vma(vma))
86854+ BUG_ON(!trylock_page(new_page));
86855+#endif
86856+
86857 if (old_page) {
86858 if (!PageAnon(old_page)) {
86859 dec_mm_counter_fast(mm, MM_FILEPAGES);
86860@@ -2860,6 +3062,10 @@ gotten:
86861 page_remove_rmap(old_page);
86862 }
86863
86864+#ifdef CONFIG_PAX_SEGMEXEC
86865+ pax_mirror_anon_pte(vma, address, new_page, ptl);
86866+#endif
86867+
86868 /* Free the old page.. */
86869 new_page = old_page;
86870 ret |= VM_FAULT_WRITE;
86871@@ -3137,6 +3343,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
86872 swap_free(entry);
86873 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
86874 try_to_free_swap(page);
86875+
86876+#ifdef CONFIG_PAX_SEGMEXEC
86877+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
86878+#endif
86879+
86880 unlock_page(page);
86881 if (page != swapcache) {
86882 /*
86883@@ -3160,6 +3371,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
86884
86885 /* No need to invalidate - it was non-present before */
86886 update_mmu_cache(vma, address, page_table);
86887+
86888+#ifdef CONFIG_PAX_SEGMEXEC
86889+ pax_mirror_anon_pte(vma, address, page, ptl);
86890+#endif
86891+
86892 unlock:
86893 pte_unmap_unlock(page_table, ptl);
86894 out:
86895@@ -3179,40 +3395,6 @@ out_release:
86896 }
86897
86898 /*
86899- * This is like a special single-page "expand_{down|up}wards()",
86900- * except we must first make sure that 'address{-|+}PAGE_SIZE'
86901- * doesn't hit another vma.
86902- */
86903-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
86904-{
86905- address &= PAGE_MASK;
86906- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
86907- struct vm_area_struct *prev = vma->vm_prev;
86908-
86909- /*
86910- * Is there a mapping abutting this one below?
86911- *
86912- * That's only ok if it's the same stack mapping
86913- * that has gotten split..
86914- */
86915- if (prev && prev->vm_end == address)
86916- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
86917-
86918- expand_downwards(vma, address - PAGE_SIZE);
86919- }
86920- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
86921- struct vm_area_struct *next = vma->vm_next;
86922-
86923- /* As VM_GROWSDOWN but s/below/above/ */
86924- if (next && next->vm_start == address + PAGE_SIZE)
86925- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
86926-
86927- expand_upwards(vma, address + PAGE_SIZE);
86928- }
86929- return 0;
86930-}
86931-
86932-/*
86933 * We enter with non-exclusive mmap_sem (to exclude vma changes,
86934 * but allow concurrent faults), and pte mapped but not yet locked.
86935 * We return with mmap_sem still held, but pte unmapped and unlocked.
86936@@ -3221,27 +3403,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
86937 unsigned long address, pte_t *page_table, pmd_t *pmd,
86938 unsigned int flags)
86939 {
86940- struct page *page;
86941+ struct page *page = NULL;
86942 spinlock_t *ptl;
86943 pte_t entry;
86944
86945- pte_unmap(page_table);
86946-
86947- /* Check if we need to add a guard page to the stack */
86948- if (check_stack_guard_page(vma, address) < 0)
86949- return VM_FAULT_SIGBUS;
86950-
86951- /* Use the zero-page for reads */
86952 if (!(flags & FAULT_FLAG_WRITE)) {
86953 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
86954 vma->vm_page_prot));
86955- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
86956+ ptl = pte_lockptr(mm, pmd);
86957+ spin_lock(ptl);
86958 if (!pte_none(*page_table))
86959 goto unlock;
86960 goto setpte;
86961 }
86962
86963 /* Allocate our own private page. */
86964+ pte_unmap(page_table);
86965+
86966 if (unlikely(anon_vma_prepare(vma)))
86967 goto oom;
86968 page = alloc_zeroed_user_highpage_movable(vma, address);
86969@@ -3265,6 +3443,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
86970 if (!pte_none(*page_table))
86971 goto release;
86972
86973+#ifdef CONFIG_PAX_SEGMEXEC
86974+ if (pax_find_mirror_vma(vma))
86975+ BUG_ON(!trylock_page(page));
86976+#endif
86977+
86978 inc_mm_counter_fast(mm, MM_ANONPAGES);
86979 page_add_new_anon_rmap(page, vma, address);
86980 setpte:
86981@@ -3272,6 +3455,12 @@ setpte:
86982
86983 /* No need to invalidate - it was non-present before */
86984 update_mmu_cache(vma, address, page_table);
86985+
86986+#ifdef CONFIG_PAX_SEGMEXEC
86987+ if (page)
86988+ pax_mirror_anon_pte(vma, address, page, ptl);
86989+#endif
86990+
86991 unlock:
86992 pte_unmap_unlock(page_table, ptl);
86993 return 0;
86994@@ -3415,6 +3604,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
86995 */
86996 /* Only go through if we didn't race with anybody else... */
86997 if (likely(pte_same(*page_table, orig_pte))) {
86998+
86999+#ifdef CONFIG_PAX_SEGMEXEC
87000+ if (anon && pax_find_mirror_vma(vma))
87001+ BUG_ON(!trylock_page(page));
87002+#endif
87003+
87004 flush_icache_page(vma, page);
87005 entry = mk_pte(page, vma->vm_page_prot);
87006 if (flags & FAULT_FLAG_WRITE)
87007@@ -3436,6 +3631,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
87008
87009 /* no need to invalidate: a not-present page won't be cached */
87010 update_mmu_cache(vma, address, page_table);
87011+
87012+#ifdef CONFIG_PAX_SEGMEXEC
87013+ if (anon)
87014+ pax_mirror_anon_pte(vma, address, page, ptl);
87015+ else
87016+ pax_mirror_file_pte(vma, address, page, ptl);
87017+#endif
87018+
87019 } else {
87020 if (cow_page)
87021 mem_cgroup_uncharge_page(cow_page);
87022@@ -3757,6 +3960,12 @@ int handle_pte_fault(struct mm_struct *mm,
87023 if (flags & FAULT_FLAG_WRITE)
87024 flush_tlb_fix_spurious_fault(vma, address);
87025 }
87026+
87027+#ifdef CONFIG_PAX_SEGMEXEC
87028+ pax_mirror_pte(vma, address, pte, pmd, ptl);
87029+ return 0;
87030+#endif
87031+
87032 unlock:
87033 pte_unmap_unlock(pte, ptl);
87034 return 0;
87035@@ -3773,6 +3982,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
87036 pmd_t *pmd;
87037 pte_t *pte;
87038
87039+#ifdef CONFIG_PAX_SEGMEXEC
87040+ struct vm_area_struct *vma_m;
87041+#endif
87042+
87043 __set_current_state(TASK_RUNNING);
87044
87045 count_vm_event(PGFAULT);
87046@@ -3784,6 +3997,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
87047 if (unlikely(is_vm_hugetlb_page(vma)))
87048 return hugetlb_fault(mm, vma, address, flags);
87049
87050+#ifdef CONFIG_PAX_SEGMEXEC
87051+ vma_m = pax_find_mirror_vma(vma);
87052+ if (vma_m) {
87053+ unsigned long address_m;
87054+ pgd_t *pgd_m;
87055+ pud_t *pud_m;
87056+ pmd_t *pmd_m;
87057+
87058+ if (vma->vm_start > vma_m->vm_start) {
87059+ address_m = address;
87060+ address -= SEGMEXEC_TASK_SIZE;
87061+ vma = vma_m;
87062+ } else
87063+ address_m = address + SEGMEXEC_TASK_SIZE;
87064+
87065+ pgd_m = pgd_offset(mm, address_m);
87066+ pud_m = pud_alloc(mm, pgd_m, address_m);
87067+ if (!pud_m)
87068+ return VM_FAULT_OOM;
87069+ pmd_m = pmd_alloc(mm, pud_m, address_m);
87070+ if (!pmd_m)
87071+ return VM_FAULT_OOM;
87072+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
87073+ return VM_FAULT_OOM;
87074+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
87075+ }
87076+#endif
87077+
87078 retry:
87079 pgd = pgd_offset(mm, address);
87080 pud = pud_alloc(mm, pgd, address);
87081@@ -3882,6 +4123,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
87082 spin_unlock(&mm->page_table_lock);
87083 return 0;
87084 }
87085+
87086+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
87087+{
87088+ pud_t *new = pud_alloc_one(mm, address);
87089+ if (!new)
87090+ return -ENOMEM;
87091+
87092+ smp_wmb(); /* See comment in __pte_alloc */
87093+
87094+ spin_lock(&mm->page_table_lock);
87095+ if (pgd_present(*pgd)) /* Another has populated it */
87096+ pud_free(mm, new);
87097+ else
87098+ pgd_populate_kernel(mm, pgd, new);
87099+ spin_unlock(&mm->page_table_lock);
87100+ return 0;
87101+}
87102 #endif /* __PAGETABLE_PUD_FOLDED */
87103
87104 #ifndef __PAGETABLE_PMD_FOLDED
87105@@ -3912,6 +4170,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
87106 spin_unlock(&mm->page_table_lock);
87107 return 0;
87108 }
87109+
87110+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
87111+{
87112+ pmd_t *new = pmd_alloc_one(mm, address);
87113+ if (!new)
87114+ return -ENOMEM;
87115+
87116+ smp_wmb(); /* See comment in __pte_alloc */
87117+
87118+ spin_lock(&mm->page_table_lock);
87119+#ifndef __ARCH_HAS_4LEVEL_HACK
87120+ if (pud_present(*pud)) /* Another has populated it */
87121+ pmd_free(mm, new);
87122+ else
87123+ pud_populate_kernel(mm, pud, new);
87124+#else
87125+ if (pgd_present(*pud)) /* Another has populated it */
87126+ pmd_free(mm, new);
87127+ else
87128+ pgd_populate_kernel(mm, pud, new);
87129+#endif /* __ARCH_HAS_4LEVEL_HACK */
87130+ spin_unlock(&mm->page_table_lock);
87131+ return 0;
87132+}
87133 #endif /* __PAGETABLE_PMD_FOLDED */
87134
87135 #if !defined(__HAVE_ARCH_GATE_AREA)
87136@@ -3925,7 +4207,7 @@ static int __init gate_vma_init(void)
87137 gate_vma.vm_start = FIXADDR_USER_START;
87138 gate_vma.vm_end = FIXADDR_USER_END;
87139 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
87140- gate_vma.vm_page_prot = __P101;
87141+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
87142
87143 return 0;
87144 }
87145@@ -4059,8 +4341,8 @@ out:
87146 return ret;
87147 }
87148
87149-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
87150- void *buf, int len, int write)
87151+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
87152+ void *buf, size_t len, int write)
87153 {
87154 resource_size_t phys_addr;
87155 unsigned long prot = 0;
87156@@ -4085,8 +4367,8 @@ int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
87157 * Access another process' address space as given in mm. If non-NULL, use the
87158 * given task for page fault accounting.
87159 */
87160-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
87161- unsigned long addr, void *buf, int len, int write)
87162+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
87163+ unsigned long addr, void *buf, size_t len, int write)
87164 {
87165 struct vm_area_struct *vma;
87166 void *old_buf = buf;
87167@@ -4094,7 +4376,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
87168 down_read(&mm->mmap_sem);
87169 /* ignore errors, just check how much was successfully transferred */
87170 while (len) {
87171- int bytes, ret, offset;
87172+ ssize_t bytes, ret, offset;
87173 void *maddr;
87174 struct page *page = NULL;
87175
87176@@ -4153,8 +4435,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
87177 *
87178 * The caller must hold a reference on @mm.
87179 */
87180-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
87181- void *buf, int len, int write)
87182+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
87183+ void *buf, size_t len, int write)
87184 {
87185 return __access_remote_vm(NULL, mm, addr, buf, len, write);
87186 }
87187@@ -4164,11 +4446,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
87188 * Source/target buffer must be kernel space,
87189 * Do not walk the page table directly, use get_user_pages
87190 */
87191-int access_process_vm(struct task_struct *tsk, unsigned long addr,
87192- void *buf, int len, int write)
87193+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
87194+ void *buf, size_t len, int write)
87195 {
87196 struct mm_struct *mm;
87197- int ret;
87198+ ssize_t ret;
87199
87200 mm = get_task_mm(tsk);
87201 if (!mm)
87202diff --git a/mm/mempolicy.c b/mm/mempolicy.c
87203index 4baf12e..5497066 100644
87204--- a/mm/mempolicy.c
87205+++ b/mm/mempolicy.c
87206@@ -708,6 +708,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
87207 unsigned long vmstart;
87208 unsigned long vmend;
87209
87210+#ifdef CONFIG_PAX_SEGMEXEC
87211+ struct vm_area_struct *vma_m;
87212+#endif
87213+
87214 vma = find_vma(mm, start);
87215 if (!vma || vma->vm_start > start)
87216 return -EFAULT;
87217@@ -751,6 +755,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
87218 err = vma_replace_policy(vma, new_pol);
87219 if (err)
87220 goto out;
87221+
87222+#ifdef CONFIG_PAX_SEGMEXEC
87223+ vma_m = pax_find_mirror_vma(vma);
87224+ if (vma_m) {
87225+ err = vma_replace_policy(vma_m, new_pol);
87226+ if (err)
87227+ goto out;
87228+ }
87229+#endif
87230+
87231 }
87232
87233 out:
87234@@ -1206,6 +1220,17 @@ static long do_mbind(unsigned long start, unsigned long len,
87235
87236 if (end < start)
87237 return -EINVAL;
87238+
87239+#ifdef CONFIG_PAX_SEGMEXEC
87240+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
87241+ if (end > SEGMEXEC_TASK_SIZE)
87242+ return -EINVAL;
87243+ } else
87244+#endif
87245+
87246+ if (end > TASK_SIZE)
87247+ return -EINVAL;
87248+
87249 if (end == start)
87250 return 0;
87251
87252@@ -1434,8 +1459,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
87253 */
87254 tcred = __task_cred(task);
87255 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
87256- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
87257- !capable(CAP_SYS_NICE)) {
87258+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
87259 rcu_read_unlock();
87260 err = -EPERM;
87261 goto out_put;
87262@@ -1466,6 +1490,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
87263 goto out;
87264 }
87265
87266+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
87267+ if (mm != current->mm &&
87268+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
87269+ mmput(mm);
87270+ err = -EPERM;
87271+ goto out;
87272+ }
87273+#endif
87274+
87275 err = do_migrate_pages(mm, old, new,
87276 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
87277
87278diff --git a/mm/migrate.c b/mm/migrate.c
87279index 6f0c244..6d1ae32 100644
87280--- a/mm/migrate.c
87281+++ b/mm/migrate.c
87282@@ -1399,8 +1399,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
87283 */
87284 tcred = __task_cred(task);
87285 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
87286- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
87287- !capable(CAP_SYS_NICE)) {
87288+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
87289 rcu_read_unlock();
87290 err = -EPERM;
87291 goto out;
87292diff --git a/mm/mlock.c b/mm/mlock.c
87293index 79b7cf7..9944291 100644
87294--- a/mm/mlock.c
87295+++ b/mm/mlock.c
87296@@ -13,6 +13,7 @@
87297 #include <linux/pagemap.h>
87298 #include <linux/mempolicy.h>
87299 #include <linux/syscalls.h>
87300+#include <linux/security.h>
87301 #include <linux/sched.h>
87302 #include <linux/export.h>
87303 #include <linux/rmap.h>
87304@@ -334,7 +335,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
87305 {
87306 unsigned long nstart, end, tmp;
87307 struct vm_area_struct * vma, * prev;
87308- int error;
87309+ int error = 0;
87310
87311 VM_BUG_ON(start & ~PAGE_MASK);
87312 VM_BUG_ON(len != PAGE_ALIGN(len));
87313@@ -343,6 +344,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
87314 return -EINVAL;
87315 if (end == start)
87316 return 0;
87317+ if (end > TASK_SIZE)
87318+ return -EINVAL;
87319+
87320 vma = find_vma(current->mm, start);
87321 if (!vma || vma->vm_start > start)
87322 return -ENOMEM;
87323@@ -354,6 +358,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
87324 for (nstart = start ; ; ) {
87325 vm_flags_t newflags;
87326
87327+#ifdef CONFIG_PAX_SEGMEXEC
87328+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
87329+ break;
87330+#endif
87331+
87332 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
87333
87334 newflags = vma->vm_flags & ~VM_LOCKED;
87335@@ -466,6 +475,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
87336 lock_limit >>= PAGE_SHIFT;
87337
87338 /* check against resource limits */
87339+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
87340 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
87341 error = do_mlock(start, len, 1);
87342 up_write(&current->mm->mmap_sem);
87343@@ -500,6 +510,11 @@ static int do_mlockall(int flags)
87344 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
87345 vm_flags_t newflags;
87346
87347+#ifdef CONFIG_PAX_SEGMEXEC
87348+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
87349+ break;
87350+#endif
87351+
87352 newflags = vma->vm_flags & ~VM_LOCKED;
87353 if (flags & MCL_CURRENT)
87354 newflags |= VM_LOCKED;
87355@@ -532,6 +547,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
87356 lock_limit >>= PAGE_SHIFT;
87357
87358 ret = -ENOMEM;
87359+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
87360 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
87361 capable(CAP_IPC_LOCK))
87362 ret = do_mlockall(flags);
87363diff --git a/mm/mmap.c b/mm/mmap.c
87364index f9c97d1..3468d3b 100644
87365--- a/mm/mmap.c
87366+++ b/mm/mmap.c
87367@@ -36,6 +36,7 @@
87368 #include <linux/sched/sysctl.h>
87369 #include <linux/notifier.h>
87370 #include <linux/memory.h>
87371+#include <linux/random.h>
87372
87373 #include <asm/uaccess.h>
87374 #include <asm/cacheflush.h>
87375@@ -52,6 +53,16 @@
87376 #define arch_rebalance_pgtables(addr, len) (addr)
87377 #endif
87378
87379+static inline void verify_mm_writelocked(struct mm_struct *mm)
87380+{
87381+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
87382+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
87383+ up_read(&mm->mmap_sem);
87384+ BUG();
87385+ }
87386+#endif
87387+}
87388+
87389 static void unmap_region(struct mm_struct *mm,
87390 struct vm_area_struct *vma, struct vm_area_struct *prev,
87391 unsigned long start, unsigned long end);
87392@@ -71,16 +82,25 @@ static void unmap_region(struct mm_struct *mm,
87393 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
87394 *
87395 */
87396-pgprot_t protection_map[16] = {
87397+pgprot_t protection_map[16] __read_only = {
87398 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
87399 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
87400 };
87401
87402-pgprot_t vm_get_page_prot(unsigned long vm_flags)
87403+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
87404 {
87405- return __pgprot(pgprot_val(protection_map[vm_flags &
87406+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
87407 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
87408 pgprot_val(arch_vm_get_page_prot(vm_flags)));
87409+
87410+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
87411+ if (!(__supported_pte_mask & _PAGE_NX) &&
87412+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
87413+ (vm_flags & (VM_READ | VM_WRITE)))
87414+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
87415+#endif
87416+
87417+ return prot;
87418 }
87419 EXPORT_SYMBOL(vm_get_page_prot);
87420
87421@@ -89,6 +109,7 @@ int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
87422 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
87423 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
87424 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
87425+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
87426 /*
87427 * Make sure vm_committed_as in one cacheline and not cacheline shared with
87428 * other variables. It can be updated by several CPUs frequently.
87429@@ -247,6 +268,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
87430 struct vm_area_struct *next = vma->vm_next;
87431
87432 might_sleep();
87433+ BUG_ON(vma->vm_mirror);
87434 if (vma->vm_ops && vma->vm_ops->close)
87435 vma->vm_ops->close(vma);
87436 if (vma->vm_file)
87437@@ -291,6 +313,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
87438 * not page aligned -Ram Gupta
87439 */
87440 rlim = rlimit(RLIMIT_DATA);
87441+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
87442 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
87443 (mm->end_data - mm->start_data) > rlim)
87444 goto out;
87445@@ -933,6 +956,12 @@ static int
87446 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
87447 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
87448 {
87449+
87450+#ifdef CONFIG_PAX_SEGMEXEC
87451+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
87452+ return 0;
87453+#endif
87454+
87455 if (is_mergeable_vma(vma, file, vm_flags) &&
87456 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
87457 if (vma->vm_pgoff == vm_pgoff)
87458@@ -952,6 +981,12 @@ static int
87459 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
87460 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
87461 {
87462+
87463+#ifdef CONFIG_PAX_SEGMEXEC
87464+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
87465+ return 0;
87466+#endif
87467+
87468 if (is_mergeable_vma(vma, file, vm_flags) &&
87469 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
87470 pgoff_t vm_pglen;
87471@@ -994,13 +1029,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
87472 struct vm_area_struct *vma_merge(struct mm_struct *mm,
87473 struct vm_area_struct *prev, unsigned long addr,
87474 unsigned long end, unsigned long vm_flags,
87475- struct anon_vma *anon_vma, struct file *file,
87476+ struct anon_vma *anon_vma, struct file *file,
87477 pgoff_t pgoff, struct mempolicy *policy)
87478 {
87479 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
87480 struct vm_area_struct *area, *next;
87481 int err;
87482
87483+#ifdef CONFIG_PAX_SEGMEXEC
87484+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
87485+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
87486+
87487+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
87488+#endif
87489+
87490 /*
87491 * We later require that vma->vm_flags == vm_flags,
87492 * so this tests vma->vm_flags & VM_SPECIAL, too.
87493@@ -1016,6 +1058,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
87494 if (next && next->vm_end == end) /* cases 6, 7, 8 */
87495 next = next->vm_next;
87496
87497+#ifdef CONFIG_PAX_SEGMEXEC
87498+ if (prev)
87499+ prev_m = pax_find_mirror_vma(prev);
87500+ if (area)
87501+ area_m = pax_find_mirror_vma(area);
87502+ if (next)
87503+ next_m = pax_find_mirror_vma(next);
87504+#endif
87505+
87506 /*
87507 * Can it merge with the predecessor?
87508 */
87509@@ -1035,9 +1086,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
87510 /* cases 1, 6 */
87511 err = vma_adjust(prev, prev->vm_start,
87512 next->vm_end, prev->vm_pgoff, NULL);
87513- } else /* cases 2, 5, 7 */
87514+
87515+#ifdef CONFIG_PAX_SEGMEXEC
87516+ if (!err && prev_m)
87517+ err = vma_adjust(prev_m, prev_m->vm_start,
87518+ next_m->vm_end, prev_m->vm_pgoff, NULL);
87519+#endif
87520+
87521+ } else { /* cases 2, 5, 7 */
87522 err = vma_adjust(prev, prev->vm_start,
87523 end, prev->vm_pgoff, NULL);
87524+
87525+#ifdef CONFIG_PAX_SEGMEXEC
87526+ if (!err && prev_m)
87527+ err = vma_adjust(prev_m, prev_m->vm_start,
87528+ end_m, prev_m->vm_pgoff, NULL);
87529+#endif
87530+
87531+ }
87532 if (err)
87533 return NULL;
87534 khugepaged_enter_vma_merge(prev);
87535@@ -1051,12 +1117,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
87536 mpol_equal(policy, vma_policy(next)) &&
87537 can_vma_merge_before(next, vm_flags,
87538 anon_vma, file, pgoff+pglen)) {
87539- if (prev && addr < prev->vm_end) /* case 4 */
87540+ if (prev && addr < prev->vm_end) { /* case 4 */
87541 err = vma_adjust(prev, prev->vm_start,
87542 addr, prev->vm_pgoff, NULL);
87543- else /* cases 3, 8 */
87544+
87545+#ifdef CONFIG_PAX_SEGMEXEC
87546+ if (!err && prev_m)
87547+ err = vma_adjust(prev_m, prev_m->vm_start,
87548+ addr_m, prev_m->vm_pgoff, NULL);
87549+#endif
87550+
87551+ } else { /* cases 3, 8 */
87552 err = vma_adjust(area, addr, next->vm_end,
87553 next->vm_pgoff - pglen, NULL);
87554+
87555+#ifdef CONFIG_PAX_SEGMEXEC
87556+ if (!err && area_m)
87557+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
87558+ next_m->vm_pgoff - pglen, NULL);
87559+#endif
87560+
87561+ }
87562 if (err)
87563 return NULL;
87564 khugepaged_enter_vma_merge(area);
87565@@ -1165,8 +1246,10 @@ none:
87566 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
87567 struct file *file, long pages)
87568 {
87569- const unsigned long stack_flags
87570- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
87571+
87572+#ifdef CONFIG_PAX_RANDMMAP
87573+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
87574+#endif
87575
87576 mm->total_vm += pages;
87577
87578@@ -1174,7 +1257,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
87579 mm->shared_vm += pages;
87580 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
87581 mm->exec_vm += pages;
87582- } else if (flags & stack_flags)
87583+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
87584 mm->stack_vm += pages;
87585 }
87586 #endif /* CONFIG_PROC_FS */
87587@@ -1213,7 +1296,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87588 * (the exception is when the underlying filesystem is noexec
87589 * mounted, in which case we dont add PROT_EXEC.)
87590 */
87591- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
87592+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
87593 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
87594 prot |= PROT_EXEC;
87595
87596@@ -1239,7 +1322,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87597 /* Obtain the address to map to. we verify (or select) it and ensure
87598 * that it represents a valid section of the address space.
87599 */
87600- addr = get_unmapped_area(file, addr, len, pgoff, flags);
87601+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
87602 if (addr & ~PAGE_MASK)
87603 return addr;
87604
87605@@ -1250,6 +1333,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87606 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
87607 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
87608
87609+#ifdef CONFIG_PAX_MPROTECT
87610+ if (mm->pax_flags & MF_PAX_MPROTECT) {
87611+
87612+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
87613+ if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
87614+ mm->binfmt->handle_mmap)
87615+ mm->binfmt->handle_mmap(file);
87616+#endif
87617+
87618+#ifndef CONFIG_PAX_MPROTECT_COMPAT
87619+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
87620+ gr_log_rwxmmap(file);
87621+
87622+#ifdef CONFIG_PAX_EMUPLT
87623+ vm_flags &= ~VM_EXEC;
87624+#else
87625+ return -EPERM;
87626+#endif
87627+
87628+ }
87629+
87630+ if (!(vm_flags & VM_EXEC))
87631+ vm_flags &= ~VM_MAYEXEC;
87632+#else
87633+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
87634+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
87635+#endif
87636+ else
87637+ vm_flags &= ~VM_MAYWRITE;
87638+ }
87639+#endif
87640+
87641+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
87642+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
87643+ vm_flags &= ~VM_PAGEEXEC;
87644+#endif
87645+
87646 if (flags & MAP_LOCKED)
87647 if (!can_do_mlock())
87648 return -EPERM;
87649@@ -1261,6 +1381,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87650 locked += mm->locked_vm;
87651 lock_limit = rlimit(RLIMIT_MEMLOCK);
87652 lock_limit >>= PAGE_SHIFT;
87653+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
87654 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
87655 return -EAGAIN;
87656 }
87657@@ -1341,6 +1462,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
87658 vm_flags |= VM_NORESERVE;
87659 }
87660
87661+ if (!gr_acl_handle_mmap(file, prot))
87662+ return -EACCES;
87663+
87664 addr = mmap_region(file, addr, len, vm_flags, pgoff);
87665 if (!IS_ERR_VALUE(addr) &&
87666 ((vm_flags & VM_LOCKED) ||
87667@@ -1434,7 +1558,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
87668 vm_flags_t vm_flags = vma->vm_flags;
87669
87670 /* If it was private or non-writable, the write bit is already clear */
87671- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
87672+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
87673 return 0;
87674
87675 /* The backer wishes to know when pages are first written to? */
87676@@ -1482,7 +1606,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
87677 unsigned long charged = 0;
87678 struct inode *inode = file ? file_inode(file) : NULL;
87679
87680+#ifdef CONFIG_PAX_SEGMEXEC
87681+ struct vm_area_struct *vma_m = NULL;
87682+#endif
87683+
87684+ /*
87685+ * mm->mmap_sem is required to protect against another thread
87686+ * changing the mappings in case we sleep.
87687+ */
87688+ verify_mm_writelocked(mm);
87689+
87690 /* Check against address space limit. */
87691+
87692+#ifdef CONFIG_PAX_RANDMMAP
87693+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
87694+#endif
87695+
87696 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
87697 unsigned long nr_pages;
87698
87699@@ -1501,11 +1640,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
87700
87701 /* Clear old maps */
87702 error = -ENOMEM;
87703-munmap_back:
87704 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
87705 if (do_munmap(mm, addr, len))
87706 return -ENOMEM;
87707- goto munmap_back;
87708+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
87709 }
87710
87711 /*
87712@@ -1536,6 +1674,16 @@ munmap_back:
87713 goto unacct_error;
87714 }
87715
87716+#ifdef CONFIG_PAX_SEGMEXEC
87717+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
87718+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
87719+ if (!vma_m) {
87720+ error = -ENOMEM;
87721+ goto free_vma;
87722+ }
87723+ }
87724+#endif
87725+
87726 vma->vm_mm = mm;
87727 vma->vm_start = addr;
87728 vma->vm_end = addr + len;
87729@@ -1560,6 +1708,13 @@ munmap_back:
87730 if (error)
87731 goto unmap_and_free_vma;
87732
87733+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
87734+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
87735+ vma->vm_flags |= VM_PAGEEXEC;
87736+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
87737+ }
87738+#endif
87739+
87740 /* Can addr have changed??
87741 *
87742 * Answer: Yes, several device drivers can do it in their
87743@@ -1598,6 +1753,11 @@ munmap_back:
87744 vma_link(mm, vma, prev, rb_link, rb_parent);
87745 file = vma->vm_file;
87746
87747+#ifdef CONFIG_PAX_SEGMEXEC
87748+ if (vma_m)
87749+ BUG_ON(pax_mirror_vma(vma_m, vma));
87750+#endif
87751+
87752 /* Once vma denies write, undo our temporary denial count */
87753 if (correct_wcount)
87754 atomic_inc(&inode->i_writecount);
87755@@ -1605,6 +1765,7 @@ out:
87756 perf_event_mmap(vma);
87757
87758 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
87759+ track_exec_limit(mm, addr, addr + len, vm_flags);
87760 if (vm_flags & VM_LOCKED) {
87761 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
87762 vma == get_gate_vma(current->mm)))
87763@@ -1628,6 +1789,12 @@ unmap_and_free_vma:
87764 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
87765 charged = 0;
87766 free_vma:
87767+
87768+#ifdef CONFIG_PAX_SEGMEXEC
87769+ if (vma_m)
87770+ kmem_cache_free(vm_area_cachep, vma_m);
87771+#endif
87772+
87773 kmem_cache_free(vm_area_cachep, vma);
87774 unacct_error:
87775 if (charged)
87776@@ -1635,7 +1802,63 @@ unacct_error:
87777 return error;
87778 }
87779
87780-unsigned long unmapped_area(struct vm_unmapped_area_info *info)
87781+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
87782+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
87783+{
87784+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
87785+ return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
87786+
87787+ return 0;
87788+}
87789+#endif
87790+
87791+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
87792+{
87793+ if (!vma) {
87794+#ifdef CONFIG_STACK_GROWSUP
87795+ if (addr > sysctl_heap_stack_gap)
87796+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
87797+ else
87798+ vma = find_vma(current->mm, 0);
87799+ if (vma && (vma->vm_flags & VM_GROWSUP))
87800+ return false;
87801+#endif
87802+ return true;
87803+ }
87804+
87805+ if (addr + len > vma->vm_start)
87806+ return false;
87807+
87808+ if (vma->vm_flags & VM_GROWSDOWN)
87809+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
87810+#ifdef CONFIG_STACK_GROWSUP
87811+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
87812+ return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
87813+#endif
87814+ else if (offset)
87815+ return offset <= vma->vm_start - addr - len;
87816+
87817+ return true;
87818+}
87819+
87820+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
87821+{
87822+ if (vma->vm_start < len)
87823+ return -ENOMEM;
87824+
87825+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
87826+ if (offset <= vma->vm_start - len)
87827+ return vma->vm_start - len - offset;
87828+ else
87829+ return -ENOMEM;
87830+ }
87831+
87832+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
87833+ return vma->vm_start - len - sysctl_heap_stack_gap;
87834+ return -ENOMEM;
87835+}
87836+
87837+unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
87838 {
87839 /*
87840 * We implement the search by looking for an rbtree node that
87841@@ -1683,11 +1906,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
87842 }
87843 }
87844
87845- gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
87846+ gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
87847 check_current:
87848 /* Check if current node has a suitable gap */
87849 if (gap_start > high_limit)
87850 return -ENOMEM;
87851+
87852+ if (gap_end - gap_start > info->threadstack_offset)
87853+ gap_start += info->threadstack_offset;
87854+ else
87855+ gap_start = gap_end;
87856+
87857+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
87858+ if (gap_end - gap_start > sysctl_heap_stack_gap)
87859+ gap_start += sysctl_heap_stack_gap;
87860+ else
87861+ gap_start = gap_end;
87862+ }
87863+ if (vma->vm_flags & VM_GROWSDOWN) {
87864+ if (gap_end - gap_start > sysctl_heap_stack_gap)
87865+ gap_end -= sysctl_heap_stack_gap;
87866+ else
87867+ gap_end = gap_start;
87868+ }
87869 if (gap_end >= low_limit && gap_end - gap_start >= length)
87870 goto found;
87871
87872@@ -1737,7 +1978,7 @@ found:
87873 return gap_start;
87874 }
87875
87876-unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
87877+unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
87878 {
87879 struct mm_struct *mm = current->mm;
87880 struct vm_area_struct *vma;
87881@@ -1791,6 +2032,24 @@ check_current:
87882 gap_end = vma->vm_start;
87883 if (gap_end < low_limit)
87884 return -ENOMEM;
87885+
87886+ if (gap_end - gap_start > info->threadstack_offset)
87887+ gap_end -= info->threadstack_offset;
87888+ else
87889+ gap_end = gap_start;
87890+
87891+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
87892+ if (gap_end - gap_start > sysctl_heap_stack_gap)
87893+ gap_start += sysctl_heap_stack_gap;
87894+ else
87895+ gap_start = gap_end;
87896+ }
87897+ if (vma->vm_flags & VM_GROWSDOWN) {
87898+ if (gap_end - gap_start > sysctl_heap_stack_gap)
87899+ gap_end -= sysctl_heap_stack_gap;
87900+ else
87901+ gap_end = gap_start;
87902+ }
87903 if (gap_start <= high_limit && gap_end - gap_start >= length)
87904 goto found;
87905
87906@@ -1854,6 +2113,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
87907 struct mm_struct *mm = current->mm;
87908 struct vm_area_struct *vma;
87909 struct vm_unmapped_area_info info;
87910+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
87911
87912 if (len > TASK_SIZE)
87913 return -ENOMEM;
87914@@ -1861,19 +2121,29 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
87915 if (flags & MAP_FIXED)
87916 return addr;
87917
87918+#ifdef CONFIG_PAX_RANDMMAP
87919+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
87920+#endif
87921+
87922 if (addr) {
87923 addr = PAGE_ALIGN(addr);
87924 vma = find_vma(mm, addr);
87925- if (TASK_SIZE - len >= addr &&
87926- (!vma || addr + len <= vma->vm_start))
87927+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
87928 return addr;
87929 }
87930
87931 info.flags = 0;
87932 info.length = len;
87933 info.low_limit = TASK_UNMAPPED_BASE;
87934+
87935+#ifdef CONFIG_PAX_RANDMMAP
87936+ if (mm->pax_flags & MF_PAX_RANDMMAP)
87937+ info.low_limit += mm->delta_mmap;
87938+#endif
87939+
87940 info.high_limit = TASK_SIZE;
87941 info.align_mask = 0;
87942+ info.threadstack_offset = offset;
87943 return vm_unmapped_area(&info);
87944 }
87945 #endif
87946@@ -1892,6 +2162,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
87947 struct mm_struct *mm = current->mm;
87948 unsigned long addr = addr0;
87949 struct vm_unmapped_area_info info;
87950+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
87951
87952 /* requested length too big for entire address space */
87953 if (len > TASK_SIZE)
87954@@ -1900,12 +2171,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
87955 if (flags & MAP_FIXED)
87956 return addr;
87957
87958+#ifdef CONFIG_PAX_RANDMMAP
87959+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
87960+#endif
87961+
87962 /* requesting a specific address */
87963 if (addr) {
87964 addr = PAGE_ALIGN(addr);
87965 vma = find_vma(mm, addr);
87966- if (TASK_SIZE - len >= addr &&
87967- (!vma || addr + len <= vma->vm_start))
87968+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
87969 return addr;
87970 }
87971
87972@@ -1914,6 +2188,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
87973 info.low_limit = PAGE_SIZE;
87974 info.high_limit = mm->mmap_base;
87975 info.align_mask = 0;
87976+ info.threadstack_offset = offset;
87977 addr = vm_unmapped_area(&info);
87978
87979 /*
87980@@ -1926,6 +2201,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
87981 VM_BUG_ON(addr != -ENOMEM);
87982 info.flags = 0;
87983 info.low_limit = TASK_UNMAPPED_BASE;
87984+
87985+#ifdef CONFIG_PAX_RANDMMAP
87986+ if (mm->pax_flags & MF_PAX_RANDMMAP)
87987+ info.low_limit += mm->delta_mmap;
87988+#endif
87989+
87990 info.high_limit = TASK_SIZE;
87991 addr = vm_unmapped_area(&info);
87992 }
87993@@ -2027,6 +2308,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
87994 return vma;
87995 }
87996
87997+#ifdef CONFIG_PAX_SEGMEXEC
87998+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
87999+{
88000+ struct vm_area_struct *vma_m;
88001+
88002+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
88003+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
88004+ BUG_ON(vma->vm_mirror);
88005+ return NULL;
88006+ }
88007+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
88008+ vma_m = vma->vm_mirror;
88009+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
88010+ BUG_ON(vma->vm_file != vma_m->vm_file);
88011+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
88012+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
88013+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
88014+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
88015+ return vma_m;
88016+}
88017+#endif
88018+
88019 /*
88020 * Verify that the stack growth is acceptable and
88021 * update accounting. This is shared with both the
88022@@ -2043,6 +2346,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
88023 return -ENOMEM;
88024
88025 /* Stack limit test */
88026+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
88027 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
88028 return -ENOMEM;
88029
88030@@ -2053,6 +2357,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
88031 locked = mm->locked_vm + grow;
88032 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
88033 limit >>= PAGE_SHIFT;
88034+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
88035 if (locked > limit && !capable(CAP_IPC_LOCK))
88036 return -ENOMEM;
88037 }
88038@@ -2082,37 +2387,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
88039 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
88040 * vma is the last one with address > vma->vm_end. Have to extend vma.
88041 */
88042+#ifndef CONFIG_IA64
88043+static
88044+#endif
88045 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
88046 {
88047 int error;
88048+ bool locknext;
88049
88050 if (!(vma->vm_flags & VM_GROWSUP))
88051 return -EFAULT;
88052
88053+ /* Also guard against wrapping around to address 0. */
88054+ if (address < PAGE_ALIGN(address+1))
88055+ address = PAGE_ALIGN(address+1);
88056+ else
88057+ return -ENOMEM;
88058+
88059 /*
88060 * We must make sure the anon_vma is allocated
88061 * so that the anon_vma locking is not a noop.
88062 */
88063 if (unlikely(anon_vma_prepare(vma)))
88064 return -ENOMEM;
88065+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
88066+ if (locknext && anon_vma_prepare(vma->vm_next))
88067+ return -ENOMEM;
88068 vma_lock_anon_vma(vma);
88069+ if (locknext)
88070+ vma_lock_anon_vma(vma->vm_next);
88071
88072 /*
88073 * vma->vm_start/vm_end cannot change under us because the caller
88074 * is required to hold the mmap_sem in read mode. We need the
88075- * anon_vma lock to serialize against concurrent expand_stacks.
88076- * Also guard against wrapping around to address 0.
88077+ * anon_vma locks to serialize against concurrent expand_stacks
88078+ * and expand_upwards.
88079 */
88080- if (address < PAGE_ALIGN(address+4))
88081- address = PAGE_ALIGN(address+4);
88082- else {
88083- vma_unlock_anon_vma(vma);
88084- return -ENOMEM;
88085- }
88086 error = 0;
88087
88088 /* Somebody else might have raced and expanded it already */
88089- if (address > vma->vm_end) {
88090+ 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)
88091+ error = -ENOMEM;
88092+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
88093 unsigned long size, grow;
88094
88095 size = address - vma->vm_start;
88096@@ -2147,6 +2463,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
88097 }
88098 }
88099 }
88100+ if (locknext)
88101+ vma_unlock_anon_vma(vma->vm_next);
88102 vma_unlock_anon_vma(vma);
88103 khugepaged_enter_vma_merge(vma);
88104 validate_mm(vma->vm_mm);
88105@@ -2161,6 +2479,8 @@ int expand_downwards(struct vm_area_struct *vma,
88106 unsigned long address)
88107 {
88108 int error;
88109+ bool lockprev = false;
88110+ struct vm_area_struct *prev;
88111
88112 /*
88113 * We must make sure the anon_vma is allocated
88114@@ -2174,6 +2494,15 @@ int expand_downwards(struct vm_area_struct *vma,
88115 if (error)
88116 return error;
88117
88118+ prev = vma->vm_prev;
88119+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
88120+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
88121+#endif
88122+ if (lockprev && anon_vma_prepare(prev))
88123+ return -ENOMEM;
88124+ if (lockprev)
88125+ vma_lock_anon_vma(prev);
88126+
88127 vma_lock_anon_vma(vma);
88128
88129 /*
88130@@ -2183,9 +2512,17 @@ int expand_downwards(struct vm_area_struct *vma,
88131 */
88132
88133 /* Somebody else might have raced and expanded it already */
88134- if (address < vma->vm_start) {
88135+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
88136+ error = -ENOMEM;
88137+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
88138 unsigned long size, grow;
88139
88140+#ifdef CONFIG_PAX_SEGMEXEC
88141+ struct vm_area_struct *vma_m;
88142+
88143+ vma_m = pax_find_mirror_vma(vma);
88144+#endif
88145+
88146 size = vma->vm_end - address;
88147 grow = (vma->vm_start - address) >> PAGE_SHIFT;
88148
88149@@ -2210,13 +2547,27 @@ int expand_downwards(struct vm_area_struct *vma,
88150 vma->vm_pgoff -= grow;
88151 anon_vma_interval_tree_post_update_vma(vma);
88152 vma_gap_update(vma);
88153+
88154+#ifdef CONFIG_PAX_SEGMEXEC
88155+ if (vma_m) {
88156+ anon_vma_interval_tree_pre_update_vma(vma_m);
88157+ vma_m->vm_start -= grow << PAGE_SHIFT;
88158+ vma_m->vm_pgoff -= grow;
88159+ anon_vma_interval_tree_post_update_vma(vma_m);
88160+ vma_gap_update(vma_m);
88161+ }
88162+#endif
88163+
88164 spin_unlock(&vma->vm_mm->page_table_lock);
88165
88166+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
88167 perf_event_mmap(vma);
88168 }
88169 }
88170 }
88171 vma_unlock_anon_vma(vma);
88172+ if (lockprev)
88173+ vma_unlock_anon_vma(prev);
88174 khugepaged_enter_vma_merge(vma);
88175 validate_mm(vma->vm_mm);
88176 return error;
88177@@ -2314,6 +2665,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
88178 do {
88179 long nrpages = vma_pages(vma);
88180
88181+#ifdef CONFIG_PAX_SEGMEXEC
88182+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
88183+ vma = remove_vma(vma);
88184+ continue;
88185+ }
88186+#endif
88187+
88188 if (vma->vm_flags & VM_ACCOUNT)
88189 nr_accounted += nrpages;
88190 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
88191@@ -2358,6 +2716,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
88192 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
88193 vma->vm_prev = NULL;
88194 do {
88195+
88196+#ifdef CONFIG_PAX_SEGMEXEC
88197+ if (vma->vm_mirror) {
88198+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
88199+ vma->vm_mirror->vm_mirror = NULL;
88200+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
88201+ vma->vm_mirror = NULL;
88202+ }
88203+#endif
88204+
88205 vma_rb_erase(vma, &mm->mm_rb);
88206 mm->map_count--;
88207 tail_vma = vma;
88208@@ -2384,14 +2752,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
88209 struct vm_area_struct *new;
88210 int err = -ENOMEM;
88211
88212+#ifdef CONFIG_PAX_SEGMEXEC
88213+ struct vm_area_struct *vma_m, *new_m = NULL;
88214+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
88215+#endif
88216+
88217 if (is_vm_hugetlb_page(vma) && (addr &
88218 ~(huge_page_mask(hstate_vma(vma)))))
88219 return -EINVAL;
88220
88221+#ifdef CONFIG_PAX_SEGMEXEC
88222+ vma_m = pax_find_mirror_vma(vma);
88223+#endif
88224+
88225 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
88226 if (!new)
88227 goto out_err;
88228
88229+#ifdef CONFIG_PAX_SEGMEXEC
88230+ if (vma_m) {
88231+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
88232+ if (!new_m) {
88233+ kmem_cache_free(vm_area_cachep, new);
88234+ goto out_err;
88235+ }
88236+ }
88237+#endif
88238+
88239 /* most fields are the same, copy all, and then fixup */
88240 *new = *vma;
88241
88242@@ -2404,6 +2791,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
88243 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
88244 }
88245
88246+#ifdef CONFIG_PAX_SEGMEXEC
88247+ if (vma_m) {
88248+ *new_m = *vma_m;
88249+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
88250+ new_m->vm_mirror = new;
88251+ new->vm_mirror = new_m;
88252+
88253+ if (new_below)
88254+ new_m->vm_end = addr_m;
88255+ else {
88256+ new_m->vm_start = addr_m;
88257+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
88258+ }
88259+ }
88260+#endif
88261+
88262 pol = mpol_dup(vma_policy(vma));
88263 if (IS_ERR(pol)) {
88264 err = PTR_ERR(pol);
88265@@ -2426,6 +2829,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
88266 else
88267 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
88268
88269+#ifdef CONFIG_PAX_SEGMEXEC
88270+ if (!err && vma_m) {
88271+ if (anon_vma_clone(new_m, vma_m))
88272+ goto out_free_mpol;
88273+
88274+ mpol_get(pol);
88275+ vma_set_policy(new_m, pol);
88276+
88277+ if (new_m->vm_file)
88278+ get_file(new_m->vm_file);
88279+
88280+ if (new_m->vm_ops && new_m->vm_ops->open)
88281+ new_m->vm_ops->open(new_m);
88282+
88283+ if (new_below)
88284+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
88285+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
88286+ else
88287+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
88288+
88289+ if (err) {
88290+ if (new_m->vm_ops && new_m->vm_ops->close)
88291+ new_m->vm_ops->close(new_m);
88292+ if (new_m->vm_file)
88293+ fput(new_m->vm_file);
88294+ mpol_put(pol);
88295+ }
88296+ }
88297+#endif
88298+
88299 /* Success. */
88300 if (!err)
88301 return 0;
88302@@ -2435,10 +2868,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
88303 new->vm_ops->close(new);
88304 if (new->vm_file)
88305 fput(new->vm_file);
88306- unlink_anon_vmas(new);
88307 out_free_mpol:
88308 mpol_put(pol);
88309 out_free_vma:
88310+
88311+#ifdef CONFIG_PAX_SEGMEXEC
88312+ if (new_m) {
88313+ unlink_anon_vmas(new_m);
88314+ kmem_cache_free(vm_area_cachep, new_m);
88315+ }
88316+#endif
88317+
88318+ unlink_anon_vmas(new);
88319 kmem_cache_free(vm_area_cachep, new);
88320 out_err:
88321 return err;
88322@@ -2451,6 +2892,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
88323 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
88324 unsigned long addr, int new_below)
88325 {
88326+
88327+#ifdef CONFIG_PAX_SEGMEXEC
88328+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
88329+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
88330+ if (mm->map_count >= sysctl_max_map_count-1)
88331+ return -ENOMEM;
88332+ } else
88333+#endif
88334+
88335 if (mm->map_count >= sysctl_max_map_count)
88336 return -ENOMEM;
88337
88338@@ -2462,11 +2912,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
88339 * work. This now handles partial unmappings.
88340 * Jeremy Fitzhardinge <jeremy@goop.org>
88341 */
88342+#ifdef CONFIG_PAX_SEGMEXEC
88343 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
88344 {
88345+ int ret = __do_munmap(mm, start, len);
88346+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
88347+ return ret;
88348+
88349+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
88350+}
88351+
88352+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
88353+#else
88354+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
88355+#endif
88356+{
88357 unsigned long end;
88358 struct vm_area_struct *vma, *prev, *last;
88359
88360+ /*
88361+ * mm->mmap_sem is required to protect against another thread
88362+ * changing the mappings in case we sleep.
88363+ */
88364+ verify_mm_writelocked(mm);
88365+
88366 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
88367 return -EINVAL;
88368
88369@@ -2541,6 +3010,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
88370 /* Fix up all other VM information */
88371 remove_vma_list(mm, vma);
88372
88373+ track_exec_limit(mm, start, end, 0UL);
88374+
88375 return 0;
88376 }
88377
88378@@ -2549,6 +3020,13 @@ int vm_munmap(unsigned long start, size_t len)
88379 int ret;
88380 struct mm_struct *mm = current->mm;
88381
88382+
88383+#ifdef CONFIG_PAX_SEGMEXEC
88384+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
88385+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
88386+ return -EINVAL;
88387+#endif
88388+
88389 down_write(&mm->mmap_sem);
88390 ret = do_munmap(mm, start, len);
88391 up_write(&mm->mmap_sem);
88392@@ -2562,16 +3040,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
88393 return vm_munmap(addr, len);
88394 }
88395
88396-static inline void verify_mm_writelocked(struct mm_struct *mm)
88397-{
88398-#ifdef CONFIG_DEBUG_VM
88399- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
88400- WARN_ON(1);
88401- up_read(&mm->mmap_sem);
88402- }
88403-#endif
88404-}
88405-
88406 /*
88407 * this is really a simplified "do_mmap". it only handles
88408 * anonymous maps. eventually we may be able to do some
88409@@ -2585,6 +3053,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88410 struct rb_node ** rb_link, * rb_parent;
88411 pgoff_t pgoff = addr >> PAGE_SHIFT;
88412 int error;
88413+ unsigned long charged;
88414
88415 len = PAGE_ALIGN(len);
88416 if (!len)
88417@@ -2592,16 +3061,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88418
88419 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
88420
88421+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
88422+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
88423+ flags &= ~VM_EXEC;
88424+
88425+#ifdef CONFIG_PAX_MPROTECT
88426+ if (mm->pax_flags & MF_PAX_MPROTECT)
88427+ flags &= ~VM_MAYEXEC;
88428+#endif
88429+
88430+ }
88431+#endif
88432+
88433 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
88434 if (error & ~PAGE_MASK)
88435 return error;
88436
88437+ charged = len >> PAGE_SHIFT;
88438+
88439 /*
88440 * mlock MCL_FUTURE?
88441 */
88442 if (mm->def_flags & VM_LOCKED) {
88443 unsigned long locked, lock_limit;
88444- locked = len >> PAGE_SHIFT;
88445+ locked = charged;
88446 locked += mm->locked_vm;
88447 lock_limit = rlimit(RLIMIT_MEMLOCK);
88448 lock_limit >>= PAGE_SHIFT;
88449@@ -2618,21 +3101,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88450 /*
88451 * Clear old maps. this also does some error checking for us
88452 */
88453- munmap_back:
88454 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
88455 if (do_munmap(mm, addr, len))
88456 return -ENOMEM;
88457- goto munmap_back;
88458+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
88459 }
88460
88461 /* Check against address space limits *after* clearing old maps... */
88462- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
88463+ if (!may_expand_vm(mm, charged))
88464 return -ENOMEM;
88465
88466 if (mm->map_count > sysctl_max_map_count)
88467 return -ENOMEM;
88468
88469- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
88470+ if (security_vm_enough_memory_mm(mm, charged))
88471 return -ENOMEM;
88472
88473 /* Can we just expand an old private anonymous mapping? */
88474@@ -2646,7 +3128,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88475 */
88476 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
88477 if (!vma) {
88478- vm_unacct_memory(len >> PAGE_SHIFT);
88479+ vm_unacct_memory(charged);
88480 return -ENOMEM;
88481 }
88482
88483@@ -2660,9 +3142,10 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
88484 vma_link(mm, vma, prev, rb_link, rb_parent);
88485 out:
88486 perf_event_mmap(vma);
88487- mm->total_vm += len >> PAGE_SHIFT;
88488+ mm->total_vm += charged;
88489 if (flags & VM_LOCKED)
88490- mm->locked_vm += (len >> PAGE_SHIFT);
88491+ mm->locked_vm += charged;
88492+ track_exec_limit(mm, addr, addr + len, flags);
88493 return addr;
88494 }
88495
88496@@ -2724,6 +3207,7 @@ void exit_mmap(struct mm_struct *mm)
88497 while (vma) {
88498 if (vma->vm_flags & VM_ACCOUNT)
88499 nr_accounted += vma_pages(vma);
88500+ vma->vm_mirror = NULL;
88501 vma = remove_vma(vma);
88502 }
88503 vm_unacct_memory(nr_accounted);
88504@@ -2740,6 +3224,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
88505 struct vm_area_struct *prev;
88506 struct rb_node **rb_link, *rb_parent;
88507
88508+#ifdef CONFIG_PAX_SEGMEXEC
88509+ struct vm_area_struct *vma_m = NULL;
88510+#endif
88511+
88512+ if (security_mmap_addr(vma->vm_start))
88513+ return -EPERM;
88514+
88515 /*
88516 * The vm_pgoff of a purely anonymous vma should be irrelevant
88517 * until its first write fault, when page's anon_vma and index
88518@@ -2763,7 +3254,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
88519 security_vm_enough_memory_mm(mm, vma_pages(vma)))
88520 return -ENOMEM;
88521
88522+#ifdef CONFIG_PAX_SEGMEXEC
88523+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
88524+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
88525+ if (!vma_m)
88526+ return -ENOMEM;
88527+ }
88528+#endif
88529+
88530 vma_link(mm, vma, prev, rb_link, rb_parent);
88531+
88532+#ifdef CONFIG_PAX_SEGMEXEC
88533+ if (vma_m)
88534+ BUG_ON(pax_mirror_vma(vma_m, vma));
88535+#endif
88536+
88537 return 0;
88538 }
88539
88540@@ -2783,6 +3288,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
88541 struct mempolicy *pol;
88542 bool faulted_in_anon_vma = true;
88543
88544+ BUG_ON(vma->vm_mirror);
88545+
88546 /*
88547 * If anonymous vma has not yet been faulted, update new pgoff
88548 * to match new location, to increase its chance of merging.
88549@@ -2849,6 +3356,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
88550 return NULL;
88551 }
88552
88553+#ifdef CONFIG_PAX_SEGMEXEC
88554+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
88555+{
88556+ struct vm_area_struct *prev_m;
88557+ struct rb_node **rb_link_m, *rb_parent_m;
88558+ struct mempolicy *pol_m;
88559+
88560+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
88561+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
88562+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
88563+ *vma_m = *vma;
88564+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
88565+ if (anon_vma_clone(vma_m, vma))
88566+ return -ENOMEM;
88567+ pol_m = vma_policy(vma_m);
88568+ mpol_get(pol_m);
88569+ vma_set_policy(vma_m, pol_m);
88570+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
88571+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
88572+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
88573+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
88574+ if (vma_m->vm_file)
88575+ get_file(vma_m->vm_file);
88576+ if (vma_m->vm_ops && vma_m->vm_ops->open)
88577+ vma_m->vm_ops->open(vma_m);
88578+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
88579+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
88580+ vma_m->vm_mirror = vma;
88581+ vma->vm_mirror = vma_m;
88582+ return 0;
88583+}
88584+#endif
88585+
88586 /*
88587 * Return true if the calling process may expand its vm space by the passed
88588 * number of pages
88589@@ -2860,6 +3400,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
88590
88591 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
88592
88593+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
88594 if (cur + npages > lim)
88595 return 0;
88596 return 1;
88597@@ -2930,6 +3471,22 @@ int install_special_mapping(struct mm_struct *mm,
88598 vma->vm_start = addr;
88599 vma->vm_end = addr + len;
88600
88601+#ifdef CONFIG_PAX_MPROTECT
88602+ if (mm->pax_flags & MF_PAX_MPROTECT) {
88603+#ifndef CONFIG_PAX_MPROTECT_COMPAT
88604+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
88605+ return -EPERM;
88606+ if (!(vm_flags & VM_EXEC))
88607+ vm_flags &= ~VM_MAYEXEC;
88608+#else
88609+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
88610+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
88611+#endif
88612+ else
88613+ vm_flags &= ~VM_MAYWRITE;
88614+ }
88615+#endif
88616+
88617 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
88618 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
88619
88620diff --git a/mm/mprotect.c b/mm/mprotect.c
88621index 94722a4..e661e29 100644
88622--- a/mm/mprotect.c
88623+++ b/mm/mprotect.c
88624@@ -23,10 +23,18 @@
88625 #include <linux/mmu_notifier.h>
88626 #include <linux/migrate.h>
88627 #include <linux/perf_event.h>
88628+#include <linux/sched/sysctl.h>
88629+
88630+#ifdef CONFIG_PAX_MPROTECT
88631+#include <linux/elf.h>
88632+#include <linux/binfmts.h>
88633+#endif
88634+
88635 #include <asm/uaccess.h>
88636 #include <asm/pgtable.h>
88637 #include <asm/cacheflush.h>
88638 #include <asm/tlbflush.h>
88639+#include <asm/mmu_context.h>
88640
88641 #ifndef pgprot_modify
88642 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
88643@@ -233,6 +241,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
88644 return pages;
88645 }
88646
88647+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
88648+/* called while holding the mmap semaphor for writing except stack expansion */
88649+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
88650+{
88651+ unsigned long oldlimit, newlimit = 0UL;
88652+
88653+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
88654+ return;
88655+
88656+ spin_lock(&mm->page_table_lock);
88657+ oldlimit = mm->context.user_cs_limit;
88658+ if ((prot & VM_EXEC) && oldlimit < end)
88659+ /* USER_CS limit moved up */
88660+ newlimit = end;
88661+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
88662+ /* USER_CS limit moved down */
88663+ newlimit = start;
88664+
88665+ if (newlimit) {
88666+ mm->context.user_cs_limit = newlimit;
88667+
88668+#ifdef CONFIG_SMP
88669+ wmb();
88670+ cpus_clear(mm->context.cpu_user_cs_mask);
88671+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
88672+#endif
88673+
88674+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
88675+ }
88676+ spin_unlock(&mm->page_table_lock);
88677+ if (newlimit == end) {
88678+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
88679+
88680+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
88681+ if (is_vm_hugetlb_page(vma))
88682+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
88683+ else
88684+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
88685+ }
88686+}
88687+#endif
88688+
88689 int
88690 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
88691 unsigned long start, unsigned long end, unsigned long newflags)
88692@@ -245,11 +295,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
88693 int error;
88694 int dirty_accountable = 0;
88695
88696+#ifdef CONFIG_PAX_SEGMEXEC
88697+ struct vm_area_struct *vma_m = NULL;
88698+ unsigned long start_m, end_m;
88699+
88700+ start_m = start + SEGMEXEC_TASK_SIZE;
88701+ end_m = end + SEGMEXEC_TASK_SIZE;
88702+#endif
88703+
88704 if (newflags == oldflags) {
88705 *pprev = vma;
88706 return 0;
88707 }
88708
88709+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
88710+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
88711+
88712+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
88713+ return -ENOMEM;
88714+
88715+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
88716+ return -ENOMEM;
88717+ }
88718+
88719 /*
88720 * If we make a private mapping writable we increase our commit;
88721 * but (without finer accounting) cannot reduce our commit if we
88722@@ -266,6 +334,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
88723 }
88724 }
88725
88726+#ifdef CONFIG_PAX_SEGMEXEC
88727+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
88728+ if (start != vma->vm_start) {
88729+ error = split_vma(mm, vma, start, 1);
88730+ if (error)
88731+ goto fail;
88732+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
88733+ *pprev = (*pprev)->vm_next;
88734+ }
88735+
88736+ if (end != vma->vm_end) {
88737+ error = split_vma(mm, vma, end, 0);
88738+ if (error)
88739+ goto fail;
88740+ }
88741+
88742+ if (pax_find_mirror_vma(vma)) {
88743+ error = __do_munmap(mm, start_m, end_m - start_m);
88744+ if (error)
88745+ goto fail;
88746+ } else {
88747+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
88748+ if (!vma_m) {
88749+ error = -ENOMEM;
88750+ goto fail;
88751+ }
88752+ vma->vm_flags = newflags;
88753+ error = pax_mirror_vma(vma_m, vma);
88754+ if (error) {
88755+ vma->vm_flags = oldflags;
88756+ goto fail;
88757+ }
88758+ }
88759+ }
88760+#endif
88761+
88762 /*
88763 * First try to merge with previous and/or next vma.
88764 */
88765@@ -296,9 +400,21 @@ success:
88766 * vm_flags and vm_page_prot are protected by the mmap_sem
88767 * held in write mode.
88768 */
88769+
88770+#ifdef CONFIG_PAX_SEGMEXEC
88771+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
88772+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
88773+#endif
88774+
88775 vma->vm_flags = newflags;
88776+
88777+#ifdef CONFIG_PAX_MPROTECT
88778+ if (mm->binfmt && mm->binfmt->handle_mprotect)
88779+ mm->binfmt->handle_mprotect(vma, newflags);
88780+#endif
88781+
88782 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
88783- vm_get_page_prot(newflags));
88784+ vm_get_page_prot(vma->vm_flags));
88785
88786 if (vma_wants_writenotify(vma)) {
88787 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
88788@@ -337,6 +453,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88789 end = start + len;
88790 if (end <= start)
88791 return -ENOMEM;
88792+
88793+#ifdef CONFIG_PAX_SEGMEXEC
88794+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
88795+ if (end > SEGMEXEC_TASK_SIZE)
88796+ return -EINVAL;
88797+ } else
88798+#endif
88799+
88800+ if (end > TASK_SIZE)
88801+ return -EINVAL;
88802+
88803 if (!arch_validate_prot(prot))
88804 return -EINVAL;
88805
88806@@ -344,7 +471,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88807 /*
88808 * Does the application expect PROT_READ to imply PROT_EXEC:
88809 */
88810- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
88811+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
88812 prot |= PROT_EXEC;
88813
88814 vm_flags = calc_vm_prot_bits(prot);
88815@@ -376,6 +503,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88816 if (start > vma->vm_start)
88817 prev = vma;
88818
88819+#ifdef CONFIG_PAX_MPROTECT
88820+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
88821+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
88822+#endif
88823+
88824 for (nstart = start ; ; ) {
88825 unsigned long newflags;
88826
88827@@ -386,6 +518,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88828
88829 /* newflags >> 4 shift VM_MAY% in place of VM_% */
88830 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
88831+ if (prot & (PROT_WRITE | PROT_EXEC))
88832+ gr_log_rwxmprotect(vma);
88833+
88834+ error = -EACCES;
88835+ goto out;
88836+ }
88837+
88838+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
88839 error = -EACCES;
88840 goto out;
88841 }
88842@@ -400,6 +540,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
88843 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
88844 if (error)
88845 goto out;
88846+
88847+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
88848+
88849 nstart = tmp;
88850
88851 if (nstart < prev->vm_end)
88852diff --git a/mm/mremap.c b/mm/mremap.c
88853index 0843feb..5607f47 100644
88854--- a/mm/mremap.c
88855+++ b/mm/mremap.c
88856@@ -25,6 +25,7 @@
88857 #include <asm/uaccess.h>
88858 #include <asm/cacheflush.h>
88859 #include <asm/tlbflush.h>
88860+#include <asm/pgalloc.h>
88861
88862 #include "internal.h"
88863
88864@@ -62,8 +63,10 @@ static pmd_t *alloc_new_pmd(struct mm_struct *mm, struct vm_area_struct *vma,
88865 return NULL;
88866
88867 pmd = pmd_alloc(mm, pud, addr);
88868- if (!pmd)
88869+ if (!pmd) {
88870+ pud_free(mm, pud);
88871 return NULL;
88872+ }
88873
88874 VM_BUG_ON(pmd_trans_huge(*pmd));
88875
88876@@ -144,6 +147,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
88877 continue;
88878 pte = ptep_get_and_clear(mm, old_addr, old_pte);
88879 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
88880+
88881+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
88882+ if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
88883+ pte = pte_exprotect(pte);
88884+#endif
88885+
88886 pte = move_soft_dirty_pte(pte);
88887 set_pte_at(mm, new_addr, new_pte, pte);
88888 }
88889@@ -337,6 +346,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
88890 if (is_vm_hugetlb_page(vma))
88891 goto Einval;
88892
88893+#ifdef CONFIG_PAX_SEGMEXEC
88894+ if (pax_find_mirror_vma(vma))
88895+ goto Einval;
88896+#endif
88897+
88898 /* We can't remap across vm area boundaries */
88899 if (old_len > vma->vm_end - addr)
88900 goto Efault;
88901@@ -392,20 +406,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
88902 unsigned long ret = -EINVAL;
88903 unsigned long charged = 0;
88904 unsigned long map_flags;
88905+ unsigned long pax_task_size = TASK_SIZE;
88906
88907 if (new_addr & ~PAGE_MASK)
88908 goto out;
88909
88910- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
88911+#ifdef CONFIG_PAX_SEGMEXEC
88912+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
88913+ pax_task_size = SEGMEXEC_TASK_SIZE;
88914+#endif
88915+
88916+ pax_task_size -= PAGE_SIZE;
88917+
88918+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
88919 goto out;
88920
88921 /* Check if the location we're moving into overlaps the
88922 * old location at all, and fail if it does.
88923 */
88924- if ((new_addr <= addr) && (new_addr+new_len) > addr)
88925- goto out;
88926-
88927- if ((addr <= new_addr) && (addr+old_len) > new_addr)
88928+ if (addr + old_len > new_addr && new_addr + new_len > addr)
88929 goto out;
88930
88931 ret = do_munmap(mm, new_addr, new_len);
88932@@ -474,6 +493,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
88933 unsigned long ret = -EINVAL;
88934 unsigned long charged = 0;
88935 bool locked = false;
88936+ unsigned long pax_task_size = TASK_SIZE;
88937
88938 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
88939 return ret;
88940@@ -495,6 +515,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
88941 if (!new_len)
88942 return ret;
88943
88944+#ifdef CONFIG_PAX_SEGMEXEC
88945+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
88946+ pax_task_size = SEGMEXEC_TASK_SIZE;
88947+#endif
88948+
88949+ pax_task_size -= PAGE_SIZE;
88950+
88951+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
88952+ old_len > pax_task_size || addr > pax_task_size-old_len)
88953+ return ret;
88954+
88955 down_write(&current->mm->mmap_sem);
88956
88957 if (flags & MREMAP_FIXED) {
88958@@ -545,6 +576,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
88959 new_addr = addr;
88960 }
88961 ret = addr;
88962+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
88963 goto out;
88964 }
88965 }
88966@@ -568,7 +600,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
88967 goto out;
88968 }
88969
88970+ map_flags = vma->vm_flags;
88971 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
88972+ if (!(ret & ~PAGE_MASK)) {
88973+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
88974+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
88975+ }
88976 }
88977 out:
88978 if (ret & ~PAGE_MASK)
88979diff --git a/mm/nommu.c b/mm/nommu.c
88980index ecd1f15..77039bd 100644
88981--- a/mm/nommu.c
88982+++ b/mm/nommu.c
88983@@ -64,7 +64,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
88984 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
88985 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
88986 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
88987-int heap_stack_gap = 0;
88988
88989 atomic_long_t mmap_pages_allocated;
88990
88991@@ -844,15 +843,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
88992 EXPORT_SYMBOL(find_vma);
88993
88994 /*
88995- * find a VMA
88996- * - we don't extend stack VMAs under NOMMU conditions
88997- */
88998-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
88999-{
89000- return find_vma(mm, addr);
89001-}
89002-
89003-/*
89004 * expand a stack to a given address
89005 * - not supported under NOMMU conditions
89006 */
89007@@ -1563,6 +1553,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
89008
89009 /* most fields are the same, copy all, and then fixup */
89010 *new = *vma;
89011+ INIT_LIST_HEAD(&new->anon_vma_chain);
89012 *region = *vma->vm_region;
89013 new->vm_region = region;
89014
89015@@ -1993,8 +1984,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
89016 }
89017 EXPORT_SYMBOL(generic_file_remap_pages);
89018
89019-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
89020- unsigned long addr, void *buf, int len, int write)
89021+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
89022+ unsigned long addr, void *buf, size_t len, int write)
89023 {
89024 struct vm_area_struct *vma;
89025
89026@@ -2035,8 +2026,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
89027 *
89028 * The caller must hold a reference on @mm.
89029 */
89030-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
89031- void *buf, int len, int write)
89032+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
89033+ void *buf, size_t len, int write)
89034 {
89035 return __access_remote_vm(NULL, mm, addr, buf, len, write);
89036 }
89037@@ -2045,7 +2036,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
89038 * Access another process' address space.
89039 * - source/target buffer must be kernel space
89040 */
89041-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
89042+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
89043 {
89044 struct mm_struct *mm;
89045
89046diff --git a/mm/page-writeback.c b/mm/page-writeback.c
89047index 3f0c895..60cd104 100644
89048--- a/mm/page-writeback.c
89049+++ b/mm/page-writeback.c
89050@@ -659,7 +659,7 @@ unsigned long bdi_dirty_limit(struct backing_dev_info *bdi, unsigned long dirty)
89051 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
89052 * - the bdi dirty thresh drops quickly due to change of JBOD workload
89053 */
89054-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
89055+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
89056 unsigned long thresh,
89057 unsigned long bg_thresh,
89058 unsigned long dirty,
89059diff --git a/mm/page_alloc.c b/mm/page_alloc.c
89060index b100255..fba1254 100644
89061--- a/mm/page_alloc.c
89062+++ b/mm/page_alloc.c
89063@@ -60,6 +60,7 @@
89064 #include <linux/page-debug-flags.h>
89065 #include <linux/hugetlb.h>
89066 #include <linux/sched/rt.h>
89067+#include <linux/random.h>
89068
89069 #include <asm/sections.h>
89070 #include <asm/tlbflush.h>
89071@@ -353,7 +354,7 @@ out:
89072 * This usage means that zero-order pages may not be compound.
89073 */
89074
89075-static void free_compound_page(struct page *page)
89076+void free_compound_page(struct page *page)
89077 {
89078 __free_pages_ok(page, compound_order(page));
89079 }
89080@@ -710,6 +711,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
89081 int i;
89082 int bad = 0;
89083
89084+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89085+ unsigned long index = 1UL << order;
89086+#endif
89087+
89088 trace_mm_page_free(page, order);
89089 kmemcheck_free_shadow(page, order);
89090
89091@@ -725,6 +730,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
89092 debug_check_no_obj_freed(page_address(page),
89093 PAGE_SIZE << order);
89094 }
89095+
89096+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89097+ for (; index; --index)
89098+ sanitize_highpage(page + index - 1);
89099+#endif
89100+
89101 arch_free_page(page, order);
89102 kernel_map_pages(page, 1 << order, 0);
89103
89104@@ -747,6 +758,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
89105 local_irq_restore(flags);
89106 }
89107
89108+#ifdef CONFIG_PAX_LATENT_ENTROPY
89109+bool __meminitdata extra_latent_entropy;
89110+
89111+static int __init setup_pax_extra_latent_entropy(char *str)
89112+{
89113+ extra_latent_entropy = true;
89114+ return 0;
89115+}
89116+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
89117+
89118+volatile u64 latent_entropy;
89119+EXPORT_SYMBOL(latent_entropy);
89120+#endif
89121+
89122 void __init __free_pages_bootmem(struct page *page, unsigned int order)
89123 {
89124 unsigned int nr_pages = 1 << order;
89125@@ -762,6 +787,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
89126 set_page_count(p, 0);
89127 }
89128
89129+#ifdef CONFIG_PAX_LATENT_ENTROPY
89130+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
89131+ u64 hash = 0;
89132+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
89133+ const u64 *data = lowmem_page_address(page);
89134+
89135+ for (index = 0; index < end; index++)
89136+ hash ^= hash + data[index];
89137+ latent_entropy ^= hash;
89138+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
89139+ }
89140+#endif
89141+
89142 page_zone(page)->managed_pages += 1 << order;
89143 set_page_refcounted(page);
89144 __free_pages(page, order);
89145@@ -867,8 +905,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
89146 arch_alloc_page(page, order);
89147 kernel_map_pages(page, 1 << order, 1);
89148
89149+#ifndef CONFIG_PAX_MEMORY_SANITIZE
89150 if (gfp_flags & __GFP_ZERO)
89151 prep_zero_page(page, order, gfp_flags);
89152+#endif
89153
89154 if (order && (gfp_flags & __GFP_COMP))
89155 prep_compound_page(page, order);
89156diff --git a/mm/page_io.c b/mm/page_io.c
89157index ba05b64..ef2f314 100644
89158--- a/mm/page_io.c
89159+++ b/mm/page_io.c
89160@@ -260,7 +260,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
89161 struct file *swap_file = sis->swap_file;
89162 struct address_space *mapping = swap_file->f_mapping;
89163 struct iovec iov = {
89164- .iov_base = kmap(page),
89165+ .iov_base = (void __force_user *)kmap(page),
89166 .iov_len = PAGE_SIZE,
89167 };
89168
89169diff --git a/mm/percpu.c b/mm/percpu.c
89170index 8c8e08f..73a5cda 100644
89171--- a/mm/percpu.c
89172+++ b/mm/percpu.c
89173@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
89174 static unsigned int pcpu_high_unit_cpu __read_mostly;
89175
89176 /* the address of the first chunk which starts with the kernel static area */
89177-void *pcpu_base_addr __read_mostly;
89178+void *pcpu_base_addr __read_only;
89179 EXPORT_SYMBOL_GPL(pcpu_base_addr);
89180
89181 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
89182diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
89183index fd26d04..0cea1b0 100644
89184--- a/mm/process_vm_access.c
89185+++ b/mm/process_vm_access.c
89186@@ -13,6 +13,7 @@
89187 #include <linux/uio.h>
89188 #include <linux/sched.h>
89189 #include <linux/highmem.h>
89190+#include <linux/security.h>
89191 #include <linux/ptrace.h>
89192 #include <linux/slab.h>
89193 #include <linux/syscalls.h>
89194@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
89195 size_t iov_l_curr_offset = 0;
89196 ssize_t iov_len;
89197
89198+ return -ENOSYS; // PaX: until properly audited
89199+
89200 /*
89201 * Work out how many pages of struct pages we're going to need
89202 * when eventually calling get_user_pages
89203 */
89204 for (i = 0; i < riovcnt; i++) {
89205 iov_len = rvec[i].iov_len;
89206- if (iov_len > 0) {
89207- nr_pages_iov = ((unsigned long)rvec[i].iov_base
89208- + iov_len)
89209- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
89210- / PAGE_SIZE + 1;
89211- nr_pages = max(nr_pages, nr_pages_iov);
89212- }
89213+ if (iov_len <= 0)
89214+ continue;
89215+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
89216+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
89217+ nr_pages = max(nr_pages, nr_pages_iov);
89218 }
89219
89220 if (nr_pages == 0)
89221@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
89222 goto free_proc_pages;
89223 }
89224
89225+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
89226+ rc = -EPERM;
89227+ goto put_task_struct;
89228+ }
89229+
89230 mm = mm_access(task, PTRACE_MODE_ATTACH);
89231 if (!mm || IS_ERR(mm)) {
89232 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
89233diff --git a/mm/rmap.c b/mm/rmap.c
89234index b2e29ac..4168491 100644
89235--- a/mm/rmap.c
89236+++ b/mm/rmap.c
89237@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
89238 struct anon_vma *anon_vma = vma->anon_vma;
89239 struct anon_vma_chain *avc;
89240
89241+#ifdef CONFIG_PAX_SEGMEXEC
89242+ struct anon_vma_chain *avc_m = NULL;
89243+#endif
89244+
89245 might_sleep();
89246 if (unlikely(!anon_vma)) {
89247 struct mm_struct *mm = vma->vm_mm;
89248@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
89249 if (!avc)
89250 goto out_enomem;
89251
89252+#ifdef CONFIG_PAX_SEGMEXEC
89253+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
89254+ if (!avc_m)
89255+ goto out_enomem_free_avc;
89256+#endif
89257+
89258 anon_vma = find_mergeable_anon_vma(vma);
89259 allocated = NULL;
89260 if (!anon_vma) {
89261@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
89262 /* page_table_lock to protect against threads */
89263 spin_lock(&mm->page_table_lock);
89264 if (likely(!vma->anon_vma)) {
89265+
89266+#ifdef CONFIG_PAX_SEGMEXEC
89267+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
89268+
89269+ if (vma_m) {
89270+ BUG_ON(vma_m->anon_vma);
89271+ vma_m->anon_vma = anon_vma;
89272+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
89273+ avc_m = NULL;
89274+ }
89275+#endif
89276+
89277 vma->anon_vma = anon_vma;
89278 anon_vma_chain_link(vma, avc, anon_vma);
89279 allocated = NULL;
89280@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
89281
89282 if (unlikely(allocated))
89283 put_anon_vma(allocated);
89284+
89285+#ifdef CONFIG_PAX_SEGMEXEC
89286+ if (unlikely(avc_m))
89287+ anon_vma_chain_free(avc_m);
89288+#endif
89289+
89290 if (unlikely(avc))
89291 anon_vma_chain_free(avc);
89292 }
89293 return 0;
89294
89295 out_enomem_free_avc:
89296+
89297+#ifdef CONFIG_PAX_SEGMEXEC
89298+ if (avc_m)
89299+ anon_vma_chain_free(avc_m);
89300+#endif
89301+
89302 anon_vma_chain_free(avc);
89303 out_enomem:
89304 return -ENOMEM;
89305@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
89306 * Attach the anon_vmas from src to dst.
89307 * Returns 0 on success, -ENOMEM on failure.
89308 */
89309-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
89310+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
89311 {
89312 struct anon_vma_chain *avc, *pavc;
89313 struct anon_vma *root = NULL;
89314@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
89315 * the corresponding VMA in the parent process is attached to.
89316 * Returns 0 on success, non-zero on failure.
89317 */
89318-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
89319+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
89320 {
89321 struct anon_vma_chain *avc;
89322 struct anon_vma *anon_vma;
89323@@ -373,8 +407,10 @@ static void anon_vma_ctor(void *data)
89324 void __init anon_vma_init(void)
89325 {
89326 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
89327- 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
89328- anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
89329+ 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
89330+ anon_vma_ctor);
89331+ anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
89332+ SLAB_PANIC|SLAB_NO_SANITIZE);
89333 }
89334
89335 /*
89336diff --git a/mm/shmem.c b/mm/shmem.c
89337index e43dc55..930e3a2 100644
89338--- a/mm/shmem.c
89339+++ b/mm/shmem.c
89340@@ -33,7 +33,7 @@
89341 #include <linux/swap.h>
89342 #include <linux/aio.h>
89343
89344-static struct vfsmount *shm_mnt;
89345+struct vfsmount *shm_mnt;
89346
89347 #ifdef CONFIG_SHMEM
89348 /*
89349@@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
89350 #define BOGO_DIRENT_SIZE 20
89351
89352 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
89353-#define SHORT_SYMLINK_LEN 128
89354+#define SHORT_SYMLINK_LEN 64
89355
89356 /*
89357 * shmem_fallocate and shmem_writepage communicate via inode->i_private
89358@@ -2232,6 +2232,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
89359 static int shmem_xattr_validate(const char *name)
89360 {
89361 struct { const char *prefix; size_t len; } arr[] = {
89362+
89363+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
89364+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
89365+#endif
89366+
89367 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
89368 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
89369 };
89370@@ -2287,6 +2292,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
89371 if (err)
89372 return err;
89373
89374+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
89375+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
89376+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
89377+ return -EOPNOTSUPP;
89378+ if (size > 8)
89379+ return -EINVAL;
89380+ }
89381+#endif
89382+
89383 return simple_xattr_set(&info->xattrs, name, value, size, flags);
89384 }
89385
89386@@ -2599,8 +2613,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
89387 int err = -ENOMEM;
89388
89389 /* Round up to L1_CACHE_BYTES to resist false sharing */
89390- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
89391- L1_CACHE_BYTES), GFP_KERNEL);
89392+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
89393 if (!sbinfo)
89394 return -ENOMEM;
89395
89396diff --git a/mm/slab.c b/mm/slab.c
89397index 2580db0..0523956 100644
89398--- a/mm/slab.c
89399+++ b/mm/slab.c
89400@@ -366,10 +366,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
89401 if ((x)->max_freeable < i) \
89402 (x)->max_freeable = i; \
89403 } while (0)
89404-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
89405-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
89406-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
89407-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
89408+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
89409+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
89410+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
89411+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
89412+#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
89413+#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
89414 #else
89415 #define STATS_INC_ACTIVE(x) do { } while (0)
89416 #define STATS_DEC_ACTIVE(x) do { } while (0)
89417@@ -386,6 +388,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
89418 #define STATS_INC_ALLOCMISS(x) do { } while (0)
89419 #define STATS_INC_FREEHIT(x) do { } while (0)
89420 #define STATS_INC_FREEMISS(x) do { } while (0)
89421+#define STATS_INC_SANITIZED(x) do { } while (0)
89422+#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
89423 #endif
89424
89425 #if DEBUG
89426@@ -477,7 +481,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
89427 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
89428 */
89429 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
89430- const struct slab *slab, void *obj)
89431+ const struct slab *slab, const void *obj)
89432 {
89433 u32 offset = (obj - slab->s_mem);
89434 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
89435@@ -1571,12 +1575,12 @@ void __init kmem_cache_init(void)
89436 */
89437
89438 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
89439- kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
89440+ kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
89441
89442 if (INDEX_AC != INDEX_NODE)
89443 kmalloc_caches[INDEX_NODE] =
89444 create_kmalloc_cache("kmalloc-node",
89445- kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
89446+ kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
89447
89448 slab_early_init = 0;
89449
89450@@ -3577,6 +3581,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
89451 struct array_cache *ac = cpu_cache_get(cachep);
89452
89453 check_irq_off();
89454+
89455+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89456+ if (pax_sanitize_slab) {
89457+ if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
89458+ memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
89459+
89460+ if (cachep->ctor)
89461+ cachep->ctor(objp);
89462+
89463+ STATS_INC_SANITIZED(cachep);
89464+ } else
89465+ STATS_INC_NOT_SANITIZED(cachep);
89466+ }
89467+#endif
89468+
89469 kmemleak_free_recursive(objp, cachep->flags);
89470 objp = cache_free_debugcheck(cachep, objp, caller);
89471
89472@@ -3805,6 +3824,7 @@ void kfree(const void *objp)
89473
89474 if (unlikely(ZERO_OR_NULL_PTR(objp)))
89475 return;
89476+ VM_BUG_ON(!virt_addr_valid(objp));
89477 local_irq_save(flags);
89478 kfree_debugcheck(objp);
89479 c = virt_to_cache(objp);
89480@@ -4246,14 +4266,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
89481 }
89482 /* cpu stats */
89483 {
89484- unsigned long allochit = atomic_read(&cachep->allochit);
89485- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
89486- unsigned long freehit = atomic_read(&cachep->freehit);
89487- unsigned long freemiss = atomic_read(&cachep->freemiss);
89488+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
89489+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
89490+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
89491+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
89492
89493 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
89494 allochit, allocmiss, freehit, freemiss);
89495 }
89496+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89497+ {
89498+ unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
89499+ unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
89500+
89501+ seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
89502+ }
89503+#endif
89504 #endif
89505 }
89506
89507@@ -4471,13 +4499,71 @@ static const struct file_operations proc_slabstats_operations = {
89508 static int __init slab_proc_init(void)
89509 {
89510 #ifdef CONFIG_DEBUG_SLAB_LEAK
89511- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
89512+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
89513 #endif
89514 return 0;
89515 }
89516 module_init(slab_proc_init);
89517 #endif
89518
89519+bool is_usercopy_object(const void *ptr)
89520+{
89521+ struct page *page;
89522+ struct kmem_cache *cachep;
89523+
89524+ if (ZERO_OR_NULL_PTR(ptr))
89525+ return false;
89526+
89527+ if (!slab_is_available())
89528+ return false;
89529+
89530+ if (!virt_addr_valid(ptr))
89531+ return false;
89532+
89533+ page = virt_to_head_page(ptr);
89534+
89535+ if (!PageSlab(page))
89536+ return false;
89537+
89538+ cachep = page->slab_cache;
89539+ return cachep->flags & SLAB_USERCOPY;
89540+}
89541+
89542+#ifdef CONFIG_PAX_USERCOPY
89543+const char *check_heap_object(const void *ptr, unsigned long n)
89544+{
89545+ struct page *page;
89546+ struct kmem_cache *cachep;
89547+ struct slab *slabp;
89548+ unsigned int objnr;
89549+ unsigned long offset;
89550+
89551+ if (ZERO_OR_NULL_PTR(ptr))
89552+ return "<null>";
89553+
89554+ if (!virt_addr_valid(ptr))
89555+ return NULL;
89556+
89557+ page = virt_to_head_page(ptr);
89558+
89559+ if (!PageSlab(page))
89560+ return NULL;
89561+
89562+ cachep = page->slab_cache;
89563+ if (!(cachep->flags & SLAB_USERCOPY))
89564+ return cachep->name;
89565+
89566+ slabp = page->slab_page;
89567+ objnr = obj_to_index(cachep, slabp, ptr);
89568+ BUG_ON(objnr >= cachep->num);
89569+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
89570+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
89571+ return NULL;
89572+
89573+ return cachep->name;
89574+}
89575+#endif
89576+
89577 /**
89578 * ksize - get the actual amount of memory allocated for a given object
89579 * @objp: Pointer to the object
89580diff --git a/mm/slab.h b/mm/slab.h
89581index a535033..2f98fe5 100644
89582--- a/mm/slab.h
89583+++ b/mm/slab.h
89584@@ -32,6 +32,15 @@ extern struct list_head slab_caches;
89585 /* The slab cache that manages slab cache information */
89586 extern struct kmem_cache *kmem_cache;
89587
89588+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89589+#ifdef CONFIG_X86_64
89590+#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
89591+#else
89592+#define PAX_MEMORY_SANITIZE_VALUE '\xff'
89593+#endif
89594+extern bool pax_sanitize_slab;
89595+#endif
89596+
89597 unsigned long calculate_alignment(unsigned long flags,
89598 unsigned long align, unsigned long size);
89599
89600@@ -67,7 +76,8 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
89601
89602 /* Legal flag mask for kmem_cache_create(), for various configurations */
89603 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
89604- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
89605+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
89606+ SLAB_USERCOPY | SLAB_NO_SANITIZE)
89607
89608 #if defined(CONFIG_DEBUG_SLAB)
89609 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
89610@@ -231,6 +241,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
89611 return s;
89612
89613 page = virt_to_head_page(x);
89614+
89615+ BUG_ON(!PageSlab(page));
89616+
89617 cachep = page->slab_cache;
89618 if (slab_equal_or_root(cachep, s))
89619 return cachep;
89620diff --git a/mm/slab_common.c b/mm/slab_common.c
89621index 538bade..36fed99 100644
89622--- a/mm/slab_common.c
89623+++ b/mm/slab_common.c
89624@@ -22,11 +22,22 @@
89625
89626 #include "slab.h"
89627
89628-enum slab_state slab_state;
89629+enum slab_state slab_state __read_only;
89630 LIST_HEAD(slab_caches);
89631 DEFINE_MUTEX(slab_mutex);
89632 struct kmem_cache *kmem_cache;
89633
89634+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89635+bool pax_sanitize_slab __read_only = true;
89636+static int __init pax_sanitize_slab_setup(char *str)
89637+{
89638+ pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
89639+ printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
89640+ return 1;
89641+}
89642+__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
89643+#endif
89644+
89645 #ifdef CONFIG_DEBUG_VM
89646 static int kmem_cache_sanity_check(struct mem_cgroup *memcg, const char *name,
89647 size_t size)
89648@@ -209,7 +220,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
89649
89650 err = __kmem_cache_create(s, flags);
89651 if (!err) {
89652- s->refcount = 1;
89653+ atomic_set(&s->refcount, 1);
89654 list_add(&s->list, &slab_caches);
89655 memcg_cache_list_add(memcg, s);
89656 } else {
89657@@ -255,8 +266,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
89658
89659 get_online_cpus();
89660 mutex_lock(&slab_mutex);
89661- s->refcount--;
89662- if (!s->refcount) {
89663+ if (atomic_dec_and_test(&s->refcount)) {
89664 list_del(&s->list);
89665
89666 if (!__kmem_cache_shutdown(s)) {
89667@@ -302,7 +312,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
89668 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
89669 name, size, err);
89670
89671- s->refcount = -1; /* Exempt from merging for now */
89672+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
89673 }
89674
89675 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
89676@@ -315,7 +325,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
89677
89678 create_boot_cache(s, name, size, flags);
89679 list_add(&s->list, &slab_caches);
89680- s->refcount = 1;
89681+ atomic_set(&s->refcount, 1);
89682 return s;
89683 }
89684
89685@@ -327,6 +337,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
89686 EXPORT_SYMBOL(kmalloc_dma_caches);
89687 #endif
89688
89689+#ifdef CONFIG_PAX_USERCOPY_SLABS
89690+struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
89691+EXPORT_SYMBOL(kmalloc_usercopy_caches);
89692+#endif
89693+
89694 /*
89695 * Conversion table for small slabs sizes / 8 to the index in the
89696 * kmalloc array. This is necessary for slabs < 192 since we have non power
89697@@ -391,6 +406,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
89698 return kmalloc_dma_caches[index];
89699
89700 #endif
89701+
89702+#ifdef CONFIG_PAX_USERCOPY_SLABS
89703+ if (unlikely((flags & GFP_USERCOPY)))
89704+ return kmalloc_usercopy_caches[index];
89705+
89706+#endif
89707+
89708 return kmalloc_caches[index];
89709 }
89710
89711@@ -447,7 +469,7 @@ void __init create_kmalloc_caches(unsigned long flags)
89712 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
89713 if (!kmalloc_caches[i]) {
89714 kmalloc_caches[i] = create_kmalloc_cache(NULL,
89715- 1 << i, flags);
89716+ 1 << i, SLAB_USERCOPY | flags);
89717 }
89718
89719 /*
89720@@ -456,10 +478,10 @@ void __init create_kmalloc_caches(unsigned long flags)
89721 * earlier power of two caches
89722 */
89723 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
89724- kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
89725+ kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
89726
89727 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
89728- kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
89729+ kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
89730 }
89731
89732 /* Kmalloc array is now usable */
89733@@ -492,6 +514,23 @@ void __init create_kmalloc_caches(unsigned long flags)
89734 }
89735 }
89736 #endif
89737+
89738+#ifdef CONFIG_PAX_USERCOPY_SLABS
89739+ for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
89740+ struct kmem_cache *s = kmalloc_caches[i];
89741+
89742+ if (s) {
89743+ int size = kmalloc_size(i);
89744+ char *n = kasprintf(GFP_NOWAIT,
89745+ "usercopy-kmalloc-%d", size);
89746+
89747+ BUG_ON(!n);
89748+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
89749+ size, SLAB_USERCOPY | flags);
89750+ }
89751+ }
89752+#endif
89753+
89754 }
89755 #endif /* !CONFIG_SLOB */
89756
89757@@ -523,6 +562,9 @@ void print_slabinfo_header(struct seq_file *m)
89758 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
89759 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
89760 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
89761+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89762+ seq_puts(m, " : pax <sanitized> <not_sanitized>");
89763+#endif
89764 #endif
89765 seq_putc(m, '\n');
89766 }
89767diff --git a/mm/slob.c b/mm/slob.c
89768index 91bd3f2..e2f549e 100644
89769--- a/mm/slob.c
89770+++ b/mm/slob.c
89771@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
89772 /*
89773 * Return the size of a slob block.
89774 */
89775-static slobidx_t slob_units(slob_t *s)
89776+static slobidx_t slob_units(const slob_t *s)
89777 {
89778 if (s->units > 0)
89779 return s->units;
89780@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
89781 /*
89782 * Return the next free slob block pointer after this one.
89783 */
89784-static slob_t *slob_next(slob_t *s)
89785+static slob_t *slob_next(const slob_t *s)
89786 {
89787 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
89788 slobidx_t next;
89789@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
89790 /*
89791 * Returns true if s is the last free block in its page.
89792 */
89793-static int slob_last(slob_t *s)
89794+static int slob_last(const slob_t *s)
89795 {
89796 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
89797 }
89798
89799-static void *slob_new_pages(gfp_t gfp, int order, int node)
89800+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
89801 {
89802- void *page;
89803+ struct page *page;
89804
89805 #ifdef CONFIG_NUMA
89806 if (node != NUMA_NO_NODE)
89807@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
89808 if (!page)
89809 return NULL;
89810
89811- return page_address(page);
89812+ __SetPageSlab(page);
89813+ return page;
89814 }
89815
89816-static void slob_free_pages(void *b, int order)
89817+static void slob_free_pages(struct page *sp, int order)
89818 {
89819 if (current->reclaim_state)
89820 current->reclaim_state->reclaimed_slab += 1 << order;
89821- free_pages((unsigned long)b, order);
89822+ __ClearPageSlab(sp);
89823+ page_mapcount_reset(sp);
89824+ sp->private = 0;
89825+ __free_pages(sp, order);
89826 }
89827
89828 /*
89829@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
89830
89831 /* Not enough space: must allocate a new page */
89832 if (!b) {
89833- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
89834- if (!b)
89835+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
89836+ if (!sp)
89837 return NULL;
89838- sp = virt_to_page(b);
89839- __SetPageSlab(sp);
89840+ b = page_address(sp);
89841
89842 spin_lock_irqsave(&slob_lock, flags);
89843 sp->units = SLOB_UNITS(PAGE_SIZE);
89844 sp->freelist = b;
89845+ sp->private = 0;
89846 INIT_LIST_HEAD(&sp->list);
89847 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
89848 set_slob_page_free(sp, slob_list);
89849@@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
89850 if (slob_page_free(sp))
89851 clear_slob_page_free(sp);
89852 spin_unlock_irqrestore(&slob_lock, flags);
89853- __ClearPageSlab(sp);
89854- page_mapcount_reset(sp);
89855- slob_free_pages(b, 0);
89856+ slob_free_pages(sp, 0);
89857 return;
89858 }
89859
89860+#ifdef CONFIG_PAX_MEMORY_SANITIZE
89861+ if (pax_sanitize_slab)
89862+ memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
89863+#endif
89864+
89865 if (!slob_page_free(sp)) {
89866 /* This slob page is about to become partially free. Easy! */
89867 sp->units = units;
89868@@ -424,11 +431,10 @@ out:
89869 */
89870
89871 static __always_inline void *
89872-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
89873+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
89874 {
89875- unsigned int *m;
89876- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
89877- void *ret;
89878+ slob_t *m;
89879+ void *ret = NULL;
89880
89881 gfp &= gfp_allowed_mask;
89882
89883@@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
89884
89885 if (!m)
89886 return NULL;
89887- *m = size;
89888+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
89889+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
89890+ m[0].units = size;
89891+ m[1].units = align;
89892 ret = (void *)m + align;
89893
89894 trace_kmalloc_node(caller, ret,
89895 size, size + align, gfp, node);
89896 } else {
89897 unsigned int order = get_order(size);
89898+ struct page *page;
89899
89900 if (likely(order))
89901 gfp |= __GFP_COMP;
89902- ret = slob_new_pages(gfp, order, node);
89903+ page = slob_new_pages(gfp, order, node);
89904+ if (page) {
89905+ ret = page_address(page);
89906+ page->private = size;
89907+ }
89908
89909 trace_kmalloc_node(caller, ret,
89910 size, PAGE_SIZE << order, gfp, node);
89911 }
89912
89913- kmemleak_alloc(ret, size, 1, gfp);
89914+ return ret;
89915+}
89916+
89917+static __always_inline void *
89918+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
89919+{
89920+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
89921+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
89922+
89923+ if (!ZERO_OR_NULL_PTR(ret))
89924+ kmemleak_alloc(ret, size, 1, gfp);
89925 return ret;
89926 }
89927
89928@@ -493,34 +517,112 @@ void kfree(const void *block)
89929 return;
89930 kmemleak_free(block);
89931
89932+ VM_BUG_ON(!virt_addr_valid(block));
89933 sp = virt_to_page(block);
89934- if (PageSlab(sp)) {
89935+ VM_BUG_ON(!PageSlab(sp));
89936+ if (!sp->private) {
89937 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
89938- unsigned int *m = (unsigned int *)(block - align);
89939- slob_free(m, *m + align);
89940- } else
89941+ slob_t *m = (slob_t *)(block - align);
89942+ slob_free(m, m[0].units + align);
89943+ } else {
89944+ __ClearPageSlab(sp);
89945+ page_mapcount_reset(sp);
89946+ sp->private = 0;
89947 __free_pages(sp, compound_order(sp));
89948+ }
89949 }
89950 EXPORT_SYMBOL(kfree);
89951
89952+bool is_usercopy_object(const void *ptr)
89953+{
89954+ if (!slab_is_available())
89955+ return false;
89956+
89957+ // PAX: TODO
89958+
89959+ return false;
89960+}
89961+
89962+#ifdef CONFIG_PAX_USERCOPY
89963+const char *check_heap_object(const void *ptr, unsigned long n)
89964+{
89965+ struct page *page;
89966+ const slob_t *free;
89967+ const void *base;
89968+ unsigned long flags;
89969+
89970+ if (ZERO_OR_NULL_PTR(ptr))
89971+ return "<null>";
89972+
89973+ if (!virt_addr_valid(ptr))
89974+ return NULL;
89975+
89976+ page = virt_to_head_page(ptr);
89977+ if (!PageSlab(page))
89978+ return NULL;
89979+
89980+ if (page->private) {
89981+ base = page;
89982+ if (base <= ptr && n <= page->private - (ptr - base))
89983+ return NULL;
89984+ return "<slob>";
89985+ }
89986+
89987+ /* some tricky double walking to find the chunk */
89988+ spin_lock_irqsave(&slob_lock, flags);
89989+ base = (void *)((unsigned long)ptr & PAGE_MASK);
89990+ free = page->freelist;
89991+
89992+ while (!slob_last(free) && (void *)free <= ptr) {
89993+ base = free + slob_units(free);
89994+ free = slob_next(free);
89995+ }
89996+
89997+ while (base < (void *)free) {
89998+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
89999+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
90000+ int offset;
90001+
90002+ if (ptr < base + align)
90003+ break;
90004+
90005+ offset = ptr - base - align;
90006+ if (offset >= m) {
90007+ base += size;
90008+ continue;
90009+ }
90010+
90011+ if (n > m - offset)
90012+ break;
90013+
90014+ spin_unlock_irqrestore(&slob_lock, flags);
90015+ return NULL;
90016+ }
90017+
90018+ spin_unlock_irqrestore(&slob_lock, flags);
90019+ return "<slob>";
90020+}
90021+#endif
90022+
90023 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
90024 size_t ksize(const void *block)
90025 {
90026 struct page *sp;
90027 int align;
90028- unsigned int *m;
90029+ slob_t *m;
90030
90031 BUG_ON(!block);
90032 if (unlikely(block == ZERO_SIZE_PTR))
90033 return 0;
90034
90035 sp = virt_to_page(block);
90036- if (unlikely(!PageSlab(sp)))
90037- return PAGE_SIZE << compound_order(sp);
90038+ VM_BUG_ON(!PageSlab(sp));
90039+ if (sp->private)
90040+ return sp->private;
90041
90042 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
90043- m = (unsigned int *)(block - align);
90044- return SLOB_UNITS(*m) * SLOB_UNIT;
90045+ m = (slob_t *)(block - align);
90046+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
90047 }
90048 EXPORT_SYMBOL(ksize);
90049
90050@@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
90051
90052 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
90053 {
90054- void *b;
90055+ void *b = NULL;
90056
90057 flags &= gfp_allowed_mask;
90058
90059 lockdep_trace_alloc(flags);
90060
90061+#ifdef CONFIG_PAX_USERCOPY_SLABS
90062+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
90063+#else
90064 if (c->size < PAGE_SIZE) {
90065 b = slob_alloc(c->size, flags, c->align, node);
90066 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
90067 SLOB_UNITS(c->size) * SLOB_UNIT,
90068 flags, node);
90069 } else {
90070- b = slob_new_pages(flags, get_order(c->size), node);
90071+ struct page *sp;
90072+
90073+ sp = slob_new_pages(flags, get_order(c->size), node);
90074+ if (sp) {
90075+ b = page_address(sp);
90076+ sp->private = c->size;
90077+ }
90078 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
90079 PAGE_SIZE << get_order(c->size),
90080 flags, node);
90081 }
90082+#endif
90083
90084 if (b && c->ctor)
90085 c->ctor(b);
90086@@ -564,10 +676,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
90087
90088 static void __kmem_cache_free(void *b, int size)
90089 {
90090- if (size < PAGE_SIZE)
90091+ struct page *sp;
90092+
90093+ sp = virt_to_page(b);
90094+ BUG_ON(!PageSlab(sp));
90095+ if (!sp->private)
90096 slob_free(b, size);
90097 else
90098- slob_free_pages(b, get_order(size));
90099+ slob_free_pages(sp, get_order(size));
90100 }
90101
90102 static void kmem_rcu_free(struct rcu_head *head)
90103@@ -580,17 +696,31 @@ static void kmem_rcu_free(struct rcu_head *head)
90104
90105 void kmem_cache_free(struct kmem_cache *c, void *b)
90106 {
90107+ int size = c->size;
90108+
90109+#ifdef CONFIG_PAX_USERCOPY_SLABS
90110+ if (size + c->align < PAGE_SIZE) {
90111+ size += c->align;
90112+ b -= c->align;
90113+ }
90114+#endif
90115+
90116 kmemleak_free_recursive(b, c->flags);
90117 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
90118 struct slob_rcu *slob_rcu;
90119- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
90120- slob_rcu->size = c->size;
90121+ slob_rcu = b + (size - sizeof(struct slob_rcu));
90122+ slob_rcu->size = size;
90123 call_rcu(&slob_rcu->head, kmem_rcu_free);
90124 } else {
90125- __kmem_cache_free(b, c->size);
90126+ __kmem_cache_free(b, size);
90127 }
90128
90129+#ifdef CONFIG_PAX_USERCOPY_SLABS
90130+ trace_kfree(_RET_IP_, b);
90131+#else
90132 trace_kmem_cache_free(_RET_IP_, b);
90133+#endif
90134+
90135 }
90136 EXPORT_SYMBOL(kmem_cache_free);
90137
90138diff --git a/mm/slub.c b/mm/slub.c
90139index e3ba1f2..bd45dac 100644
90140--- a/mm/slub.c
90141+++ b/mm/slub.c
90142@@ -207,7 +207,7 @@ struct track {
90143
90144 enum track_item { TRACK_ALLOC, TRACK_FREE };
90145
90146-#ifdef CONFIG_SYSFS
90147+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90148 static int sysfs_slab_add(struct kmem_cache *);
90149 static int sysfs_slab_alias(struct kmem_cache *, const char *);
90150 static void sysfs_slab_remove(struct kmem_cache *);
90151@@ -528,7 +528,7 @@ static void print_track(const char *s, struct track *t)
90152 if (!t->addr)
90153 return;
90154
90155- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
90156+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
90157 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
90158 #ifdef CONFIG_STACKTRACE
90159 {
90160@@ -2609,6 +2609,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
90161
90162 slab_free_hook(s, x);
90163
90164+#ifdef CONFIG_PAX_MEMORY_SANITIZE
90165+ if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
90166+ memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
90167+ if (s->ctor)
90168+ s->ctor(x);
90169+ }
90170+#endif
90171+
90172 redo:
90173 /*
90174 * Determine the currently cpus per cpu slab.
90175@@ -2676,7 +2684,7 @@ static int slub_min_objects;
90176 * Merge control. If this is set then no merging of slab caches will occur.
90177 * (Could be removed. This was introduced to pacify the merge skeptics.)
90178 */
90179-static int slub_nomerge;
90180+static int slub_nomerge = 1;
90181
90182 /*
90183 * Calculate the order of allocation given an slab object size.
90184@@ -2953,6 +2961,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
90185 s->inuse = size;
90186
90187 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
90188+#ifdef CONFIG_PAX_MEMORY_SANITIZE
90189+ (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
90190+#endif
90191 s->ctor)) {
90192 /*
90193 * Relocate free pointer after the object if it is not
90194@@ -3298,6 +3309,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
90195 EXPORT_SYMBOL(__kmalloc_node);
90196 #endif
90197
90198+bool is_usercopy_object(const void *ptr)
90199+{
90200+ struct page *page;
90201+ struct kmem_cache *s;
90202+
90203+ if (ZERO_OR_NULL_PTR(ptr))
90204+ return false;
90205+
90206+ if (!slab_is_available())
90207+ return false;
90208+
90209+ if (!virt_addr_valid(ptr))
90210+ return false;
90211+
90212+ page = virt_to_head_page(ptr);
90213+
90214+ if (!PageSlab(page))
90215+ return false;
90216+
90217+ s = page->slab_cache;
90218+ return s->flags & SLAB_USERCOPY;
90219+}
90220+
90221+#ifdef CONFIG_PAX_USERCOPY
90222+const char *check_heap_object(const void *ptr, unsigned long n)
90223+{
90224+ struct page *page;
90225+ struct kmem_cache *s;
90226+ unsigned long offset;
90227+
90228+ if (ZERO_OR_NULL_PTR(ptr))
90229+ return "<null>";
90230+
90231+ if (!virt_addr_valid(ptr))
90232+ return NULL;
90233+
90234+ page = virt_to_head_page(ptr);
90235+
90236+ if (!PageSlab(page))
90237+ return NULL;
90238+
90239+ s = page->slab_cache;
90240+ if (!(s->flags & SLAB_USERCOPY))
90241+ return s->name;
90242+
90243+ offset = (ptr - page_address(page)) % s->size;
90244+ if (offset <= s->object_size && n <= s->object_size - offset)
90245+ return NULL;
90246+
90247+ return s->name;
90248+}
90249+#endif
90250+
90251 size_t ksize(const void *object)
90252 {
90253 struct page *page;
90254@@ -3362,6 +3426,7 @@ void kfree(const void *x)
90255 if (unlikely(ZERO_OR_NULL_PTR(x)))
90256 return;
90257
90258+ VM_BUG_ON(!virt_addr_valid(x));
90259 page = virt_to_head_page(x);
90260 if (unlikely(!PageSlab(page))) {
90261 BUG_ON(!PageCompound(page));
90262@@ -3667,7 +3732,7 @@ static int slab_unmergeable(struct kmem_cache *s)
90263 /*
90264 * We may have set a slab to be unmergeable during bootstrap.
90265 */
90266- if (s->refcount < 0)
90267+ if (atomic_read(&s->refcount) < 0)
90268 return 1;
90269
90270 return 0;
90271@@ -3725,7 +3790,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
90272
90273 s = find_mergeable(memcg, size, align, flags, name, ctor);
90274 if (s) {
90275- s->refcount++;
90276+ atomic_inc(&s->refcount);
90277 /*
90278 * Adjust the object sizes so that we clear
90279 * the complete object on kzalloc.
90280@@ -3734,7 +3799,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
90281 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
90282
90283 if (sysfs_slab_alias(s, name)) {
90284- s->refcount--;
90285+ atomic_dec(&s->refcount);
90286 s = NULL;
90287 }
90288 }
90289@@ -3854,7 +3919,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
90290 }
90291 #endif
90292
90293-#ifdef CONFIG_SYSFS
90294+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90295 static int count_inuse(struct page *page)
90296 {
90297 return page->inuse;
90298@@ -4241,12 +4306,12 @@ static void resiliency_test(void)
90299 validate_slab_cache(kmalloc_caches[9]);
90300 }
90301 #else
90302-#ifdef CONFIG_SYSFS
90303+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90304 static void resiliency_test(void) {};
90305 #endif
90306 #endif
90307
90308-#ifdef CONFIG_SYSFS
90309+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90310 enum slab_stat_type {
90311 SL_ALL, /* All slabs */
90312 SL_PARTIAL, /* Only partially allocated slabs */
90313@@ -4490,7 +4555,7 @@ SLAB_ATTR_RO(ctor);
90314
90315 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
90316 {
90317- return sprintf(buf, "%d\n", s->refcount - 1);
90318+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
90319 }
90320 SLAB_ATTR_RO(aliases);
90321
90322@@ -4578,6 +4643,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
90323 SLAB_ATTR_RO(cache_dma);
90324 #endif
90325
90326+#ifdef CONFIG_PAX_USERCOPY_SLABS
90327+static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
90328+{
90329+ return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
90330+}
90331+SLAB_ATTR_RO(usercopy);
90332+#endif
90333+
90334 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
90335 {
90336 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
90337@@ -4912,6 +4985,9 @@ static struct attribute *slab_attrs[] = {
90338 #ifdef CONFIG_ZONE_DMA
90339 &cache_dma_attr.attr,
90340 #endif
90341+#ifdef CONFIG_PAX_USERCOPY_SLABS
90342+ &usercopy_attr.attr,
90343+#endif
90344 #ifdef CONFIG_NUMA
90345 &remote_node_defrag_ratio_attr.attr,
90346 #endif
90347@@ -5143,6 +5219,7 @@ static char *create_unique_id(struct kmem_cache *s)
90348 return name;
90349 }
90350
90351+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90352 static int sysfs_slab_add(struct kmem_cache *s)
90353 {
90354 int err;
90355@@ -5166,7 +5243,7 @@ static int sysfs_slab_add(struct kmem_cache *s)
90356 }
90357
90358 s->kobj.kset = slab_kset;
90359- err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, name);
90360+ err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name);
90361 if (err) {
90362 kobject_put(&s->kobj);
90363 return err;
90364@@ -5200,6 +5277,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
90365 kobject_del(&s->kobj);
90366 kobject_put(&s->kobj);
90367 }
90368+#endif
90369
90370 /*
90371 * Need to buffer aliases during bootup until sysfs becomes
90372@@ -5213,6 +5291,7 @@ struct saved_alias {
90373
90374 static struct saved_alias *alias_list;
90375
90376+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
90377 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
90378 {
90379 struct saved_alias *al;
90380@@ -5235,6 +5314,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
90381 alias_list = al;
90382 return 0;
90383 }
90384+#endif
90385
90386 static int __init slab_sysfs_init(void)
90387 {
90388diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
90389index 27eeab3..7c3f7f2 100644
90390--- a/mm/sparse-vmemmap.c
90391+++ b/mm/sparse-vmemmap.c
90392@@ -130,7 +130,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
90393 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
90394 if (!p)
90395 return NULL;
90396- pud_populate(&init_mm, pud, p);
90397+ pud_populate_kernel(&init_mm, pud, p);
90398 }
90399 return pud;
90400 }
90401@@ -142,7 +142,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
90402 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
90403 if (!p)
90404 return NULL;
90405- pgd_populate(&init_mm, pgd, p);
90406+ pgd_populate_kernel(&init_mm, pgd, p);
90407 }
90408 return pgd;
90409 }
90410diff --git a/mm/sparse.c b/mm/sparse.c
90411index 308d503..3dbbd04 100644
90412--- a/mm/sparse.c
90413+++ b/mm/sparse.c
90414@@ -764,7 +764,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
90415
90416 for (i = 0; i < PAGES_PER_SECTION; i++) {
90417 if (PageHWPoison(&memmap[i])) {
90418- atomic_long_sub(1, &num_poisoned_pages);
90419+ atomic_long_sub_unchecked(1, &num_poisoned_pages);
90420 ClearPageHWPoison(&memmap[i]);
90421 }
90422 }
90423diff --git a/mm/swap.c b/mm/swap.c
90424index 62b78a6..0bcf28f 100644
90425--- a/mm/swap.c
90426+++ b/mm/swap.c
90427@@ -31,6 +31,7 @@
90428 #include <linux/memcontrol.h>
90429 #include <linux/gfp.h>
90430 #include <linux/uio.h>
90431+#include <linux/hugetlb.h>
90432
90433 #include "internal.h"
90434
90435@@ -76,6 +77,8 @@ static void __put_compound_page(struct page *page)
90436
90437 __page_cache_release(page);
90438 dtor = get_compound_page_dtor(page);
90439+ if (!PageHuge(page))
90440+ BUG_ON(dtor != free_compound_page);
90441 (*dtor)(page);
90442 }
90443
90444diff --git a/mm/swapfile.c b/mm/swapfile.c
90445index 6cf2e60..d204b3e 100644
90446--- a/mm/swapfile.c
90447+++ b/mm/swapfile.c
90448@@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
90449
90450 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
90451 /* Activity counter to indicate that a swapon or swapoff has occurred */
90452-static atomic_t proc_poll_event = ATOMIC_INIT(0);
90453+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
90454
90455 static inline unsigned char swap_count(unsigned char ent)
90456 {
90457@@ -1699,7 +1699,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
90458 }
90459 filp_close(swap_file, NULL);
90460 err = 0;
90461- atomic_inc(&proc_poll_event);
90462+ atomic_inc_unchecked(&proc_poll_event);
90463 wake_up_interruptible(&proc_poll_wait);
90464
90465 out_dput:
90466@@ -1716,8 +1716,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
90467
90468 poll_wait(file, &proc_poll_wait, wait);
90469
90470- if (seq->poll_event != atomic_read(&proc_poll_event)) {
90471- seq->poll_event = atomic_read(&proc_poll_event);
90472+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
90473+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
90474 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
90475 }
90476
90477@@ -1815,7 +1815,7 @@ static int swaps_open(struct inode *inode, struct file *file)
90478 return ret;
90479
90480 seq = file->private_data;
90481- seq->poll_event = atomic_read(&proc_poll_event);
90482+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
90483 return 0;
90484 }
90485
90486@@ -2203,7 +2203,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
90487 (frontswap_map) ? "FS" : "");
90488
90489 mutex_unlock(&swapon_mutex);
90490- atomic_inc(&proc_poll_event);
90491+ atomic_inc_unchecked(&proc_poll_event);
90492 wake_up_interruptible(&proc_poll_wait);
90493
90494 if (S_ISREG(inode->i_mode))
90495diff --git a/mm/util.c b/mm/util.c
90496index 7441c41..c3de793 100644
90497--- a/mm/util.c
90498+++ b/mm/util.c
90499@@ -294,6 +294,12 @@ done:
90500 void arch_pick_mmap_layout(struct mm_struct *mm)
90501 {
90502 mm->mmap_base = TASK_UNMAPPED_BASE;
90503+
90504+#ifdef CONFIG_PAX_RANDMMAP
90505+ if (mm->pax_flags & MF_PAX_RANDMMAP)
90506+ mm->mmap_base += mm->delta_mmap;
90507+#endif
90508+
90509 mm->get_unmapped_area = arch_get_unmapped_area;
90510 }
90511 #endif
90512diff --git a/mm/vmalloc.c b/mm/vmalloc.c
90513index 13a5495..6707d97 100644
90514--- a/mm/vmalloc.c
90515+++ b/mm/vmalloc.c
90516@@ -59,8 +59,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
90517
90518 pte = pte_offset_kernel(pmd, addr);
90519 do {
90520- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
90521- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
90522+
90523+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
90524+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
90525+ BUG_ON(!pte_exec(*pte));
90526+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
90527+ continue;
90528+ }
90529+#endif
90530+
90531+ {
90532+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
90533+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
90534+ }
90535 } while (pte++, addr += PAGE_SIZE, addr != end);
90536 }
90537
90538@@ -120,16 +131,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
90539 pte = pte_alloc_kernel(pmd, addr);
90540 if (!pte)
90541 return -ENOMEM;
90542+
90543+ pax_open_kernel();
90544 do {
90545 struct page *page = pages[*nr];
90546
90547- if (WARN_ON(!pte_none(*pte)))
90548+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
90549+ if (pgprot_val(prot) & _PAGE_NX)
90550+#endif
90551+
90552+ if (!pte_none(*pte)) {
90553+ pax_close_kernel();
90554+ WARN_ON(1);
90555 return -EBUSY;
90556- if (WARN_ON(!page))
90557+ }
90558+ if (!page) {
90559+ pax_close_kernel();
90560+ WARN_ON(1);
90561 return -ENOMEM;
90562+ }
90563 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
90564 (*nr)++;
90565 } while (pte++, addr += PAGE_SIZE, addr != end);
90566+ pax_close_kernel();
90567 return 0;
90568 }
90569
90570@@ -139,7 +163,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
90571 pmd_t *pmd;
90572 unsigned long next;
90573
90574- pmd = pmd_alloc(&init_mm, pud, addr);
90575+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
90576 if (!pmd)
90577 return -ENOMEM;
90578 do {
90579@@ -156,7 +180,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
90580 pud_t *pud;
90581 unsigned long next;
90582
90583- pud = pud_alloc(&init_mm, pgd, addr);
90584+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
90585 if (!pud)
90586 return -ENOMEM;
90587 do {
90588@@ -216,6 +240,12 @@ int is_vmalloc_or_module_addr(const void *x)
90589 if (addr >= MODULES_VADDR && addr < MODULES_END)
90590 return 1;
90591 #endif
90592+
90593+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
90594+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
90595+ return 1;
90596+#endif
90597+
90598 return is_vmalloc_addr(x);
90599 }
90600
90601@@ -236,8 +266,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
90602
90603 if (!pgd_none(*pgd)) {
90604 pud_t *pud = pud_offset(pgd, addr);
90605+#ifdef CONFIG_X86
90606+ if (!pud_large(*pud))
90607+#endif
90608 if (!pud_none(*pud)) {
90609 pmd_t *pmd = pmd_offset(pud, addr);
90610+#ifdef CONFIG_X86
90611+ if (!pmd_large(*pmd))
90612+#endif
90613 if (!pmd_none(*pmd)) {
90614 pte_t *ptep, pte;
90615
90616@@ -339,7 +375,7 @@ static void purge_vmap_area_lazy(void);
90617 * Allocate a region of KVA of the specified size and alignment, within the
90618 * vstart and vend.
90619 */
90620-static struct vmap_area *alloc_vmap_area(unsigned long size,
90621+static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
90622 unsigned long align,
90623 unsigned long vstart, unsigned long vend,
90624 int node, gfp_t gfp_mask)
90625@@ -1308,6 +1344,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
90626 struct vm_struct *area;
90627
90628 BUG_ON(in_interrupt());
90629+
90630+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
90631+ if (flags & VM_KERNEXEC) {
90632+ if (start != VMALLOC_START || end != VMALLOC_END)
90633+ return NULL;
90634+ start = (unsigned long)MODULES_EXEC_VADDR;
90635+ end = (unsigned long)MODULES_EXEC_END;
90636+ }
90637+#endif
90638+
90639 if (flags & VM_IOREMAP)
90640 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
90641
90642@@ -1533,6 +1579,11 @@ void *vmap(struct page **pages, unsigned int count,
90643 if (count > totalram_pages)
90644 return NULL;
90645
90646+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
90647+ if (!(pgprot_val(prot) & _PAGE_NX))
90648+ flags |= VM_KERNEXEC;
90649+#endif
90650+
90651 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
90652 __builtin_return_address(0));
90653 if (!area)
90654@@ -1634,6 +1685,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
90655 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
90656 goto fail;
90657
90658+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
90659+ if (!(pgprot_val(prot) & _PAGE_NX))
90660+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
90661+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
90662+ else
90663+#endif
90664+
90665 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
90666 start, end, node, gfp_mask, caller);
90667 if (!area)
90668@@ -1810,10 +1868,9 @@ EXPORT_SYMBOL(vzalloc_node);
90669 * For tight control over page level allocator and protection flags
90670 * use __vmalloc() instead.
90671 */
90672-
90673 void *vmalloc_exec(unsigned long size)
90674 {
90675- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
90676+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
90677 NUMA_NO_NODE, __builtin_return_address(0));
90678 }
90679
90680@@ -2120,6 +2177,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
90681 {
90682 struct vm_struct *area;
90683
90684+ BUG_ON(vma->vm_mirror);
90685+
90686 size = PAGE_ALIGN(size);
90687
90688 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
90689@@ -2605,7 +2664,11 @@ static int s_show(struct seq_file *m, void *p)
90690 v->addr, v->addr + v->size, v->size);
90691
90692 if (v->caller)
90693+#ifdef CONFIG_GRKERNSEC_HIDESYM
90694+ seq_printf(m, " %pK", v->caller);
90695+#else
90696 seq_printf(m, " %pS", v->caller);
90697+#endif
90698
90699 if (v->nr_pages)
90700 seq_printf(m, " pages=%d", v->nr_pages);
90701diff --git a/mm/vmstat.c b/mm/vmstat.c
90702index 20c2ef4..15e7ab7 100644
90703--- a/mm/vmstat.c
90704+++ b/mm/vmstat.c
90705@@ -76,7 +76,7 @@ void vm_events_fold_cpu(int cpu)
90706 *
90707 * vm_stat contains the global counters
90708 */
90709-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
90710+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
90711 EXPORT_SYMBOL(vm_stat);
90712
90713 #ifdef CONFIG_SMP
90714@@ -452,7 +452,7 @@ void refresh_cpu_vm_stats(int cpu)
90715 v = p->vm_stat_diff[i];
90716 p->vm_stat_diff[i] = 0;
90717 local_irq_restore(flags);
90718- atomic_long_add(v, &zone->vm_stat[i]);
90719+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
90720 global_diff[i] += v;
90721 #ifdef CONFIG_NUMA
90722 /* 3 seconds idle till flush */
90723@@ -490,7 +490,7 @@ void refresh_cpu_vm_stats(int cpu)
90724
90725 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
90726 if (global_diff[i])
90727- atomic_long_add(global_diff[i], &vm_stat[i]);
90728+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
90729 }
90730
90731 /*
90732@@ -505,8 +505,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
90733 if (pset->vm_stat_diff[i]) {
90734 int v = pset->vm_stat_diff[i];
90735 pset->vm_stat_diff[i] = 0;
90736- atomic_long_add(v, &zone->vm_stat[i]);
90737- atomic_long_add(v, &vm_stat[i]);
90738+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
90739+ atomic_long_add_unchecked(v, &vm_stat[i]);
90740 }
90741 }
90742 #endif
90743@@ -1241,10 +1241,20 @@ static int __init setup_vmstat(void)
90744 start_cpu_timer(cpu);
90745 #endif
90746 #ifdef CONFIG_PROC_FS
90747- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
90748- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
90749- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
90750- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
90751+ {
90752+ mode_t gr_mode = S_IRUGO;
90753+#ifdef CONFIG_GRKERNSEC_PROC_ADD
90754+ gr_mode = S_IRUSR;
90755+#endif
90756+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
90757+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
90758+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
90759+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
90760+#else
90761+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
90762+#endif
90763+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
90764+ }
90765 #endif
90766 return 0;
90767 }
90768diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
90769index 2fb2d88..8c06e40 100644
90770--- a/net/8021q/vlan.c
90771+++ b/net/8021q/vlan.c
90772@@ -469,7 +469,7 @@ out:
90773 return NOTIFY_DONE;
90774 }
90775
90776-static struct notifier_block vlan_notifier_block __read_mostly = {
90777+static struct notifier_block vlan_notifier_block = {
90778 .notifier_call = vlan_device_event,
90779 };
90780
90781@@ -544,8 +544,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
90782 err = -EPERM;
90783 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
90784 break;
90785- if ((args.u.name_type >= 0) &&
90786- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
90787+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
90788 struct vlan_net *vn;
90789
90790 vn = net_generic(net, vlan_net_id);
90791diff --git a/net/9p/mod.c b/net/9p/mod.c
90792index 6ab36ae..6f1841b 100644
90793--- a/net/9p/mod.c
90794+++ b/net/9p/mod.c
90795@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
90796 void v9fs_register_trans(struct p9_trans_module *m)
90797 {
90798 spin_lock(&v9fs_trans_lock);
90799- list_add_tail(&m->list, &v9fs_trans_list);
90800+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
90801 spin_unlock(&v9fs_trans_lock);
90802 }
90803 EXPORT_SYMBOL(v9fs_register_trans);
90804@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
90805 void v9fs_unregister_trans(struct p9_trans_module *m)
90806 {
90807 spin_lock(&v9fs_trans_lock);
90808- list_del_init(&m->list);
90809+ pax_list_del_init((struct list_head *)&m->list);
90810 spin_unlock(&v9fs_trans_lock);
90811 }
90812 EXPORT_SYMBOL(v9fs_unregister_trans);
90813diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
90814index 3ffda1b..fceac96 100644
90815--- a/net/9p/trans_fd.c
90816+++ b/net/9p/trans_fd.c
90817@@ -432,7 +432,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
90818 oldfs = get_fs();
90819 set_fs(get_ds());
90820 /* The cast to a user pointer is valid due to the set_fs() */
90821- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
90822+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
90823 set_fs(oldfs);
90824
90825 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
90826diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
90827index 876fbe8..8bbea9f 100644
90828--- a/net/atm/atm_misc.c
90829+++ b/net/atm/atm_misc.c
90830@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
90831 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
90832 return 1;
90833 atm_return(vcc, truesize);
90834- atomic_inc(&vcc->stats->rx_drop);
90835+ atomic_inc_unchecked(&vcc->stats->rx_drop);
90836 return 0;
90837 }
90838 EXPORT_SYMBOL(atm_charge);
90839@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
90840 }
90841 }
90842 atm_return(vcc, guess);
90843- atomic_inc(&vcc->stats->rx_drop);
90844+ atomic_inc_unchecked(&vcc->stats->rx_drop);
90845 return NULL;
90846 }
90847 EXPORT_SYMBOL(atm_alloc_charge);
90848@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
90849
90850 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
90851 {
90852-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
90853+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
90854 __SONET_ITEMS
90855 #undef __HANDLE_ITEM
90856 }
90857@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
90858
90859 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
90860 {
90861-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
90862+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
90863 __SONET_ITEMS
90864 #undef __HANDLE_ITEM
90865 }
90866diff --git a/net/atm/lec.h b/net/atm/lec.h
90867index 4149db1..f2ab682 100644
90868--- a/net/atm/lec.h
90869+++ b/net/atm/lec.h
90870@@ -48,7 +48,7 @@ struct lane2_ops {
90871 const u8 *tlvs, u32 sizeoftlvs);
90872 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
90873 const u8 *tlvs, u32 sizeoftlvs);
90874-};
90875+} __no_const;
90876
90877 /*
90878 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
90879diff --git a/net/atm/proc.c b/net/atm/proc.c
90880index bbb6461..cf04016 100644
90881--- a/net/atm/proc.c
90882+++ b/net/atm/proc.c
90883@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
90884 const struct k_atm_aal_stats *stats)
90885 {
90886 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
90887- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
90888- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
90889- atomic_read(&stats->rx_drop));
90890+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
90891+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
90892+ atomic_read_unchecked(&stats->rx_drop));
90893 }
90894
90895 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
90896diff --git a/net/atm/resources.c b/net/atm/resources.c
90897index 0447d5d..3cf4728 100644
90898--- a/net/atm/resources.c
90899+++ b/net/atm/resources.c
90900@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
90901 static void copy_aal_stats(struct k_atm_aal_stats *from,
90902 struct atm_aal_stats *to)
90903 {
90904-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
90905+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
90906 __AAL_STAT_ITEMS
90907 #undef __HANDLE_ITEM
90908 }
90909@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
90910 static void subtract_aal_stats(struct k_atm_aal_stats *from,
90911 struct atm_aal_stats *to)
90912 {
90913-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
90914+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
90915 __AAL_STAT_ITEMS
90916 #undef __HANDLE_ITEM
90917 }
90918diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
90919index 919a5ce..cc6b444 100644
90920--- a/net/ax25/sysctl_net_ax25.c
90921+++ b/net/ax25/sysctl_net_ax25.c
90922@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
90923 {
90924 char path[sizeof("net/ax25/") + IFNAMSIZ];
90925 int k;
90926- struct ctl_table *table;
90927+ ctl_table_no_const *table;
90928
90929 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
90930 if (!table)
90931diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
90932index 62da527..aa27535 100644
90933--- a/net/batman-adv/bat_iv_ogm.c
90934+++ b/net/batman-adv/bat_iv_ogm.c
90935@@ -120,7 +120,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
90936
90937 /* randomize initial seqno to avoid collision */
90938 get_random_bytes(&random_seqno, sizeof(random_seqno));
90939- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
90940+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
90941
90942 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
90943 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
90944@@ -701,9 +701,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
90945 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
90946
90947 /* change sequence number to network order */
90948- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
90949+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
90950 batadv_ogm_packet->seqno = htonl(seqno);
90951- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
90952+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
90953
90954 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
90955 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
90956@@ -1109,7 +1109,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
90957 return;
90958
90959 /* could be changed by schedule_own_packet() */
90960- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
90961+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
90962
90963 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
90964 has_directlink_flag = 1;
90965diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
90966index c478e6b..469fd2f 100644
90967--- a/net/batman-adv/hard-interface.c
90968+++ b/net/batman-adv/hard-interface.c
90969@@ -453,7 +453,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
90970 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
90971 dev_add_pack(&hard_iface->batman_adv_ptype);
90972
90973- atomic_set(&hard_iface->frag_seqno, 1);
90974+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
90975 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
90976 hard_iface->net_dev->name);
90977
90978diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
90979index 0f04e1c..9c0ac11 100644
90980--- a/net/batman-adv/soft-interface.c
90981+++ b/net/batman-adv/soft-interface.c
90982@@ -260,7 +260,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
90983 primary_if->net_dev->dev_addr, ETH_ALEN);
90984
90985 /* set broadcast sequence number */
90986- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
90987+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
90988 bcast_packet->seqno = htonl(seqno);
90989
90990 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
90991@@ -479,7 +479,7 @@ static int batadv_softif_init_late(struct net_device *dev)
90992 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
90993
90994 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
90995- atomic_set(&bat_priv->bcast_seqno, 1);
90996+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
90997 atomic_set(&bat_priv->tt.vn, 0);
90998 atomic_set(&bat_priv->tt.local_changes, 0);
90999 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
91000diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
91001index b2c94e1..3d47e07 100644
91002--- a/net/batman-adv/types.h
91003+++ b/net/batman-adv/types.h
91004@@ -51,7 +51,7 @@
91005 struct batadv_hard_iface_bat_iv {
91006 unsigned char *ogm_buff;
91007 int ogm_buff_len;
91008- atomic_t ogm_seqno;
91009+ atomic_unchecked_t ogm_seqno;
91010 };
91011
91012 /**
91013@@ -76,7 +76,7 @@ struct batadv_hard_iface {
91014 int16_t if_num;
91015 char if_status;
91016 struct net_device *net_dev;
91017- atomic_t frag_seqno;
91018+ atomic_unchecked_t frag_seqno;
91019 uint8_t num_bcasts;
91020 struct kobject *hardif_obj;
91021 atomic_t refcount;
91022@@ -560,7 +560,7 @@ struct batadv_priv {
91023 #ifdef CONFIG_BATMAN_ADV_DEBUG
91024 atomic_t log_level;
91025 #endif
91026- atomic_t bcast_seqno;
91027+ atomic_unchecked_t bcast_seqno;
91028 atomic_t bcast_queue_left;
91029 atomic_t batman_queue_left;
91030 char num_ifaces;
91031diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
91032index 857e1b8..5ad07b2 100644
91033--- a/net/batman-adv/unicast.c
91034+++ b/net/batman-adv/unicast.c
91035@@ -270,7 +270,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
91036 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
91037 frag2->flags = large_tail;
91038
91039- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
91040+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
91041 frag1->seqno = htons(seqno - 1);
91042 frag2->seqno = htons(seqno);
91043
91044diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
91045index 9bd7d95..6c4884f 100644
91046--- a/net/bluetooth/hci_sock.c
91047+++ b/net/bluetooth/hci_sock.c
91048@@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
91049 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
91050 }
91051
91052- len = min_t(unsigned int, len, sizeof(uf));
91053+ len = min((size_t)len, sizeof(uf));
91054 if (copy_from_user(&uf, optval, len)) {
91055 err = -EFAULT;
91056 break;
91057diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
91058index 8c3499b..2661c6a 100644
91059--- a/net/bluetooth/l2cap_core.c
91060+++ b/net/bluetooth/l2cap_core.c
91061@@ -3510,8 +3510,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
91062 break;
91063
91064 case L2CAP_CONF_RFC:
91065- if (olen == sizeof(rfc))
91066- memcpy(&rfc, (void *)val, olen);
91067+ if (olen != sizeof(rfc))
91068+ break;
91069+
91070+ memcpy(&rfc, (void *)val, olen);
91071
91072 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
91073 rfc.mode != chan->mode)
91074diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
91075index 0098af8..fb5a31f 100644
91076--- a/net/bluetooth/l2cap_sock.c
91077+++ b/net/bluetooth/l2cap_sock.c
91078@@ -485,7 +485,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
91079 struct sock *sk = sock->sk;
91080 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
91081 struct l2cap_options opts;
91082- int len, err = 0;
91083+ int err = 0;
91084+ size_t len = optlen;
91085 u32 opt;
91086
91087 BT_DBG("sk %p", sk);
91088@@ -507,7 +508,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
91089 opts.max_tx = chan->max_tx;
91090 opts.txwin_size = chan->tx_win;
91091
91092- len = min_t(unsigned int, sizeof(opts), optlen);
91093+ len = min(sizeof(opts), len);
91094 if (copy_from_user((char *) &opts, optval, len)) {
91095 err = -EFAULT;
91096 break;
91097@@ -587,7 +588,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
91098 struct bt_security sec;
91099 struct bt_power pwr;
91100 struct l2cap_conn *conn;
91101- int len, err = 0;
91102+ int err = 0;
91103+ size_t len = optlen;
91104 u32 opt;
91105
91106 BT_DBG("sk %p", sk);
91107@@ -610,7 +612,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
91108
91109 sec.level = BT_SECURITY_LOW;
91110
91111- len = min_t(unsigned int, sizeof(sec), optlen);
91112+ len = min(sizeof(sec), len);
91113 if (copy_from_user((char *) &sec, optval, len)) {
91114 err = -EFAULT;
91115 break;
91116@@ -707,7 +709,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
91117
91118 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
91119
91120- len = min_t(unsigned int, sizeof(pwr), optlen);
91121+ len = min(sizeof(pwr), len);
91122 if (copy_from_user((char *) &pwr, optval, len)) {
91123 err = -EFAULT;
91124 break;
91125diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
91126index 30b3721..c1bd0a0 100644
91127--- a/net/bluetooth/rfcomm/sock.c
91128+++ b/net/bluetooth/rfcomm/sock.c
91129@@ -666,7 +666,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
91130 struct sock *sk = sock->sk;
91131 struct bt_security sec;
91132 int err = 0;
91133- size_t len;
91134+ size_t len = optlen;
91135 u32 opt;
91136
91137 BT_DBG("sk %p", sk);
91138@@ -688,7 +688,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
91139
91140 sec.level = BT_SECURITY_LOW;
91141
91142- len = min_t(unsigned int, sizeof(sec), optlen);
91143+ len = min(sizeof(sec), len);
91144 if (copy_from_user((char *) &sec, optval, len)) {
91145 err = -EFAULT;
91146 break;
91147diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
91148index b6e44ad..5b0d514 100644
91149--- a/net/bluetooth/rfcomm/tty.c
91150+++ b/net/bluetooth/rfcomm/tty.c
91151@@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
91152 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
91153
91154 spin_lock_irqsave(&dev->port.lock, flags);
91155- if (dev->port.count > 0) {
91156+ if (atomic_read(&dev->port.count) > 0) {
91157 spin_unlock_irqrestore(&dev->port.lock, flags);
91158 return;
91159 }
91160@@ -659,10 +659,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
91161 return -ENODEV;
91162
91163 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
91164- dev->channel, dev->port.count);
91165+ dev->channel, atomic_read(&dev->port.count));
91166
91167 spin_lock_irqsave(&dev->port.lock, flags);
91168- if (++dev->port.count > 1) {
91169+ if (atomic_inc_return(&dev->port.count) > 1) {
91170 spin_unlock_irqrestore(&dev->port.lock, flags);
91171 return 0;
91172 }
91173@@ -727,10 +727,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
91174 return;
91175
91176 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
91177- dev->port.count);
91178+ atomic_read(&dev->port.count));
91179
91180 spin_lock_irqsave(&dev->port.lock, flags);
91181- if (!--dev->port.count) {
91182+ if (!atomic_dec_return(&dev->port.count)) {
91183 spin_unlock_irqrestore(&dev->port.lock, flags);
91184 if (dev->tty_dev->parent)
91185 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
91186diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
91187index ac78024..161a80c 100644
91188--- a/net/bridge/netfilter/ebtables.c
91189+++ b/net/bridge/netfilter/ebtables.c
91190@@ -1525,7 +1525,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
91191 tmp.valid_hooks = t->table->valid_hooks;
91192 }
91193 mutex_unlock(&ebt_mutex);
91194- if (copy_to_user(user, &tmp, *len) != 0){
91195+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
91196 BUGPRINT("c2u Didn't work\n");
91197 ret = -EFAULT;
91198 break;
91199@@ -2331,7 +2331,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
91200 goto out;
91201 tmp.valid_hooks = t->valid_hooks;
91202
91203- if (copy_to_user(user, &tmp, *len) != 0) {
91204+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
91205 ret = -EFAULT;
91206 break;
91207 }
91208@@ -2342,7 +2342,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
91209 tmp.entries_size = t->table->entries_size;
91210 tmp.valid_hooks = t->table->valid_hooks;
91211
91212- if (copy_to_user(user, &tmp, *len) != 0) {
91213+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
91214 ret = -EFAULT;
91215 break;
91216 }
91217diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
91218index 2bd4b58..0dc30a1 100644
91219--- a/net/caif/cfctrl.c
91220+++ b/net/caif/cfctrl.c
91221@@ -10,6 +10,7 @@
91222 #include <linux/spinlock.h>
91223 #include <linux/slab.h>
91224 #include <linux/pkt_sched.h>
91225+#include <linux/sched.h>
91226 #include <net/caif/caif_layer.h>
91227 #include <net/caif/cfpkt.h>
91228 #include <net/caif/cfctrl.h>
91229@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
91230 memset(&dev_info, 0, sizeof(dev_info));
91231 dev_info.id = 0xff;
91232 cfsrvl_init(&this->serv, 0, &dev_info, false);
91233- atomic_set(&this->req_seq_no, 1);
91234- atomic_set(&this->rsp_seq_no, 1);
91235+ atomic_set_unchecked(&this->req_seq_no, 1);
91236+ atomic_set_unchecked(&this->rsp_seq_no, 1);
91237 this->serv.layer.receive = cfctrl_recv;
91238 sprintf(this->serv.layer.name, "ctrl");
91239 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
91240@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
91241 struct cfctrl_request_info *req)
91242 {
91243 spin_lock_bh(&ctrl->info_list_lock);
91244- atomic_inc(&ctrl->req_seq_no);
91245- req->sequence_no = atomic_read(&ctrl->req_seq_no);
91246+ atomic_inc_unchecked(&ctrl->req_seq_no);
91247+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
91248 list_add_tail(&req->list, &ctrl->list);
91249 spin_unlock_bh(&ctrl->info_list_lock);
91250 }
91251@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
91252 if (p != first)
91253 pr_warn("Requests are not received in order\n");
91254
91255- atomic_set(&ctrl->rsp_seq_no,
91256+ atomic_set_unchecked(&ctrl->rsp_seq_no,
91257 p->sequence_no);
91258 list_del(&p->list);
91259 goto out;
91260diff --git a/net/can/af_can.c b/net/can/af_can.c
91261index 3ab8dd2..b9aef13 100644
91262--- a/net/can/af_can.c
91263+++ b/net/can/af_can.c
91264@@ -862,7 +862,7 @@ static const struct net_proto_family can_family_ops = {
91265 };
91266
91267 /* notifier block for netdevice event */
91268-static struct notifier_block can_netdev_notifier __read_mostly = {
91269+static struct notifier_block can_netdev_notifier = {
91270 .notifier_call = can_notifier,
91271 };
91272
91273diff --git a/net/can/gw.c b/net/can/gw.c
91274index 2f291f9..98c986a 100644
91275--- a/net/can/gw.c
91276+++ b/net/can/gw.c
91277@@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
91278 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
91279
91280 static HLIST_HEAD(cgw_list);
91281-static struct notifier_block notifier;
91282
91283 static struct kmem_cache *cgw_cache __read_mostly;
91284
91285@@ -927,6 +926,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
91286 return err;
91287 }
91288
91289+static struct notifier_block notifier = {
91290+ .notifier_call = cgw_notifier
91291+};
91292+
91293 static __init int cgw_module_init(void)
91294 {
91295 /* sanitize given module parameter */
91296@@ -942,7 +945,6 @@ static __init int cgw_module_init(void)
91297 return -ENOMEM;
91298
91299 /* set notifier */
91300- notifier.notifier_call = cgw_notifier;
91301 register_netdevice_notifier(&notifier);
91302
91303 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
91304diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
91305index eb0a46a..5f3bae8 100644
91306--- a/net/ceph/messenger.c
91307+++ b/net/ceph/messenger.c
91308@@ -186,7 +186,7 @@ static void con_fault(struct ceph_connection *con);
91309 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
91310
91311 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
91312-static atomic_t addr_str_seq = ATOMIC_INIT(0);
91313+static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
91314
91315 static struct page *zero_page; /* used in certain error cases */
91316
91317@@ -197,7 +197,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
91318 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
91319 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
91320
91321- i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
91322+ i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
91323 s = addr_str[i];
91324
91325 switch (ss->ss_family) {
91326diff --git a/net/compat.c b/net/compat.c
91327index f0a1ba6..0541331 100644
91328--- a/net/compat.c
91329+++ b/net/compat.c
91330@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
91331 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
91332 __get_user(kmsg->msg_flags, &umsg->msg_flags))
91333 return -EFAULT;
91334- kmsg->msg_name = compat_ptr(tmp1);
91335- kmsg->msg_iov = compat_ptr(tmp2);
91336- kmsg->msg_control = compat_ptr(tmp3);
91337+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
91338+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
91339+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
91340 return 0;
91341 }
91342
91343@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
91344
91345 if (kern_msg->msg_namelen) {
91346 if (mode == VERIFY_READ) {
91347- int err = move_addr_to_kernel(kern_msg->msg_name,
91348+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
91349 kern_msg->msg_namelen,
91350 kern_address);
91351 if (err < 0)
91352@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
91353 kern_msg->msg_name = NULL;
91354
91355 tot_len = iov_from_user_compat_to_kern(kern_iov,
91356- (struct compat_iovec __user *)kern_msg->msg_iov,
91357+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
91358 kern_msg->msg_iovlen);
91359 if (tot_len >= 0)
91360 kern_msg->msg_iov = kern_iov;
91361@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
91362
91363 #define CMSG_COMPAT_FIRSTHDR(msg) \
91364 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
91365- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
91366+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
91367 (struct compat_cmsghdr __user *)NULL)
91368
91369 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
91370 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
91371 (ucmlen) <= (unsigned long) \
91372 ((mhdr)->msg_controllen - \
91373- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
91374+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
91375
91376 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
91377 struct compat_cmsghdr __user *cmsg, int cmsg_len)
91378 {
91379 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
91380- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
91381+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
91382 msg->msg_controllen)
91383 return NULL;
91384 return (struct compat_cmsghdr __user *)ptr;
91385@@ -219,7 +219,7 @@ Efault:
91386
91387 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
91388 {
91389- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
91390+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
91391 struct compat_cmsghdr cmhdr;
91392 struct compat_timeval ctv;
91393 struct compat_timespec cts[3];
91394@@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
91395
91396 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
91397 {
91398- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
91399+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
91400 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
91401 int fdnum = scm->fp->count;
91402 struct file **fp = scm->fp->fp;
91403@@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
91404 return -EFAULT;
91405 old_fs = get_fs();
91406 set_fs(KERNEL_DS);
91407- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
91408+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
91409 set_fs(old_fs);
91410
91411 return err;
91412@@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
91413 len = sizeof(ktime);
91414 old_fs = get_fs();
91415 set_fs(KERNEL_DS);
91416- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
91417+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
91418 set_fs(old_fs);
91419
91420 if (!err) {
91421@@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
91422 case MCAST_JOIN_GROUP:
91423 case MCAST_LEAVE_GROUP:
91424 {
91425- struct compat_group_req __user *gr32 = (void *)optval;
91426+ struct compat_group_req __user *gr32 = (void __user *)optval;
91427 struct group_req __user *kgr =
91428 compat_alloc_user_space(sizeof(struct group_req));
91429 u32 interface;
91430@@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
91431 case MCAST_BLOCK_SOURCE:
91432 case MCAST_UNBLOCK_SOURCE:
91433 {
91434- struct compat_group_source_req __user *gsr32 = (void *)optval;
91435+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
91436 struct group_source_req __user *kgsr = compat_alloc_user_space(
91437 sizeof(struct group_source_req));
91438 u32 interface;
91439@@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
91440 }
91441 case MCAST_MSFILTER:
91442 {
91443- struct compat_group_filter __user *gf32 = (void *)optval;
91444+ struct compat_group_filter __user *gf32 = (void __user *)optval;
91445 struct group_filter __user *kgf;
91446 u32 interface, fmode, numsrc;
91447
91448@@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
91449 char __user *optval, int __user *optlen,
91450 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
91451 {
91452- struct compat_group_filter __user *gf32 = (void *)optval;
91453+ struct compat_group_filter __user *gf32 = (void __user *)optval;
91454 struct group_filter __user *kgf;
91455 int __user *koptlen;
91456 u32 interface, fmode, numsrc;
91457@@ -805,7 +805,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
91458
91459 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
91460 return -EINVAL;
91461- if (copy_from_user(a, args, nas[call]))
91462+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
91463 return -EFAULT;
91464 a0 = a[0];
91465 a1 = a[1];
91466diff --git a/net/core/datagram.c b/net/core/datagram.c
91467index 8ab48cd..57b1a80 100644
91468--- a/net/core/datagram.c
91469+++ b/net/core/datagram.c
91470@@ -300,7 +300,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
91471 }
91472
91473 kfree_skb(skb);
91474- atomic_inc(&sk->sk_drops);
91475+ atomic_inc_unchecked(&sk->sk_drops);
91476 sk_mem_reclaim_partial(sk);
91477
91478 return err;
91479diff --git a/net/core/dev.c b/net/core/dev.c
91480index 26755dd..5020ced 100644
91481--- a/net/core/dev.c
91482+++ b/net/core/dev.c
91483@@ -1680,14 +1680,14 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
91484 {
91485 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
91486 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
91487- atomic_long_inc(&dev->rx_dropped);
91488+ atomic_long_inc_unchecked(&dev->rx_dropped);
91489 kfree_skb(skb);
91490 return NET_RX_DROP;
91491 }
91492 }
91493
91494 if (unlikely(!is_skb_forwardable(dev, skb))) {
91495- atomic_long_inc(&dev->rx_dropped);
91496+ atomic_long_inc_unchecked(&dev->rx_dropped);
91497 kfree_skb(skb);
91498 return NET_RX_DROP;
91499 }
91500@@ -2431,7 +2431,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
91501
91502 struct dev_gso_cb {
91503 void (*destructor)(struct sk_buff *skb);
91504-};
91505+} __no_const;
91506
91507 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
91508
91509@@ -3206,7 +3206,7 @@ enqueue:
91510
91511 local_irq_restore(flags);
91512
91513- atomic_long_inc(&skb->dev->rx_dropped);
91514+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
91515 kfree_skb(skb);
91516 return NET_RX_DROP;
91517 }
91518@@ -3278,7 +3278,7 @@ int netif_rx_ni(struct sk_buff *skb)
91519 }
91520 EXPORT_SYMBOL(netif_rx_ni);
91521
91522-static void net_tx_action(struct softirq_action *h)
91523+static void net_tx_action(void)
91524 {
91525 struct softnet_data *sd = &__get_cpu_var(softnet_data);
91526
91527@@ -3612,7 +3612,7 @@ ncls:
91528 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
91529 } else {
91530 drop:
91531- atomic_long_inc(&skb->dev->rx_dropped);
91532+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
91533 kfree_skb(skb);
91534 /* Jamal, now you will not able to escape explaining
91535 * me how you were going to use this. :-)
91536@@ -4272,7 +4272,7 @@ void netif_napi_del(struct napi_struct *napi)
91537 }
91538 EXPORT_SYMBOL(netif_napi_del);
91539
91540-static void net_rx_action(struct softirq_action *h)
91541+static void net_rx_action(void)
91542 {
91543 struct softnet_data *sd = &__get_cpu_var(softnet_data);
91544 unsigned long time_limit = jiffies + 2;
91545@@ -5730,7 +5730,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
91546 } else {
91547 netdev_stats_to_stats64(storage, &dev->stats);
91548 }
91549- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
91550+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
91551 return storage;
91552 }
91553 EXPORT_SYMBOL(dev_get_stats);
91554diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
91555index 5b7d0e1..cb960fc 100644
91556--- a/net/core/dev_ioctl.c
91557+++ b/net/core/dev_ioctl.c
91558@@ -365,9 +365,13 @@ void dev_load(struct net *net, const char *name)
91559 if (no_module && capable(CAP_NET_ADMIN))
91560 no_module = request_module("netdev-%s", name);
91561 if (no_module && capable(CAP_SYS_MODULE)) {
91562+#ifdef CONFIG_GRKERNSEC_MODHARDEN
91563+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
91564+#else
91565 if (!request_module("%s", name))
91566 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
91567 name);
91568+#endif
91569 }
91570 }
91571 EXPORT_SYMBOL(dev_load);
91572diff --git a/net/core/flow.c b/net/core/flow.c
91573index dfa602c..3103d88 100644
91574--- a/net/core/flow.c
91575+++ b/net/core/flow.c
91576@@ -61,7 +61,7 @@ struct flow_cache {
91577 struct timer_list rnd_timer;
91578 };
91579
91580-atomic_t flow_cache_genid = ATOMIC_INIT(0);
91581+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
91582 EXPORT_SYMBOL(flow_cache_genid);
91583 static struct flow_cache flow_cache_global;
91584 static struct kmem_cache *flow_cachep __read_mostly;
91585@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
91586
91587 static int flow_entry_valid(struct flow_cache_entry *fle)
91588 {
91589- if (atomic_read(&flow_cache_genid) != fle->genid)
91590+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
91591 return 0;
91592 if (fle->object && !fle->object->ops->check(fle->object))
91593 return 0;
91594@@ -258,7 +258,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
91595 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
91596 fcp->hash_count++;
91597 }
91598- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
91599+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
91600 flo = fle->object;
91601 if (!flo)
91602 goto ret_object;
91603@@ -279,7 +279,7 @@ nocache:
91604 }
91605 flo = resolver(net, key, family, dir, flo, ctx);
91606 if (fle) {
91607- fle->genid = atomic_read(&flow_cache_genid);
91608+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
91609 if (!IS_ERR(flo))
91610 fle->object = flo;
91611 else
91612diff --git a/net/core/iovec.c b/net/core/iovec.c
91613index de178e4..1dabd8b 100644
91614--- a/net/core/iovec.c
91615+++ b/net/core/iovec.c
91616@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
91617 if (m->msg_namelen) {
91618 if (mode == VERIFY_READ) {
91619 void __user *namep;
91620- namep = (void __user __force *) m->msg_name;
91621+ namep = (void __force_user *) m->msg_name;
91622 err = move_addr_to_kernel(namep, m->msg_namelen,
91623 address);
91624 if (err < 0)
91625@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
91626 }
91627
91628 size = m->msg_iovlen * sizeof(struct iovec);
91629- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
91630+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
91631 return -EFAULT;
91632
91633 m->msg_iov = iov;
91634diff --git a/net/core/neighbour.c b/net/core/neighbour.c
91635index 60533db..14842cc 100644
91636--- a/net/core/neighbour.c
91637+++ b/net/core/neighbour.c
91638@@ -2776,7 +2776,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
91639 void __user *buffer, size_t *lenp, loff_t *ppos)
91640 {
91641 int size, ret;
91642- struct ctl_table tmp = *ctl;
91643+ ctl_table_no_const tmp = *ctl;
91644
91645 tmp.extra1 = &zero;
91646 tmp.extra2 = &unres_qlen_max;
91647diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
91648index 2bf8329..7960607 100644
91649--- a/net/core/net-procfs.c
91650+++ b/net/core/net-procfs.c
91651@@ -283,8 +283,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
91652 else
91653 seq_printf(seq, "%04x", ntohs(pt->type));
91654
91655+#ifdef CONFIG_GRKERNSEC_HIDESYM
91656+ seq_printf(seq, " %-8s %pf\n",
91657+ pt->dev ? pt->dev->name : "", NULL);
91658+#else
91659 seq_printf(seq, " %-8s %pf\n",
91660 pt->dev ? pt->dev->name : "", pt->func);
91661+#endif
91662 }
91663
91664 return 0;
91665diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
91666index 981fed3..536af34 100644
91667--- a/net/core/net-sysfs.c
91668+++ b/net/core/net-sysfs.c
91669@@ -1311,7 +1311,7 @@ void netdev_class_remove_file(struct class_attribute *class_attr)
91670 }
91671 EXPORT_SYMBOL(netdev_class_remove_file);
91672
91673-int netdev_kobject_init(void)
91674+int __init netdev_kobject_init(void)
91675 {
91676 kobj_ns_type_register(&net_ns_type_operations);
91677 return class_register(&net_class);
91678diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
91679index f9765203..9feaef8 100644
91680--- a/net/core/net_namespace.c
91681+++ b/net/core/net_namespace.c
91682@@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
91683 int error;
91684 LIST_HEAD(net_exit_list);
91685
91686- list_add_tail(&ops->list, list);
91687+ pax_list_add_tail((struct list_head *)&ops->list, list);
91688 if (ops->init || (ops->id && ops->size)) {
91689 for_each_net(net) {
91690 error = ops_init(ops, net);
91691@@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
91692
91693 out_undo:
91694 /* If I have an error cleanup all namespaces I initialized */
91695- list_del(&ops->list);
91696+ pax_list_del((struct list_head *)&ops->list);
91697 ops_exit_list(ops, &net_exit_list);
91698 ops_free_list(ops, &net_exit_list);
91699 return error;
91700@@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
91701 struct net *net;
91702 LIST_HEAD(net_exit_list);
91703
91704- list_del(&ops->list);
91705+ pax_list_del((struct list_head *)&ops->list);
91706 for_each_net(net)
91707 list_add_tail(&net->exit_list, &net_exit_list);
91708 ops_exit_list(ops, &net_exit_list);
91709@@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
91710 mutex_lock(&net_mutex);
91711 error = register_pernet_operations(&pernet_list, ops);
91712 if (!error && (first_device == &pernet_list))
91713- first_device = &ops->list;
91714+ first_device = (struct list_head *)&ops->list;
91715 mutex_unlock(&net_mutex);
91716 return error;
91717 }
91718diff --git a/net/core/netpoll.c b/net/core/netpoll.c
91719index 2c637e9..68c9087 100644
91720--- a/net/core/netpoll.c
91721+++ b/net/core/netpoll.c
91722@@ -428,7 +428,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
91723 struct udphdr *udph;
91724 struct iphdr *iph;
91725 struct ethhdr *eth;
91726- static atomic_t ip_ident;
91727+ static atomic_unchecked_t ip_ident;
91728 struct ipv6hdr *ip6h;
91729
91730 udp_len = len + sizeof(*udph);
91731@@ -499,7 +499,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
91732 put_unaligned(0x45, (unsigned char *)iph);
91733 iph->tos = 0;
91734 put_unaligned(htons(ip_len), &(iph->tot_len));
91735- iph->id = htons(atomic_inc_return(&ip_ident));
91736+ iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
91737 iph->frag_off = 0;
91738 iph->ttl = 64;
91739 iph->protocol = IPPROTO_UDP;
91740diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
91741index ca198c1d1..125372f 100644
91742--- a/net/core/rtnetlink.c
91743+++ b/net/core/rtnetlink.c
91744@@ -58,7 +58,7 @@ struct rtnl_link {
91745 rtnl_doit_func doit;
91746 rtnl_dumpit_func dumpit;
91747 rtnl_calcit_func calcit;
91748-};
91749+} __no_const;
91750
91751 static DEFINE_MUTEX(rtnl_mutex);
91752
91753@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
91754 if (rtnl_link_ops_get(ops->kind))
91755 return -EEXIST;
91756
91757- if (!ops->dellink)
91758- ops->dellink = unregister_netdevice_queue;
91759+ if (!ops->dellink) {
91760+ pax_open_kernel();
91761+ *(void **)&ops->dellink = unregister_netdevice_queue;
91762+ pax_close_kernel();
91763+ }
91764
91765- list_add_tail(&ops->list, &link_ops);
91766+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
91767 return 0;
91768 }
91769 EXPORT_SYMBOL_GPL(__rtnl_link_register);
91770@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
91771 for_each_net(net) {
91772 __rtnl_kill_links(net, ops);
91773 }
91774- list_del(&ops->list);
91775+ pax_list_del((struct list_head *)&ops->list);
91776 }
91777 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
91778
91779diff --git a/net/core/scm.c b/net/core/scm.c
91780index b4da80b..98d6bdb 100644
91781--- a/net/core/scm.c
91782+++ b/net/core/scm.c
91783@@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
91784 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
91785 {
91786 struct cmsghdr __user *cm
91787- = (__force struct cmsghdr __user *)msg->msg_control;
91788+ = (struct cmsghdr __force_user *)msg->msg_control;
91789 struct cmsghdr cmhdr;
91790 int cmlen = CMSG_LEN(len);
91791 int err;
91792@@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
91793 err = -EFAULT;
91794 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
91795 goto out;
91796- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
91797+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
91798 goto out;
91799 cmlen = CMSG_SPACE(len);
91800 if (msg->msg_controllen < cmlen)
91801@@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
91802 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
91803 {
91804 struct cmsghdr __user *cm
91805- = (__force struct cmsghdr __user*)msg->msg_control;
91806+ = (struct cmsghdr __force_user *)msg->msg_control;
91807
91808 int fdmax = 0;
91809 int fdnum = scm->fp->count;
91810@@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
91811 if (fdnum < fdmax)
91812 fdmax = fdnum;
91813
91814- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
91815+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
91816 i++, cmfptr++)
91817 {
91818 struct socket *sock;
91819diff --git a/net/core/skbuff.c b/net/core/skbuff.c
91820index 2c3d0f5..f5a326f 100644
91821--- a/net/core/skbuff.c
91822+++ b/net/core/skbuff.c
91823@@ -3082,13 +3082,15 @@ void __init skb_init(void)
91824 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
91825 sizeof(struct sk_buff),
91826 0,
91827- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
91828+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
91829+ SLAB_NO_SANITIZE,
91830 NULL);
91831 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
91832 (2*sizeof(struct sk_buff)) +
91833 sizeof(atomic_t),
91834 0,
91835- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
91836+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
91837+ SLAB_NO_SANITIZE,
91838 NULL);
91839 }
91840
91841diff --git a/net/core/sock.c b/net/core/sock.c
91842index 2c097c5..bf72858 100644
91843--- a/net/core/sock.c
91844+++ b/net/core/sock.c
91845@@ -392,7 +392,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
91846 struct sk_buff_head *list = &sk->sk_receive_queue;
91847
91848 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
91849- atomic_inc(&sk->sk_drops);
91850+ atomic_inc_unchecked(&sk->sk_drops);
91851 trace_sock_rcvqueue_full(sk, skb);
91852 return -ENOMEM;
91853 }
91854@@ -402,7 +402,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
91855 return err;
91856
91857 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
91858- atomic_inc(&sk->sk_drops);
91859+ atomic_inc_unchecked(&sk->sk_drops);
91860 return -ENOBUFS;
91861 }
91862
91863@@ -422,7 +422,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
91864 skb_dst_force(skb);
91865
91866 spin_lock_irqsave(&list->lock, flags);
91867- skb->dropcount = atomic_read(&sk->sk_drops);
91868+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
91869 __skb_queue_tail(list, skb);
91870 spin_unlock_irqrestore(&list->lock, flags);
91871
91872@@ -442,7 +442,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
91873 skb->dev = NULL;
91874
91875 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
91876- atomic_inc(&sk->sk_drops);
91877+ atomic_inc_unchecked(&sk->sk_drops);
91878 goto discard_and_relse;
91879 }
91880 if (nested)
91881@@ -460,7 +460,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
91882 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
91883 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
91884 bh_unlock_sock(sk);
91885- atomic_inc(&sk->sk_drops);
91886+ atomic_inc_unchecked(&sk->sk_drops);
91887 goto discard_and_relse;
91888 }
91889
91890@@ -948,12 +948,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
91891 struct timeval tm;
91892 } v;
91893
91894- int lv = sizeof(int);
91895- int len;
91896+ unsigned int lv = sizeof(int);
91897+ unsigned int len;
91898
91899 if (get_user(len, optlen))
91900 return -EFAULT;
91901- if (len < 0)
91902+ if (len > INT_MAX)
91903 return -EINVAL;
91904
91905 memset(&v, 0, sizeof(v));
91906@@ -1105,11 +1105,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
91907
91908 case SO_PEERNAME:
91909 {
91910- char address[128];
91911+ char address[_K_SS_MAXSIZE];
91912
91913 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
91914 return -ENOTCONN;
91915- if (lv < len)
91916+ if (lv < len || sizeof address < len)
91917 return -EINVAL;
91918 if (copy_to_user(optval, address, len))
91919 return -EFAULT;
91920@@ -1182,7 +1182,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
91921
91922 if (len > lv)
91923 len = lv;
91924- if (copy_to_user(optval, &v, len))
91925+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
91926 return -EFAULT;
91927 lenout:
91928 if (put_user(len, optlen))
91929@@ -2303,7 +2303,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
91930 */
91931 smp_wmb();
91932 atomic_set(&sk->sk_refcnt, 1);
91933- atomic_set(&sk->sk_drops, 0);
91934+ atomic_set_unchecked(&sk->sk_drops, 0);
91935 }
91936 EXPORT_SYMBOL(sock_init_data);
91937
91938diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
91939index a0e9cf6..ef7f9ed 100644
91940--- a/net/core/sock_diag.c
91941+++ b/net/core/sock_diag.c
91942@@ -9,26 +9,33 @@
91943 #include <linux/inet_diag.h>
91944 #include <linux/sock_diag.h>
91945
91946-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
91947+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
91948 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
91949 static DEFINE_MUTEX(sock_diag_table_mutex);
91950
91951 int sock_diag_check_cookie(void *sk, __u32 *cookie)
91952 {
91953+#ifndef CONFIG_GRKERNSEC_HIDESYM
91954 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
91955 cookie[1] != INET_DIAG_NOCOOKIE) &&
91956 ((u32)(unsigned long)sk != cookie[0] ||
91957 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
91958 return -ESTALE;
91959 else
91960+#endif
91961 return 0;
91962 }
91963 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
91964
91965 void sock_diag_save_cookie(void *sk, __u32 *cookie)
91966 {
91967+#ifdef CONFIG_GRKERNSEC_HIDESYM
91968+ cookie[0] = 0;
91969+ cookie[1] = 0;
91970+#else
91971 cookie[0] = (u32)(unsigned long)sk;
91972 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
91973+#endif
91974 }
91975 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
91976
91977@@ -113,8 +120,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
91978 mutex_lock(&sock_diag_table_mutex);
91979 if (sock_diag_handlers[hndl->family])
91980 err = -EBUSY;
91981- else
91982+ else {
91983+ pax_open_kernel();
91984 sock_diag_handlers[hndl->family] = hndl;
91985+ pax_close_kernel();
91986+ }
91987 mutex_unlock(&sock_diag_table_mutex);
91988
91989 return err;
91990@@ -130,7 +140,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
91991
91992 mutex_lock(&sock_diag_table_mutex);
91993 BUG_ON(sock_diag_handlers[family] != hnld);
91994+ pax_open_kernel();
91995 sock_diag_handlers[family] = NULL;
91996+ pax_close_kernel();
91997 mutex_unlock(&sock_diag_table_mutex);
91998 }
91999 EXPORT_SYMBOL_GPL(sock_diag_unregister);
92000diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
92001index 31107ab..ae03d5a 100644
92002--- a/net/core/sysctl_net_core.c
92003+++ b/net/core/sysctl_net_core.c
92004@@ -31,7 +31,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
92005 {
92006 unsigned int orig_size, size;
92007 int ret, i;
92008- struct ctl_table tmp = {
92009+ ctl_table_no_const tmp = {
92010 .data = &size,
92011 .maxlen = sizeof(size),
92012 .mode = table->mode
92013@@ -350,13 +350,12 @@ static struct ctl_table netns_core_table[] = {
92014
92015 static __net_init int sysctl_core_net_init(struct net *net)
92016 {
92017- struct ctl_table *tbl;
92018+ ctl_table_no_const *tbl = NULL;
92019
92020 net->core.sysctl_somaxconn = SOMAXCONN;
92021
92022- tbl = netns_core_table;
92023 if (!net_eq(net, &init_net)) {
92024- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
92025+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
92026 if (tbl == NULL)
92027 goto err_dup;
92028
92029@@ -366,17 +365,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
92030 if (net->user_ns != &init_user_ns) {
92031 tbl[0].procname = NULL;
92032 }
92033- }
92034-
92035- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
92036+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
92037+ } else
92038+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
92039 if (net->core.sysctl_hdr == NULL)
92040 goto err_reg;
92041
92042 return 0;
92043
92044 err_reg:
92045- if (tbl != netns_core_table)
92046- kfree(tbl);
92047+ kfree(tbl);
92048 err_dup:
92049 return -ENOMEM;
92050 }
92051@@ -391,7 +389,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
92052 kfree(tbl);
92053 }
92054
92055-static __net_initdata struct pernet_operations sysctl_core_ops = {
92056+static __net_initconst struct pernet_operations sysctl_core_ops = {
92057 .init = sysctl_core_net_init,
92058 .exit = sysctl_core_net_exit,
92059 };
92060diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
92061index dd4d506..fb2fb87 100644
92062--- a/net/decnet/af_decnet.c
92063+++ b/net/decnet/af_decnet.c
92064@@ -465,6 +465,7 @@ static struct proto dn_proto = {
92065 .sysctl_rmem = sysctl_decnet_rmem,
92066 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
92067 .obj_size = sizeof(struct dn_sock),
92068+ .slab_flags = SLAB_USERCOPY,
92069 };
92070
92071 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
92072diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
92073index 5325b54..a0d4d69 100644
92074--- a/net/decnet/sysctl_net_decnet.c
92075+++ b/net/decnet/sysctl_net_decnet.c
92076@@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
92077
92078 if (len > *lenp) len = *lenp;
92079
92080- if (copy_to_user(buffer, addr, len))
92081+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
92082 return -EFAULT;
92083
92084 *lenp = len;
92085@@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
92086
92087 if (len > *lenp) len = *lenp;
92088
92089- if (copy_to_user(buffer, devname, len))
92090+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
92091 return -EFAULT;
92092
92093 *lenp = len;
92094diff --git a/net/ieee802154/6lowpan.c b/net/ieee802154/6lowpan.c
92095index 3b9d5f2..d7015c6 100644
92096--- a/net/ieee802154/6lowpan.c
92097+++ b/net/ieee802154/6lowpan.c
92098@@ -459,7 +459,7 @@ static int lowpan_header_create(struct sk_buff *skb,
92099 hc06_ptr += 3;
92100 } else {
92101 /* compress nothing */
92102- memcpy(hc06_ptr, &hdr, 4);
92103+ memcpy(hc06_ptr, hdr, 4);
92104 /* replace the top byte with new ECN | DSCP format */
92105 *hc06_ptr = tmp;
92106 hc06_ptr += 4;
92107diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
92108index b4d0be2..443d0f0 100644
92109--- a/net/ipv4/af_inet.c
92110+++ b/net/ipv4/af_inet.c
92111@@ -1689,13 +1689,9 @@ static int __init inet_init(void)
92112
92113 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
92114
92115- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
92116- if (!sysctl_local_reserved_ports)
92117- goto out;
92118-
92119 rc = proto_register(&tcp_prot, 1);
92120 if (rc)
92121- goto out_free_reserved_ports;
92122+ goto out;
92123
92124 rc = proto_register(&udp_prot, 1);
92125 if (rc)
92126@@ -1804,8 +1800,6 @@ out_unregister_udp_proto:
92127 proto_unregister(&udp_prot);
92128 out_unregister_tcp_proto:
92129 proto_unregister(&tcp_prot);
92130-out_free_reserved_ports:
92131- kfree(sysctl_local_reserved_ports);
92132 goto out;
92133 }
92134
92135diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
92136index 34ca6d5..b6421e8 100644
92137--- a/net/ipv4/devinet.c
92138+++ b/net/ipv4/devinet.c
92139@@ -1532,7 +1532,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
92140 idx = 0;
92141 head = &net->dev_index_head[h];
92142 rcu_read_lock();
92143- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
92144+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
92145 net->dev_base_seq;
92146 hlist_for_each_entry_rcu(dev, head, index_hlist) {
92147 if (idx < s_idx)
92148@@ -1843,7 +1843,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
92149 idx = 0;
92150 head = &net->dev_index_head[h];
92151 rcu_read_lock();
92152- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
92153+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
92154 net->dev_base_seq;
92155 hlist_for_each_entry_rcu(dev, head, index_hlist) {
92156 if (idx < s_idx)
92157@@ -2068,7 +2068,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
92158 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
92159 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
92160
92161-static struct devinet_sysctl_table {
92162+static const struct devinet_sysctl_table {
92163 struct ctl_table_header *sysctl_header;
92164 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
92165 } devinet_sysctl = {
92166@@ -2186,7 +2186,7 @@ static __net_init int devinet_init_net(struct net *net)
92167 int err;
92168 struct ipv4_devconf *all, *dflt;
92169 #ifdef CONFIG_SYSCTL
92170- struct ctl_table *tbl = ctl_forward_entry;
92171+ ctl_table_no_const *tbl = NULL;
92172 struct ctl_table_header *forw_hdr;
92173 #endif
92174
92175@@ -2204,7 +2204,7 @@ static __net_init int devinet_init_net(struct net *net)
92176 goto err_alloc_dflt;
92177
92178 #ifdef CONFIG_SYSCTL
92179- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
92180+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
92181 if (tbl == NULL)
92182 goto err_alloc_ctl;
92183
92184@@ -2224,7 +2224,10 @@ static __net_init int devinet_init_net(struct net *net)
92185 goto err_reg_dflt;
92186
92187 err = -ENOMEM;
92188- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
92189+ if (!net_eq(net, &init_net))
92190+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
92191+ else
92192+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
92193 if (forw_hdr == NULL)
92194 goto err_reg_ctl;
92195 net->ipv4.forw_hdr = forw_hdr;
92196@@ -2240,8 +2243,7 @@ err_reg_ctl:
92197 err_reg_dflt:
92198 __devinet_sysctl_unregister(all);
92199 err_reg_all:
92200- if (tbl != ctl_forward_entry)
92201- kfree(tbl);
92202+ kfree(tbl);
92203 err_alloc_ctl:
92204 #endif
92205 if (dflt != &ipv4_devconf_dflt)
92206diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
92207index b3f627a..b0f3e99 100644
92208--- a/net/ipv4/fib_frontend.c
92209+++ b/net/ipv4/fib_frontend.c
92210@@ -1017,12 +1017,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
92211 #ifdef CONFIG_IP_ROUTE_MULTIPATH
92212 fib_sync_up(dev);
92213 #endif
92214- atomic_inc(&net->ipv4.dev_addr_genid);
92215+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
92216 rt_cache_flush(dev_net(dev));
92217 break;
92218 case NETDEV_DOWN:
92219 fib_del_ifaddr(ifa, NULL);
92220- atomic_inc(&net->ipv4.dev_addr_genid);
92221+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
92222 if (ifa->ifa_dev->ifa_list == NULL) {
92223 /* Last address was deleted from this interface.
92224 * Disable IP.
92225@@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
92226 #ifdef CONFIG_IP_ROUTE_MULTIPATH
92227 fib_sync_up(dev);
92228 #endif
92229- atomic_inc(&net->ipv4.dev_addr_genid);
92230+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
92231 rt_cache_flush(net);
92232 break;
92233 case NETDEV_DOWN:
92234diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
92235index d5dbca5..6251d5f 100644
92236--- a/net/ipv4/fib_semantics.c
92237+++ b/net/ipv4/fib_semantics.c
92238@@ -766,7 +766,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
92239 nh->nh_saddr = inet_select_addr(nh->nh_dev,
92240 nh->nh_gw,
92241 nh->nh_parent->fib_scope);
92242- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
92243+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
92244
92245 return nh->nh_saddr;
92246 }
92247diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
92248index 6acb541..9ea617d 100644
92249--- a/net/ipv4/inet_connection_sock.c
92250+++ b/net/ipv4/inet_connection_sock.c
92251@@ -37,7 +37,7 @@ struct local_ports sysctl_local_ports __read_mostly = {
92252 .range = { 32768, 61000 },
92253 };
92254
92255-unsigned long *sysctl_local_reserved_ports;
92256+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
92257 EXPORT_SYMBOL(sysctl_local_reserved_ports);
92258
92259 void inet_get_local_port_range(int *low, int *high)
92260diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
92261index 7bd8983..3abdcf6 100644
92262--- a/net/ipv4/inet_hashtables.c
92263+++ b/net/ipv4/inet_hashtables.c
92264@@ -18,12 +18,15 @@
92265 #include <linux/sched.h>
92266 #include <linux/slab.h>
92267 #include <linux/wait.h>
92268+#include <linux/security.h>
92269
92270 #include <net/inet_connection_sock.h>
92271 #include <net/inet_hashtables.h>
92272 #include <net/secure_seq.h>
92273 #include <net/ip.h>
92274
92275+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
92276+
92277 /*
92278 * Allocate and initialize a new local port bind bucket.
92279 * The bindhash mutex for snum's hash chain must be held here.
92280@@ -554,6 +557,8 @@ ok:
92281 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
92282 spin_unlock(&head->lock);
92283
92284+ gr_update_task_in_ip_table(current, inet_sk(sk));
92285+
92286 if (tw) {
92287 inet_twsk_deschedule(tw, death_row);
92288 while (twrefcnt) {
92289diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
92290index 000e3d2..5472da3 100644
92291--- a/net/ipv4/inetpeer.c
92292+++ b/net/ipv4/inetpeer.c
92293@@ -503,8 +503,8 @@ relookup:
92294 if (p) {
92295 p->daddr = *daddr;
92296 atomic_set(&p->refcnt, 1);
92297- atomic_set(&p->rid, 0);
92298- atomic_set(&p->ip_id_count,
92299+ atomic_set_unchecked(&p->rid, 0);
92300+ atomic_set_unchecked(&p->ip_id_count,
92301 (daddr->family == AF_INET) ?
92302 secure_ip_id(daddr->addr.a4) :
92303 secure_ipv6_id(daddr->addr.a6));
92304diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
92305index b66910a..cfe416e 100644
92306--- a/net/ipv4/ip_fragment.c
92307+++ b/net/ipv4/ip_fragment.c
92308@@ -282,7 +282,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
92309 return 0;
92310
92311 start = qp->rid;
92312- end = atomic_inc_return(&peer->rid);
92313+ end = atomic_inc_return_unchecked(&peer->rid);
92314 qp->rid = end;
92315
92316 rc = qp->q.fragments && (end - start) > max;
92317@@ -759,12 +759,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
92318
92319 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
92320 {
92321- struct ctl_table *table;
92322+ ctl_table_no_const *table = NULL;
92323 struct ctl_table_header *hdr;
92324
92325- table = ip4_frags_ns_ctl_table;
92326 if (!net_eq(net, &init_net)) {
92327- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
92328+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
92329 if (table == NULL)
92330 goto err_alloc;
92331
92332@@ -775,9 +774,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
92333 /* Don't export sysctls to unprivileged users */
92334 if (net->user_ns != &init_user_ns)
92335 table[0].procname = NULL;
92336- }
92337+ hdr = register_net_sysctl(net, "net/ipv4", table);
92338+ } else
92339+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
92340
92341- hdr = register_net_sysctl(net, "net/ipv4", table);
92342 if (hdr == NULL)
92343 goto err_reg;
92344
92345@@ -785,8 +785,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
92346 return 0;
92347
92348 err_reg:
92349- if (!net_eq(net, &init_net))
92350- kfree(table);
92351+ kfree(table);
92352 err_alloc:
92353 return -ENOMEM;
92354 }
92355diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
92356index 8d6939e..19d0a95 100644
92357--- a/net/ipv4/ip_gre.c
92358+++ b/net/ipv4/ip_gre.c
92359@@ -115,7 +115,7 @@ static bool log_ecn_error = true;
92360 module_param(log_ecn_error, bool, 0644);
92361 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
92362
92363-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
92364+static struct rtnl_link_ops ipgre_link_ops;
92365 static int ipgre_tunnel_init(struct net_device *dev);
92366
92367 static int ipgre_net_id __read_mostly;
92368@@ -731,7 +731,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
92369 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
92370 };
92371
92372-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
92373+static struct rtnl_link_ops ipgre_link_ops = {
92374 .kind = "gre",
92375 .maxtype = IFLA_GRE_MAX,
92376 .policy = ipgre_policy,
92377@@ -745,7 +745,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
92378 .fill_info = ipgre_fill_info,
92379 };
92380
92381-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
92382+static struct rtnl_link_ops ipgre_tap_ops = {
92383 .kind = "gretap",
92384 .maxtype = IFLA_GRE_MAX,
92385 .policy = ipgre_policy,
92386diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
92387index d9c4f11..02b82dbc 100644
92388--- a/net/ipv4/ip_sockglue.c
92389+++ b/net/ipv4/ip_sockglue.c
92390@@ -1152,7 +1152,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
92391 len = min_t(unsigned int, len, opt->optlen);
92392 if (put_user(len, optlen))
92393 return -EFAULT;
92394- if (copy_to_user(optval, opt->__data, len))
92395+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
92396+ copy_to_user(optval, opt->__data, len))
92397 return -EFAULT;
92398 return 0;
92399 }
92400@@ -1283,7 +1284,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
92401 if (sk->sk_type != SOCK_STREAM)
92402 return -ENOPROTOOPT;
92403
92404- msg.msg_control = optval;
92405+ msg.msg_control = (void __force_kernel *)optval;
92406 msg.msg_controllen = len;
92407 msg.msg_flags = flags;
92408
92409diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
92410index 17cc0ff..63856c4 100644
92411--- a/net/ipv4/ip_vti.c
92412+++ b/net/ipv4/ip_vti.c
92413@@ -47,7 +47,7 @@
92414 #define HASH_SIZE 16
92415 #define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&(HASH_SIZE-1))
92416
92417-static struct rtnl_link_ops vti_link_ops __read_mostly;
92418+static struct rtnl_link_ops vti_link_ops;
92419
92420 static int vti_net_id __read_mostly;
92421 struct vti_net {
92422@@ -840,7 +840,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
92423 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
92424 };
92425
92426-static struct rtnl_link_ops vti_link_ops __read_mostly = {
92427+static struct rtnl_link_ops vti_link_ops = {
92428 .kind = "vti",
92429 .maxtype = IFLA_VTI_MAX,
92430 .policy = vti_policy,
92431diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
92432index efa1138..20dbba0 100644
92433--- a/net/ipv4/ipconfig.c
92434+++ b/net/ipv4/ipconfig.c
92435@@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
92436
92437 mm_segment_t oldfs = get_fs();
92438 set_fs(get_ds());
92439- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
92440+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
92441 set_fs(oldfs);
92442 return res;
92443 }
92444@@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
92445
92446 mm_segment_t oldfs = get_fs();
92447 set_fs(get_ds());
92448- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
92449+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
92450 set_fs(oldfs);
92451 return res;
92452 }
92453@@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
92454
92455 mm_segment_t oldfs = get_fs();
92456 set_fs(get_ds());
92457- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
92458+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
92459 set_fs(oldfs);
92460 return res;
92461 }
92462diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
92463index b3ac3c3..ec6bd95 100644
92464--- a/net/ipv4/ipip.c
92465+++ b/net/ipv4/ipip.c
92466@@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
92467 static int ipip_net_id __read_mostly;
92468
92469 static int ipip_tunnel_init(struct net_device *dev);
92470-static struct rtnl_link_ops ipip_link_ops __read_mostly;
92471+static struct rtnl_link_ops ipip_link_ops;
92472
92473 static int ipip_err(struct sk_buff *skb, u32 info)
92474 {
92475@@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
92476 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
92477 };
92478
92479-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
92480+static struct rtnl_link_ops ipip_link_ops = {
92481 .kind = "ipip",
92482 .maxtype = IFLA_IPTUN_MAX,
92483 .policy = ipip_policy,
92484diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
92485index 85a4f21..1beb1f5 100644
92486--- a/net/ipv4/netfilter/arp_tables.c
92487+++ b/net/ipv4/netfilter/arp_tables.c
92488@@ -880,14 +880,14 @@ static int compat_table_info(const struct xt_table_info *info,
92489 #endif
92490
92491 static int get_info(struct net *net, void __user *user,
92492- const int *len, int compat)
92493+ int len, int compat)
92494 {
92495 char name[XT_TABLE_MAXNAMELEN];
92496 struct xt_table *t;
92497 int ret;
92498
92499- if (*len != sizeof(struct arpt_getinfo)) {
92500- duprintf("length %u != %Zu\n", *len,
92501+ if (len != sizeof(struct arpt_getinfo)) {
92502+ duprintf("length %u != %Zu\n", len,
92503 sizeof(struct arpt_getinfo));
92504 return -EINVAL;
92505 }
92506@@ -924,7 +924,7 @@ static int get_info(struct net *net, void __user *user,
92507 info.size = private->size;
92508 strcpy(info.name, name);
92509
92510- if (copy_to_user(user, &info, *len) != 0)
92511+ if (copy_to_user(user, &info, len) != 0)
92512 ret = -EFAULT;
92513 else
92514 ret = 0;
92515@@ -1683,7 +1683,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
92516
92517 switch (cmd) {
92518 case ARPT_SO_GET_INFO:
92519- ret = get_info(sock_net(sk), user, len, 1);
92520+ ret = get_info(sock_net(sk), user, *len, 1);
92521 break;
92522 case ARPT_SO_GET_ENTRIES:
92523 ret = compat_get_entries(sock_net(sk), user, len);
92524@@ -1728,7 +1728,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
92525
92526 switch (cmd) {
92527 case ARPT_SO_GET_INFO:
92528- ret = get_info(sock_net(sk), user, len, 0);
92529+ ret = get_info(sock_net(sk), user, *len, 0);
92530 break;
92531
92532 case ARPT_SO_GET_ENTRIES:
92533diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
92534index d23118d..6ad7277 100644
92535--- a/net/ipv4/netfilter/ip_tables.c
92536+++ b/net/ipv4/netfilter/ip_tables.c
92537@@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
92538 #endif
92539
92540 static int get_info(struct net *net, void __user *user,
92541- const int *len, int compat)
92542+ int len, int compat)
92543 {
92544 char name[XT_TABLE_MAXNAMELEN];
92545 struct xt_table *t;
92546 int ret;
92547
92548- if (*len != sizeof(struct ipt_getinfo)) {
92549- duprintf("length %u != %zu\n", *len,
92550+ if (len != sizeof(struct ipt_getinfo)) {
92551+ duprintf("length %u != %zu\n", len,
92552 sizeof(struct ipt_getinfo));
92553 return -EINVAL;
92554 }
92555@@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
92556 info.size = private->size;
92557 strcpy(info.name, name);
92558
92559- if (copy_to_user(user, &info, *len) != 0)
92560+ if (copy_to_user(user, &info, len) != 0)
92561 ret = -EFAULT;
92562 else
92563 ret = 0;
92564@@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
92565
92566 switch (cmd) {
92567 case IPT_SO_GET_INFO:
92568- ret = get_info(sock_net(sk), user, len, 1);
92569+ ret = get_info(sock_net(sk), user, *len, 1);
92570 break;
92571 case IPT_SO_GET_ENTRIES:
92572 ret = compat_get_entries(sock_net(sk), user, len);
92573@@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
92574
92575 switch (cmd) {
92576 case IPT_SO_GET_INFO:
92577- ret = get_info(sock_net(sk), user, len, 0);
92578+ ret = get_info(sock_net(sk), user, *len, 0);
92579 break;
92580
92581 case IPT_SO_GET_ENTRIES:
92582diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
92583index 746427c..80eab72 100644
92584--- a/net/ipv4/ping.c
92585+++ b/net/ipv4/ping.c
92586@@ -55,7 +55,7 @@
92587
92588
92589 struct ping_table ping_table;
92590-struct pingv6_ops pingv6_ops;
92591+struct pingv6_ops *pingv6_ops;
92592 EXPORT_SYMBOL_GPL(pingv6_ops);
92593
92594 static u16 ping_port_rover;
92595@@ -335,7 +335,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
92596 return -ENODEV;
92597 }
92598 }
92599- has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
92600+ has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
92601 scoped);
92602 rcu_read_unlock();
92603
92604@@ -541,7 +541,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
92605 }
92606 #if IS_ENABLED(CONFIG_IPV6)
92607 } else if (skb->protocol == htons(ETH_P_IPV6)) {
92608- harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
92609+ harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
92610 #endif
92611 }
92612
92613@@ -559,7 +559,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
92614 info, (u8 *)icmph);
92615 #if IS_ENABLED(CONFIG_IPV6)
92616 } else if (family == AF_INET6) {
92617- pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
92618+ pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
92619 info, (u8 *)icmph);
92620 #endif
92621 }
92622@@ -850,7 +850,7 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
92623 return ip_recv_error(sk, msg, len);
92624 #if IS_ENABLED(CONFIG_IPV6)
92625 } else if (family == AF_INET6) {
92626- return pingv6_ops.ipv6_recv_error(sk, msg, len);
92627+ return pingv6_ops->ipv6_recv_error(sk, msg, len);
92628 #endif
92629 }
92630 }
92631@@ -900,7 +900,7 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
92632 IP6CB(skb)->iif);
92633
92634 if (inet6_sk(sk)->rxopt.all)
92635- pingv6_ops.ip6_datagram_recv_ctl(sk, msg, skb);
92636+ pingv6_ops->ip6_datagram_recv_ctl(sk, msg, skb);
92637 #endif
92638 } else {
92639 BUG();
92640@@ -1090,7 +1090,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
92641 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
92642 0, sock_i_ino(sp),
92643 atomic_read(&sp->sk_refcnt), sp,
92644- atomic_read(&sp->sk_drops), len);
92645+ atomic_read_unchecked(&sp->sk_drops), len);
92646 }
92647
92648 static int ping_v4_seq_show(struct seq_file *seq, void *v)
92649diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
92650index 61e60d6..d6996cd 100644
92651--- a/net/ipv4/raw.c
92652+++ b/net/ipv4/raw.c
92653@@ -309,7 +309,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
92654 int raw_rcv(struct sock *sk, struct sk_buff *skb)
92655 {
92656 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
92657- atomic_inc(&sk->sk_drops);
92658+ atomic_inc_unchecked(&sk->sk_drops);
92659 kfree_skb(skb);
92660 return NET_RX_DROP;
92661 }
92662@@ -746,16 +746,20 @@ static int raw_init(struct sock *sk)
92663
92664 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
92665 {
92666+ struct icmp_filter filter;
92667+
92668 if (optlen > sizeof(struct icmp_filter))
92669 optlen = sizeof(struct icmp_filter);
92670- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
92671+ if (copy_from_user(&filter, optval, optlen))
92672 return -EFAULT;
92673+ raw_sk(sk)->filter = filter;
92674 return 0;
92675 }
92676
92677 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
92678 {
92679 int len, ret = -EFAULT;
92680+ struct icmp_filter filter;
92681
92682 if (get_user(len, optlen))
92683 goto out;
92684@@ -765,8 +769,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
92685 if (len > sizeof(struct icmp_filter))
92686 len = sizeof(struct icmp_filter);
92687 ret = -EFAULT;
92688- if (put_user(len, optlen) ||
92689- copy_to_user(optval, &raw_sk(sk)->filter, len))
92690+ filter = raw_sk(sk)->filter;
92691+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
92692 goto out;
92693 ret = 0;
92694 out: return ret;
92695@@ -995,7 +999,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
92696 0, 0L, 0,
92697 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
92698 0, sock_i_ino(sp),
92699- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
92700+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
92701 }
92702
92703 static int raw_seq_show(struct seq_file *seq, void *v)
92704diff --git a/net/ipv4/route.c b/net/ipv4/route.c
92705index a9a54a2..647316e 100644
92706--- a/net/ipv4/route.c
92707+++ b/net/ipv4/route.c
92708@@ -2615,34 +2615,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
92709 .maxlen = sizeof(int),
92710 .mode = 0200,
92711 .proc_handler = ipv4_sysctl_rtcache_flush,
92712+ .extra1 = &init_net,
92713 },
92714 { },
92715 };
92716
92717 static __net_init int sysctl_route_net_init(struct net *net)
92718 {
92719- struct ctl_table *tbl;
92720+ ctl_table_no_const *tbl = NULL;
92721
92722- tbl = ipv4_route_flush_table;
92723 if (!net_eq(net, &init_net)) {
92724- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
92725+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
92726 if (tbl == NULL)
92727 goto err_dup;
92728
92729 /* Don't export sysctls to unprivileged users */
92730 if (net->user_ns != &init_user_ns)
92731 tbl[0].procname = NULL;
92732- }
92733- tbl[0].extra1 = net;
92734+ tbl[0].extra1 = net;
92735+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
92736+ } else
92737+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
92738
92739- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
92740 if (net->ipv4.route_hdr == NULL)
92741 goto err_reg;
92742 return 0;
92743
92744 err_reg:
92745- if (tbl != ipv4_route_flush_table)
92746- kfree(tbl);
92747+ kfree(tbl);
92748 err_dup:
92749 return -ENOMEM;
92750 }
92751@@ -2665,8 +2665,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
92752
92753 static __net_init int rt_genid_init(struct net *net)
92754 {
92755- atomic_set(&net->rt_genid, 0);
92756- atomic_set(&net->fnhe_genid, 0);
92757+ atomic_set_unchecked(&net->rt_genid, 0);
92758+ atomic_set_unchecked(&net->fnhe_genid, 0);
92759 get_random_bytes(&net->ipv4.dev_addr_genid,
92760 sizeof(net->ipv4.dev_addr_genid));
92761 return 0;
92762diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
92763index 610e324..fd42e75 100644
92764--- a/net/ipv4/sysctl_net_ipv4.c
92765+++ b/net/ipv4/sysctl_net_ipv4.c
92766@@ -57,7 +57,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
92767 {
92768 int ret;
92769 int range[2];
92770- struct ctl_table tmp = {
92771+ ctl_table_no_const tmp = {
92772 .data = &range,
92773 .maxlen = sizeof(range),
92774 .mode = table->mode,
92775@@ -110,7 +110,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
92776 int ret;
92777 gid_t urange[2];
92778 kgid_t low, high;
92779- struct ctl_table tmp = {
92780+ ctl_table_no_const tmp = {
92781 .data = &urange,
92782 .maxlen = sizeof(urange),
92783 .mode = table->mode,
92784@@ -141,7 +141,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
92785 void __user *buffer, size_t *lenp, loff_t *ppos)
92786 {
92787 char val[TCP_CA_NAME_MAX];
92788- struct ctl_table tbl = {
92789+ ctl_table_no_const tbl = {
92790 .data = val,
92791 .maxlen = TCP_CA_NAME_MAX,
92792 };
92793@@ -160,7 +160,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
92794 void __user *buffer, size_t *lenp,
92795 loff_t *ppos)
92796 {
92797- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
92798+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
92799 int ret;
92800
92801 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
92802@@ -177,7 +177,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
92803 void __user *buffer, size_t *lenp,
92804 loff_t *ppos)
92805 {
92806- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
92807+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
92808 int ret;
92809
92810 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
92811@@ -203,15 +203,17 @@ static int ipv4_tcp_mem(struct ctl_table *ctl, int write,
92812 struct mem_cgroup *memcg;
92813 #endif
92814
92815- struct ctl_table tmp = {
92816+ ctl_table_no_const tmp = {
92817 .data = &vec,
92818 .maxlen = sizeof(vec),
92819 .mode = ctl->mode,
92820 };
92821
92822 if (!write) {
92823- ctl->data = &net->ipv4.sysctl_tcp_mem;
92824- return proc_doulongvec_minmax(ctl, write, buffer, lenp, ppos);
92825+ ctl_table_no_const tcp_mem = *ctl;
92826+
92827+ tcp_mem.data = &net->ipv4.sysctl_tcp_mem;
92828+ return proc_doulongvec_minmax(&tcp_mem, write, buffer, lenp, ppos);
92829 }
92830
92831 ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
92832@@ -239,7 +241,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
92833 void __user *buffer, size_t *lenp,
92834 loff_t *ppos)
92835 {
92836- struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
92837+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
92838 struct tcp_fastopen_context *ctxt;
92839 int ret;
92840 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
92841@@ -482,7 +484,7 @@ static struct ctl_table ipv4_table[] = {
92842 },
92843 {
92844 .procname = "ip_local_reserved_ports",
92845- .data = NULL, /* initialized in sysctl_ipv4_init */
92846+ .data = sysctl_local_reserved_ports,
92847 .maxlen = 65536,
92848 .mode = 0644,
92849 .proc_handler = proc_do_large_bitmap,
92850@@ -847,11 +849,10 @@ static struct ctl_table ipv4_net_table[] = {
92851
92852 static __net_init int ipv4_sysctl_init_net(struct net *net)
92853 {
92854- struct ctl_table *table;
92855+ ctl_table_no_const *table = NULL;
92856
92857- table = ipv4_net_table;
92858 if (!net_eq(net, &init_net)) {
92859- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
92860+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
92861 if (table == NULL)
92862 goto err_alloc;
92863
92864@@ -886,15 +887,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
92865
92866 tcp_init_mem(net);
92867
92868- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
92869+ if (!net_eq(net, &init_net))
92870+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
92871+ else
92872+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
92873 if (net->ipv4.ipv4_hdr == NULL)
92874 goto err_reg;
92875
92876 return 0;
92877
92878 err_reg:
92879- if (!net_eq(net, &init_net))
92880- kfree(table);
92881+ kfree(table);
92882 err_alloc:
92883 return -ENOMEM;
92884 }
92885@@ -916,16 +919,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
92886 static __init int sysctl_ipv4_init(void)
92887 {
92888 struct ctl_table_header *hdr;
92889- struct ctl_table *i;
92890-
92891- for (i = ipv4_table; i->procname; i++) {
92892- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
92893- i->data = sysctl_local_reserved_ports;
92894- break;
92895- }
92896- }
92897- if (!i->procname)
92898- return -EINVAL;
92899
92900 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
92901 if (hdr == NULL)
92902diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
92903index 3ca2139..c4cc060 100644
92904--- a/net/ipv4/tcp_input.c
92905+++ b/net/ipv4/tcp_input.c
92906@@ -4379,7 +4379,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
92907 * simplifies code)
92908 */
92909 static void
92910-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
92911+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
92912 struct sk_buff *head, struct sk_buff *tail,
92913 u32 start, u32 end)
92914 {
92915@@ -5465,6 +5465,7 @@ discard:
92916 tcp_paws_reject(&tp->rx_opt, 0))
92917 goto discard_and_undo;
92918
92919+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
92920 if (th->syn) {
92921 /* We see SYN without ACK. It is attempt of
92922 * simultaneous connect with crossed SYNs.
92923@@ -5515,6 +5516,7 @@ discard:
92924 goto discard;
92925 #endif
92926 }
92927+#endif
92928 /* "fifth, if neither of the SYN or RST bits is set then
92929 * drop the segment and return."
92930 */
92931@@ -5560,7 +5562,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
92932 goto discard;
92933
92934 if (th->syn) {
92935- if (th->fin)
92936+ if (th->fin || th->urg || th->psh)
92937 goto discard;
92938 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
92939 return 1;
92940diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
92941index b299da5..097db06 100644
92942--- a/net/ipv4/tcp_ipv4.c
92943+++ b/net/ipv4/tcp_ipv4.c
92944@@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
92945 EXPORT_SYMBOL(sysctl_tcp_low_latency);
92946
92947
92948+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92949+extern int grsec_enable_blackhole;
92950+#endif
92951+
92952 #ifdef CONFIG_TCP_MD5SIG
92953 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
92954 __be32 daddr, __be32 saddr, const struct tcphdr *th);
92955@@ -1830,6 +1834,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
92956 return 0;
92957
92958 reset:
92959+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92960+ if (!grsec_enable_blackhole)
92961+#endif
92962 tcp_v4_send_reset(rsk, skb);
92963 discard:
92964 kfree_skb(skb);
92965@@ -1975,12 +1982,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
92966 TCP_SKB_CB(skb)->sacked = 0;
92967
92968 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
92969- if (!sk)
92970+ if (!sk) {
92971+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92972+ ret = 1;
92973+#endif
92974 goto no_tcp_socket;
92975-
92976+ }
92977 process:
92978- if (sk->sk_state == TCP_TIME_WAIT)
92979+ if (sk->sk_state == TCP_TIME_WAIT) {
92980+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92981+ ret = 2;
92982+#endif
92983 goto do_time_wait;
92984+ }
92985
92986 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
92987 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
92988@@ -2034,6 +2048,10 @@ csum_error:
92989 bad_packet:
92990 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
92991 } else {
92992+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
92993+ if (!grsec_enable_blackhole || (ret == 1 &&
92994+ (skb->dev->flags & IFF_LOOPBACK)))
92995+#endif
92996 tcp_v4_send_reset(NULL, skb);
92997 }
92998
92999diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
93000index ab1c086..2a8d76b 100644
93001--- a/net/ipv4/tcp_minisocks.c
93002+++ b/net/ipv4/tcp_minisocks.c
93003@@ -27,6 +27,10 @@
93004 #include <net/inet_common.h>
93005 #include <net/xfrm.h>
93006
93007+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93008+extern int grsec_enable_blackhole;
93009+#endif
93010+
93011 int sysctl_tcp_syncookies __read_mostly = 1;
93012 EXPORT_SYMBOL(sysctl_tcp_syncookies);
93013
93014@@ -715,7 +719,10 @@ embryonic_reset:
93015 * avoid becoming vulnerable to outside attack aiming at
93016 * resetting legit local connections.
93017 */
93018- req->rsk_ops->send_reset(sk, skb);
93019+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93020+ if (!grsec_enable_blackhole)
93021+#endif
93022+ req->rsk_ops->send_reset(sk, skb);
93023 } else if (fastopen) { /* received a valid RST pkt */
93024 reqsk_fastopen_remove(sk, req, true);
93025 tcp_reset(sk);
93026diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
93027index d4943f6..e7a74a5 100644
93028--- a/net/ipv4/tcp_probe.c
93029+++ b/net/ipv4/tcp_probe.c
93030@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
93031 if (cnt + width >= len)
93032 break;
93033
93034- if (copy_to_user(buf + cnt, tbuf, width))
93035+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
93036 return -EFAULT;
93037 cnt += width;
93038 }
93039diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
93040index 4b85e6f..22f9ac9 100644
93041--- a/net/ipv4/tcp_timer.c
93042+++ b/net/ipv4/tcp_timer.c
93043@@ -22,6 +22,10 @@
93044 #include <linux/gfp.h>
93045 #include <net/tcp.h>
93046
93047+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93048+extern int grsec_lastack_retries;
93049+#endif
93050+
93051 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
93052 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
93053 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
93054@@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
93055 }
93056 }
93057
93058+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93059+ if ((sk->sk_state == TCP_LAST_ACK) &&
93060+ (grsec_lastack_retries > 0) &&
93061+ (grsec_lastack_retries < retry_until))
93062+ retry_until = grsec_lastack_retries;
93063+#endif
93064+
93065 if (retransmits_timed_out(sk, retry_until,
93066 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
93067 /* Has it gone just too far? */
93068diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
93069index 766e6ba..aff2f8d 100644
93070--- a/net/ipv4/udp.c
93071+++ b/net/ipv4/udp.c
93072@@ -87,6 +87,7 @@
93073 #include <linux/types.h>
93074 #include <linux/fcntl.h>
93075 #include <linux/module.h>
93076+#include <linux/security.h>
93077 #include <linux/socket.h>
93078 #include <linux/sockios.h>
93079 #include <linux/igmp.h>
93080@@ -112,6 +113,10 @@
93081 #include <net/busy_poll.h>
93082 #include "udp_impl.h"
93083
93084+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93085+extern int grsec_enable_blackhole;
93086+#endif
93087+
93088 struct udp_table udp_table __read_mostly;
93089 EXPORT_SYMBOL(udp_table);
93090
93091@@ -595,6 +600,9 @@ found:
93092 return s;
93093 }
93094
93095+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
93096+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
93097+
93098 /*
93099 * This routine is called by the ICMP module when it gets some
93100 * sort of error condition. If err < 0 then the socket should
93101@@ -891,9 +899,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
93102 dport = usin->sin_port;
93103 if (dport == 0)
93104 return -EINVAL;
93105+
93106+ err = gr_search_udp_sendmsg(sk, usin);
93107+ if (err)
93108+ return err;
93109 } else {
93110 if (sk->sk_state != TCP_ESTABLISHED)
93111 return -EDESTADDRREQ;
93112+
93113+ err = gr_search_udp_sendmsg(sk, NULL);
93114+ if (err)
93115+ return err;
93116+
93117 daddr = inet->inet_daddr;
93118 dport = inet->inet_dport;
93119 /* Open fast path for connected socket.
93120@@ -1137,7 +1154,7 @@ static unsigned int first_packet_length(struct sock *sk)
93121 IS_UDPLITE(sk));
93122 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
93123 IS_UDPLITE(sk));
93124- atomic_inc(&sk->sk_drops);
93125+ atomic_inc_unchecked(&sk->sk_drops);
93126 __skb_unlink(skb, rcvq);
93127 __skb_queue_tail(&list_kill, skb);
93128 }
93129@@ -1223,6 +1240,10 @@ try_again:
93130 if (!skb)
93131 goto out;
93132
93133+ err = gr_search_udp_recvmsg(sk, skb);
93134+ if (err)
93135+ goto out_free;
93136+
93137 ulen = skb->len - sizeof(struct udphdr);
93138 copied = len;
93139 if (copied > ulen)
93140@@ -1256,7 +1277,7 @@ try_again:
93141 if (unlikely(err)) {
93142 trace_kfree_skb(skb, udp_recvmsg);
93143 if (!peeked) {
93144- atomic_inc(&sk->sk_drops);
93145+ atomic_inc_unchecked(&sk->sk_drops);
93146 UDP_INC_STATS_USER(sock_net(sk),
93147 UDP_MIB_INERRORS, is_udplite);
93148 }
93149@@ -1543,7 +1564,7 @@ csum_error:
93150 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
93151 drop:
93152 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
93153- atomic_inc(&sk->sk_drops);
93154+ atomic_inc_unchecked(&sk->sk_drops);
93155 kfree_skb(skb);
93156 return -1;
93157 }
93158@@ -1562,7 +1583,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
93159 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
93160
93161 if (!skb1) {
93162- atomic_inc(&sk->sk_drops);
93163+ atomic_inc_unchecked(&sk->sk_drops);
93164 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
93165 IS_UDPLITE(sk));
93166 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
93167@@ -1734,6 +1755,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
93168 goto csum_error;
93169
93170 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
93171+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93172+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
93173+#endif
93174 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
93175
93176 /*
93177@@ -2166,7 +2190,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
93178 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
93179 0, sock_i_ino(sp),
93180 atomic_read(&sp->sk_refcnt), sp,
93181- atomic_read(&sp->sk_drops), len);
93182+ atomic_read_unchecked(&sp->sk_drops), len);
93183 }
93184
93185 int udp4_seq_show(struct seq_file *seq, void *v)
93186diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
93187index 9a459be..c7bc04c 100644
93188--- a/net/ipv4/xfrm4_policy.c
93189+++ b/net/ipv4/xfrm4_policy.c
93190@@ -181,11 +181,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
93191 fl4->flowi4_tos = iph->tos;
93192 }
93193
93194-static inline int xfrm4_garbage_collect(struct dst_ops *ops)
93195+static int xfrm4_garbage_collect(struct dst_ops *ops)
93196 {
93197 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
93198
93199- xfrm4_policy_afinfo.garbage_collect(net);
93200+ xfrm_garbage_collect_deferred(net);
93201 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
93202 }
93203
93204@@ -264,19 +264,18 @@ static struct ctl_table xfrm4_policy_table[] = {
93205
93206 static int __net_init xfrm4_net_init(struct net *net)
93207 {
93208- struct ctl_table *table;
93209+ ctl_table_no_const *table = NULL;
93210 struct ctl_table_header *hdr;
93211
93212- table = xfrm4_policy_table;
93213 if (!net_eq(net, &init_net)) {
93214- table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
93215+ table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
93216 if (!table)
93217 goto err_alloc;
93218
93219 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
93220- }
93221-
93222- hdr = register_net_sysctl(net, "net/ipv4", table);
93223+ hdr = register_net_sysctl(net, "net/ipv4", table);
93224+ } else
93225+ hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
93226 if (!hdr)
93227 goto err_reg;
93228
93229@@ -284,8 +283,7 @@ static int __net_init xfrm4_net_init(struct net *net)
93230 return 0;
93231
93232 err_reg:
93233- if (!net_eq(net, &init_net))
93234- kfree(table);
93235+ kfree(table);
93236 err_alloc:
93237 return -ENOMEM;
93238 }
93239diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
93240index 498ea99..42501bc 100644
93241--- a/net/ipv6/addrconf.c
93242+++ b/net/ipv6/addrconf.c
93243@@ -618,7 +618,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
93244 idx = 0;
93245 head = &net->dev_index_head[h];
93246 rcu_read_lock();
93247- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
93248+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
93249 net->dev_base_seq;
93250 hlist_for_each_entry_rcu(dev, head, index_hlist) {
93251 if (idx < s_idx)
93252@@ -2381,7 +2381,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
93253 p.iph.ihl = 5;
93254 p.iph.protocol = IPPROTO_IPV6;
93255 p.iph.ttl = 64;
93256- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
93257+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
93258
93259 if (ops->ndo_do_ioctl) {
93260 mm_segment_t oldfs = get_fs();
93261@@ -4030,7 +4030,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
93262 s_ip_idx = ip_idx = cb->args[2];
93263
93264 rcu_read_lock();
93265- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
93266+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
93267 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
93268 idx = 0;
93269 head = &net->dev_index_head[h];
93270@@ -4651,7 +4651,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
93271 dst_free(&ifp->rt->dst);
93272 break;
93273 }
93274- atomic_inc(&net->ipv6.dev_addr_genid);
93275+ atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
93276 }
93277
93278 static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
93279@@ -4671,7 +4671,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
93280 int *valp = ctl->data;
93281 int val = *valp;
93282 loff_t pos = *ppos;
93283- struct ctl_table lctl;
93284+ ctl_table_no_const lctl;
93285 int ret;
93286
93287 /*
93288@@ -4756,7 +4756,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
93289 int *valp = ctl->data;
93290 int val = *valp;
93291 loff_t pos = *ppos;
93292- struct ctl_table lctl;
93293+ ctl_table_no_const lctl;
93294 int ret;
93295
93296 /*
93297diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
93298index 197e6f4..16d8396 100644
93299--- a/net/ipv6/datagram.c
93300+++ b/net/ipv6/datagram.c
93301@@ -904,5 +904,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
93302 0,
93303 sock_i_ino(sp),
93304 atomic_read(&sp->sk_refcnt), sp,
93305- atomic_read(&sp->sk_drops));
93306+ atomic_read_unchecked(&sp->sk_drops));
93307 }
93308diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
93309index 7cfc8d2..c5394b6 100644
93310--- a/net/ipv6/icmp.c
93311+++ b/net/ipv6/icmp.c
93312@@ -989,7 +989,7 @@ struct ctl_table ipv6_icmp_table_template[] = {
93313
93314 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
93315 {
93316- struct ctl_table *table;
93317+ ctl_table_no_const *table;
93318
93319 table = kmemdup(ipv6_icmp_table_template,
93320 sizeof(ipv6_icmp_table_template),
93321diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
93322index 90747f1..505320d 100644
93323--- a/net/ipv6/ip6_gre.c
93324+++ b/net/ipv6/ip6_gre.c
93325@@ -74,7 +74,7 @@ struct ip6gre_net {
93326 struct net_device *fb_tunnel_dev;
93327 };
93328
93329-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
93330+static struct rtnl_link_ops ip6gre_link_ops;
93331 static int ip6gre_tunnel_init(struct net_device *dev);
93332 static void ip6gre_tunnel_setup(struct net_device *dev);
93333 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
93334@@ -1288,7 +1288,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
93335 }
93336
93337
93338-static struct inet6_protocol ip6gre_protocol __read_mostly = {
93339+static struct inet6_protocol ip6gre_protocol = {
93340 .handler = ip6gre_rcv,
93341 .err_handler = ip6gre_err,
93342 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
93343@@ -1622,7 +1622,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
93344 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
93345 };
93346
93347-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
93348+static struct rtnl_link_ops ip6gre_link_ops = {
93349 .kind = "ip6gre",
93350 .maxtype = IFLA_GRE_MAX,
93351 .policy = ip6gre_policy,
93352@@ -1635,7 +1635,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
93353 .fill_info = ip6gre_fill_info,
93354 };
93355
93356-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
93357+static struct rtnl_link_ops ip6gre_tap_ops = {
93358 .kind = "ip6gretap",
93359 .maxtype = IFLA_GRE_MAX,
93360 .policy = ip6gre_policy,
93361diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
93362index 46ba243..576f50e 100644
93363--- a/net/ipv6/ip6_tunnel.c
93364+++ b/net/ipv6/ip6_tunnel.c
93365@@ -88,7 +88,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
93366
93367 static int ip6_tnl_dev_init(struct net_device *dev);
93368 static void ip6_tnl_dev_setup(struct net_device *dev);
93369-static struct rtnl_link_ops ip6_link_ops __read_mostly;
93370+static struct rtnl_link_ops ip6_link_ops;
93371
93372 static int ip6_tnl_net_id __read_mostly;
93373 struct ip6_tnl_net {
93374@@ -1678,7 +1678,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
93375 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
93376 };
93377
93378-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
93379+static struct rtnl_link_ops ip6_link_ops = {
93380 .kind = "ip6tnl",
93381 .maxtype = IFLA_IPTUN_MAX,
93382 .policy = ip6_tnl_policy,
93383diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
93384index d1e2e8e..51c19ae 100644
93385--- a/net/ipv6/ipv6_sockglue.c
93386+++ b/net/ipv6/ipv6_sockglue.c
93387@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
93388 if (sk->sk_type != SOCK_STREAM)
93389 return -ENOPROTOOPT;
93390
93391- msg.msg_control = optval;
93392+ msg.msg_control = (void __force_kernel *)optval;
93393 msg.msg_controllen = len;
93394 msg.msg_flags = flags;
93395
93396diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
93397index 44400c2..8e11f52 100644
93398--- a/net/ipv6/netfilter/ip6_tables.c
93399+++ b/net/ipv6/netfilter/ip6_tables.c
93400@@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
93401 #endif
93402
93403 static int get_info(struct net *net, void __user *user,
93404- const int *len, int compat)
93405+ int len, int compat)
93406 {
93407 char name[XT_TABLE_MAXNAMELEN];
93408 struct xt_table *t;
93409 int ret;
93410
93411- if (*len != sizeof(struct ip6t_getinfo)) {
93412- duprintf("length %u != %zu\n", *len,
93413+ if (len != sizeof(struct ip6t_getinfo)) {
93414+ duprintf("length %u != %zu\n", len,
93415 sizeof(struct ip6t_getinfo));
93416 return -EINVAL;
93417 }
93418@@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
93419 info.size = private->size;
93420 strcpy(info.name, name);
93421
93422- if (copy_to_user(user, &info, *len) != 0)
93423+ if (copy_to_user(user, &info, len) != 0)
93424 ret = -EFAULT;
93425 else
93426 ret = 0;
93427@@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
93428
93429 switch (cmd) {
93430 case IP6T_SO_GET_INFO:
93431- ret = get_info(sock_net(sk), user, len, 1);
93432+ ret = get_info(sock_net(sk), user, *len, 1);
93433 break;
93434 case IP6T_SO_GET_ENTRIES:
93435 ret = compat_get_entries(sock_net(sk), user, len);
93436@@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
93437
93438 switch (cmd) {
93439 case IP6T_SO_GET_INFO:
93440- ret = get_info(sock_net(sk), user, len, 0);
93441+ ret = get_info(sock_net(sk), user, *len, 0);
93442 break;
93443
93444 case IP6T_SO_GET_ENTRIES:
93445diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
93446index dffdc1a..ccc6678 100644
93447--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
93448+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
93449@@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
93450
93451 static int nf_ct_frag6_sysctl_register(struct net *net)
93452 {
93453- struct ctl_table *table;
93454+ ctl_table_no_const *table = NULL;
93455 struct ctl_table_header *hdr;
93456
93457- table = nf_ct_frag6_sysctl_table;
93458 if (!net_eq(net, &init_net)) {
93459- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
93460+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
93461 GFP_KERNEL);
93462 if (table == NULL)
93463 goto err_alloc;
93464@@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
93465 table[0].data = &net->nf_frag.frags.timeout;
93466 table[1].data = &net->nf_frag.frags.low_thresh;
93467 table[2].data = &net->nf_frag.frags.high_thresh;
93468- }
93469-
93470- hdr = register_net_sysctl(net, "net/netfilter", table);
93471+ hdr = register_net_sysctl(net, "net/netfilter", table);
93472+ } else
93473+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
93474 if (hdr == NULL)
93475 goto err_reg;
93476
93477@@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
93478 return 0;
93479
93480 err_reg:
93481- if (!net_eq(net, &init_net))
93482- kfree(table);
93483+ kfree(table);
93484 err_alloc:
93485 return -ENOMEM;
93486 }
93487diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
93488index ab92a36..bb4a528 100644
93489--- a/net/ipv6/output_core.c
93490+++ b/net/ipv6/output_core.c
93491@@ -8,8 +8,8 @@
93492
93493 void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
93494 {
93495- static atomic_t ipv6_fragmentation_id;
93496- int old, new;
93497+ static atomic_unchecked_t ipv6_fragmentation_id;
93498+ int id;
93499
93500 #if IS_ENABLED(CONFIG_IPV6)
93501 if (rt && !(rt->dst.flags & DST_NOPEER)) {
93502@@ -25,13 +25,10 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
93503 }
93504 }
93505 #endif
93506- do {
93507- old = atomic_read(&ipv6_fragmentation_id);
93508- new = old + 1;
93509- if (!new)
93510- new = 1;
93511- } while (atomic_cmpxchg(&ipv6_fragmentation_id, old, new) != old);
93512- fhdr->identification = htonl(new);
93513+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
93514+ if (!id)
93515+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
93516+ fhdr->identification = htonl(id);
93517 }
93518 EXPORT_SYMBOL(ipv6_select_ident);
93519
93520diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
93521index 18f19df..b46ada1 100644
93522--- a/net/ipv6/ping.c
93523+++ b/net/ipv6/ping.c
93524@@ -245,6 +245,22 @@ static struct pernet_operations ping_v6_net_ops = {
93525 };
93526 #endif
93527
93528+static struct pingv6_ops real_pingv6_ops = {
93529+ .ipv6_recv_error = ipv6_recv_error,
93530+ .ip6_datagram_recv_ctl = ip6_datagram_recv_ctl,
93531+ .icmpv6_err_convert = icmpv6_err_convert,
93532+ .ipv6_icmp_error = ipv6_icmp_error,
93533+ .ipv6_chk_addr = ipv6_chk_addr,
93534+};
93535+
93536+static struct pingv6_ops dummy_pingv6_ops = {
93537+ .ipv6_recv_error = dummy_ipv6_recv_error,
93538+ .ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl,
93539+ .icmpv6_err_convert = dummy_icmpv6_err_convert,
93540+ .ipv6_icmp_error = dummy_ipv6_icmp_error,
93541+ .ipv6_chk_addr = dummy_ipv6_chk_addr,
93542+};
93543+
93544 int __init pingv6_init(void)
93545 {
93546 #ifdef CONFIG_PROC_FS
93547@@ -252,11 +268,7 @@ int __init pingv6_init(void)
93548 if (ret)
93549 return ret;
93550 #endif
93551- pingv6_ops.ipv6_recv_error = ipv6_recv_error;
93552- pingv6_ops.ip6_datagram_recv_ctl = ip6_datagram_recv_ctl;
93553- pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
93554- pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
93555- pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
93556+ pingv6_ops = &real_pingv6_ops;
93557 return inet6_register_protosw(&pingv6_protosw);
93558 }
93559
93560@@ -265,11 +277,7 @@ int __init pingv6_init(void)
93561 */
93562 void pingv6_exit(void)
93563 {
93564- pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
93565- pingv6_ops.ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl;
93566- pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
93567- pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
93568- pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
93569+ pingv6_ops = &dummy_pingv6_ops;
93570 #ifdef CONFIG_PROC_FS
93571 unregister_pernet_subsys(&ping_v6_net_ops);
93572 #endif
93573diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
93574index cdaed47..515edde9 100644
93575--- a/net/ipv6/raw.c
93576+++ b/net/ipv6/raw.c
93577@@ -108,7 +108,7 @@ found:
93578 */
93579 static int icmpv6_filter(const struct sock *sk, const struct sk_buff *skb)
93580 {
93581- struct icmp6hdr *_hdr;
93582+ struct icmp6hdr _hdr;
93583 const struct icmp6hdr *hdr;
93584
93585 hdr = skb_header_pointer(skb, skb_transport_offset(skb),
93586@@ -378,7 +378,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
93587 {
93588 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
93589 skb_checksum_complete(skb)) {
93590- atomic_inc(&sk->sk_drops);
93591+ atomic_inc_unchecked(&sk->sk_drops);
93592 kfree_skb(skb);
93593 return NET_RX_DROP;
93594 }
93595@@ -406,7 +406,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
93596 struct raw6_sock *rp = raw6_sk(sk);
93597
93598 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
93599- atomic_inc(&sk->sk_drops);
93600+ atomic_inc_unchecked(&sk->sk_drops);
93601 kfree_skb(skb);
93602 return NET_RX_DROP;
93603 }
93604@@ -430,7 +430,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
93605
93606 if (inet->hdrincl) {
93607 if (skb_checksum_complete(skb)) {
93608- atomic_inc(&sk->sk_drops);
93609+ atomic_inc_unchecked(&sk->sk_drops);
93610 kfree_skb(skb);
93611 return NET_RX_DROP;
93612 }
93613@@ -602,7 +602,7 @@ out:
93614 return err;
93615 }
93616
93617-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
93618+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
93619 struct flowi6 *fl6, struct dst_entry **dstp,
93620 unsigned int flags)
93621 {
93622@@ -915,12 +915,15 @@ do_confirm:
93623 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
93624 char __user *optval, int optlen)
93625 {
93626+ struct icmp6_filter filter;
93627+
93628 switch (optname) {
93629 case ICMPV6_FILTER:
93630 if (optlen > sizeof(struct icmp6_filter))
93631 optlen = sizeof(struct icmp6_filter);
93632- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
93633+ if (copy_from_user(&filter, optval, optlen))
93634 return -EFAULT;
93635+ raw6_sk(sk)->filter = filter;
93636 return 0;
93637 default:
93638 return -ENOPROTOOPT;
93639@@ -933,6 +936,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
93640 char __user *optval, int __user *optlen)
93641 {
93642 int len;
93643+ struct icmp6_filter filter;
93644
93645 switch (optname) {
93646 case ICMPV6_FILTER:
93647@@ -944,7 +948,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
93648 len = sizeof(struct icmp6_filter);
93649 if (put_user(len, optlen))
93650 return -EFAULT;
93651- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
93652+ filter = raw6_sk(sk)->filter;
93653+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
93654 return -EFAULT;
93655 return 0;
93656 default:
93657diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
93658index 1aeb473..bea761c 100644
93659--- a/net/ipv6/reassembly.c
93660+++ b/net/ipv6/reassembly.c
93661@@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
93662
93663 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
93664 {
93665- struct ctl_table *table;
93666+ ctl_table_no_const *table = NULL;
93667 struct ctl_table_header *hdr;
93668
93669- table = ip6_frags_ns_ctl_table;
93670 if (!net_eq(net, &init_net)) {
93671- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
93672+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
93673 if (table == NULL)
93674 goto err_alloc;
93675
93676@@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
93677 /* Don't export sysctls to unprivileged users */
93678 if (net->user_ns != &init_user_ns)
93679 table[0].procname = NULL;
93680- }
93681+ hdr = register_net_sysctl(net, "net/ipv6", table);
93682+ } else
93683+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
93684
93685- hdr = register_net_sysctl(net, "net/ipv6", table);
93686 if (hdr == NULL)
93687 goto err_reg;
93688
93689@@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
93690 return 0;
93691
93692 err_reg:
93693- if (!net_eq(net, &init_net))
93694- kfree(table);
93695+ kfree(table);
93696 err_alloc:
93697 return -ENOMEM;
93698 }
93699diff --git a/net/ipv6/route.c b/net/ipv6/route.c
93700index 8d9a93ed..cd89616 100644
93701--- a/net/ipv6/route.c
93702+++ b/net/ipv6/route.c
93703@@ -2926,7 +2926,7 @@ struct ctl_table ipv6_route_table_template[] = {
93704
93705 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
93706 {
93707- struct ctl_table *table;
93708+ ctl_table_no_const *table;
93709
93710 table = kmemdup(ipv6_route_table_template,
93711 sizeof(ipv6_route_table_template),
93712diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
93713index 21b25dd..9a43e37 100644
93714--- a/net/ipv6/sit.c
93715+++ b/net/ipv6/sit.c
93716@@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
93717 static void ipip6_dev_free(struct net_device *dev);
93718 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
93719 __be32 *v4dst);
93720-static struct rtnl_link_ops sit_link_ops __read_mostly;
93721+static struct rtnl_link_ops sit_link_ops;
93722
93723 static int sit_net_id __read_mostly;
93724 struct sit_net {
93725@@ -1547,7 +1547,7 @@ static const struct nla_policy ipip6_policy[IFLA_IPTUN_MAX + 1] = {
93726 #endif
93727 };
93728
93729-static struct rtnl_link_ops sit_link_ops __read_mostly = {
93730+static struct rtnl_link_ops sit_link_ops = {
93731 .kind = "sit",
93732 .maxtype = IFLA_IPTUN_MAX,
93733 .policy = ipip6_policy,
93734diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
93735index 107b2f1..72741a9 100644
93736--- a/net/ipv6/sysctl_net_ipv6.c
93737+++ b/net/ipv6/sysctl_net_ipv6.c
93738@@ -40,7 +40,7 @@ static struct ctl_table ipv6_rotable[] = {
93739
93740 static int __net_init ipv6_sysctl_net_init(struct net *net)
93741 {
93742- struct ctl_table *ipv6_table;
93743+ ctl_table_no_const *ipv6_table;
93744 struct ctl_table *ipv6_route_table;
93745 struct ctl_table *ipv6_icmp_table;
93746 int err;
93747diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
93748index 6e1649d..75ddb4c 100644
93749--- a/net/ipv6/tcp_ipv6.c
93750+++ b/net/ipv6/tcp_ipv6.c
93751@@ -104,6 +104,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
93752 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
93753 }
93754
93755+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93756+extern int grsec_enable_blackhole;
93757+#endif
93758+
93759 static void tcp_v6_hash(struct sock *sk)
93760 {
93761 if (sk->sk_state != TCP_CLOSE) {
93762@@ -1399,6 +1403,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
93763 return 0;
93764
93765 reset:
93766+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93767+ if (!grsec_enable_blackhole)
93768+#endif
93769 tcp_v6_send_reset(sk, skb);
93770 discard:
93771 if (opt_skb)
93772@@ -1427,7 +1434,7 @@ ipv6_pktoptions:
93773 if (np->rxopt.bits.rxhlim || np->rxopt.bits.rxohlim)
93774 np->mcast_hops = ipv6_hdr(opt_skb)->hop_limit;
93775 if (np->rxopt.bits.rxtclass)
93776- np->rcv_tclass = ipv6_get_dsfield(ipv6_hdr(skb));
93777+ np->rcv_tclass = ipv6_get_dsfield(ipv6_hdr(opt_skb));
93778 if (ipv6_opt_accepted(sk, opt_skb)) {
93779 skb_set_owner_r(opt_skb, sk);
93780 opt_skb = xchg(&np->pktoptions, opt_skb);
93781@@ -1481,12 +1488,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
93782 TCP_SKB_CB(skb)->sacked = 0;
93783
93784 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
93785- if (!sk)
93786+ if (!sk) {
93787+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93788+ ret = 1;
93789+#endif
93790 goto no_tcp_socket;
93791+ }
93792
93793 process:
93794- if (sk->sk_state == TCP_TIME_WAIT)
93795+ if (sk->sk_state == TCP_TIME_WAIT) {
93796+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93797+ ret = 2;
93798+#endif
93799 goto do_time_wait;
93800+ }
93801
93802 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
93803 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
93804@@ -1538,6 +1553,10 @@ csum_error:
93805 bad_packet:
93806 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
93807 } else {
93808+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93809+ if (!grsec_enable_blackhole || (ret == 1 &&
93810+ (skb->dev->flags & IFF_LOOPBACK)))
93811+#endif
93812 tcp_v6_send_reset(NULL, skb);
93813 }
93814
93815diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
93816index f405815..45a68a6 100644
93817--- a/net/ipv6/udp.c
93818+++ b/net/ipv6/udp.c
93819@@ -53,6 +53,10 @@
93820 #include <trace/events/skb.h>
93821 #include "udp_impl.h"
93822
93823+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93824+extern int grsec_enable_blackhole;
93825+#endif
93826+
93827 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
93828 {
93829 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
93830@@ -420,7 +424,7 @@ try_again:
93831 if (unlikely(err)) {
93832 trace_kfree_skb(skb, udpv6_recvmsg);
93833 if (!peeked) {
93834- atomic_inc(&sk->sk_drops);
93835+ atomic_inc_unchecked(&sk->sk_drops);
93836 if (is_udp4)
93837 UDP_INC_STATS_USER(sock_net(sk),
93838 UDP_MIB_INERRORS,
93839@@ -666,7 +670,7 @@ csum_error:
93840 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
93841 drop:
93842 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
93843- atomic_inc(&sk->sk_drops);
93844+ atomic_inc_unchecked(&sk->sk_drops);
93845 kfree_skb(skb);
93846 return -1;
93847 }
93848@@ -724,7 +728,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
93849 if (likely(skb1 == NULL))
93850 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
93851 if (!skb1) {
93852- atomic_inc(&sk->sk_drops);
93853+ atomic_inc_unchecked(&sk->sk_drops);
93854 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
93855 IS_UDPLITE(sk));
93856 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
93857@@ -864,6 +868,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
93858 goto csum_error;
93859
93860 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
93861+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
93862+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
93863+#endif
93864 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
93865
93866 kfree_skb(skb);
93867diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
93868index 23ed03d..6532e67 100644
93869--- a/net/ipv6/xfrm6_policy.c
93870+++ b/net/ipv6/xfrm6_policy.c
93871@@ -207,11 +207,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
93872 }
93873 }
93874
93875-static inline int xfrm6_garbage_collect(struct dst_ops *ops)
93876+static int xfrm6_garbage_collect(struct dst_ops *ops)
93877 {
93878 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
93879
93880- xfrm6_policy_afinfo.garbage_collect(net);
93881+ xfrm_garbage_collect_deferred(net);
93882 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
93883 }
93884
93885@@ -324,19 +324,19 @@ static struct ctl_table xfrm6_policy_table[] = {
93886
93887 static int __net_init xfrm6_net_init(struct net *net)
93888 {
93889- struct ctl_table *table;
93890+ ctl_table_no_const *table = NULL;
93891 struct ctl_table_header *hdr;
93892
93893- table = xfrm6_policy_table;
93894 if (!net_eq(net, &init_net)) {
93895- table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
93896+ table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
93897 if (!table)
93898 goto err_alloc;
93899
93900 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
93901- }
93902+ hdr = register_net_sysctl(net, "net/ipv6", table);
93903+ } else
93904+ hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
93905
93906- hdr = register_net_sysctl(net, "net/ipv6", table);
93907 if (!hdr)
93908 goto err_reg;
93909
93910@@ -344,8 +344,7 @@ static int __net_init xfrm6_net_init(struct net *net)
93911 return 0;
93912
93913 err_reg:
93914- if (!net_eq(net, &init_net))
93915- kfree(table);
93916+ kfree(table);
93917 err_alloc:
93918 return -ENOMEM;
93919 }
93920diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
93921index 41ac7938..75e3bb1 100644
93922--- a/net/irda/ircomm/ircomm_tty.c
93923+++ b/net/irda/ircomm/ircomm_tty.c
93924@@ -319,11 +319,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
93925 add_wait_queue(&port->open_wait, &wait);
93926
93927 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
93928- __FILE__, __LINE__, tty->driver->name, port->count);
93929+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
93930
93931 spin_lock_irqsave(&port->lock, flags);
93932 if (!tty_hung_up_p(filp))
93933- port->count--;
93934+ atomic_dec(&port->count);
93935 port->blocked_open++;
93936 spin_unlock_irqrestore(&port->lock, flags);
93937
93938@@ -358,7 +358,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
93939 }
93940
93941 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
93942- __FILE__, __LINE__, tty->driver->name, port->count);
93943+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
93944
93945 schedule();
93946 }
93947@@ -368,12 +368,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
93948
93949 spin_lock_irqsave(&port->lock, flags);
93950 if (!tty_hung_up_p(filp))
93951- port->count++;
93952+ atomic_inc(&port->count);
93953 port->blocked_open--;
93954 spin_unlock_irqrestore(&port->lock, flags);
93955
93956 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
93957- __FILE__, __LINE__, tty->driver->name, port->count);
93958+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
93959
93960 if (!retval)
93961 port->flags |= ASYNC_NORMAL_ACTIVE;
93962@@ -447,12 +447,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
93963
93964 /* ++ is not atomic, so this should be protected - Jean II */
93965 spin_lock_irqsave(&self->port.lock, flags);
93966- self->port.count++;
93967+ atomic_inc(&self->port.count);
93968 spin_unlock_irqrestore(&self->port.lock, flags);
93969 tty_port_tty_set(&self->port, tty);
93970
93971 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
93972- self->line, self->port.count);
93973+ self->line, atomic_read(&self->port.count));
93974
93975 /* Not really used by us, but lets do it anyway */
93976 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
93977@@ -989,7 +989,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
93978 tty_kref_put(port->tty);
93979 }
93980 port->tty = NULL;
93981- port->count = 0;
93982+ atomic_set(&port->count, 0);
93983 spin_unlock_irqrestore(&port->lock, flags);
93984
93985 wake_up_interruptible(&port->open_wait);
93986@@ -1346,7 +1346,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
93987 seq_putc(m, '\n');
93988
93989 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
93990- seq_printf(m, "Open count: %d\n", self->port.count);
93991+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
93992 seq_printf(m, "Max data size: %d\n", self->max_data_size);
93993 seq_printf(m, "Max header size: %d\n", self->max_header_size);
93994
93995diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
93996index 168aff5..9d43132 100644
93997--- a/net/iucv/af_iucv.c
93998+++ b/net/iucv/af_iucv.c
93999@@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
94000
94001 write_lock_bh(&iucv_sk_list.lock);
94002
94003- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
94004+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
94005 while (__iucv_get_sock_by_name(name)) {
94006 sprintf(name, "%08x",
94007- atomic_inc_return(&iucv_sk_list.autobind_name));
94008+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
94009 }
94010
94011 write_unlock_bh(&iucv_sk_list.lock);
94012diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
94013index cd5b8ec..f205e6b 100644
94014--- a/net/iucv/iucv.c
94015+++ b/net/iucv/iucv.c
94016@@ -690,7 +690,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
94017 return NOTIFY_OK;
94018 }
94019
94020-static struct notifier_block __refdata iucv_cpu_notifier = {
94021+static struct notifier_block iucv_cpu_notifier = {
94022 .notifier_call = iucv_cpu_notify,
94023 };
94024
94025diff --git a/net/key/af_key.c b/net/key/af_key.c
94026index ab8bd2c..cd2d641 100644
94027--- a/net/key/af_key.c
94028+++ b/net/key/af_key.c
94029@@ -3048,10 +3048,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
94030 static u32 get_acqseq(void)
94031 {
94032 u32 res;
94033- static atomic_t acqseq;
94034+ static atomic_unchecked_t acqseq;
94035
94036 do {
94037- res = atomic_inc_return(&acqseq);
94038+ res = atomic_inc_return_unchecked(&acqseq);
94039 } while (!res);
94040 return res;
94041 }
94042diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
94043index 43dd752..63a23bc 100644
94044--- a/net/mac80211/cfg.c
94045+++ b/net/mac80211/cfg.c
94046@@ -820,7 +820,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
94047 ret = ieee80211_vif_use_channel(sdata, chandef,
94048 IEEE80211_CHANCTX_EXCLUSIVE);
94049 }
94050- } else if (local->open_count == local->monitors) {
94051+ } else if (local_read(&local->open_count) == local->monitors) {
94052 local->_oper_chandef = *chandef;
94053 ieee80211_hw_config(local, 0);
94054 }
94055@@ -2941,7 +2941,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
94056 else
94057 local->probe_req_reg--;
94058
94059- if (!local->open_count)
94060+ if (!local_read(&local->open_count))
94061 break;
94062
94063 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
94064@@ -3404,8 +3404,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
94065 if (chanctx_conf) {
94066 *chandef = chanctx_conf->def;
94067 ret = 0;
94068- } else if (local->open_count > 0 &&
94069- local->open_count == local->monitors &&
94070+ } else if (local_read(&local->open_count) > 0 &&
94071+ local_read(&local->open_count) == local->monitors &&
94072 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
94073 if (local->use_chanctx)
94074 *chandef = local->monitor_chandef;
94075diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
94076index 8412a30..6e00181 100644
94077--- a/net/mac80211/ieee80211_i.h
94078+++ b/net/mac80211/ieee80211_i.h
94079@@ -28,6 +28,7 @@
94080 #include <net/ieee80211_radiotap.h>
94081 #include <net/cfg80211.h>
94082 #include <net/mac80211.h>
94083+#include <asm/local.h>
94084 #include "key.h"
94085 #include "sta_info.h"
94086 #include "debug.h"
94087@@ -907,7 +908,7 @@ struct ieee80211_local {
94088 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
94089 spinlock_t queue_stop_reason_lock;
94090
94091- int open_count;
94092+ local_t open_count;
94093 int monitors, cooked_mntrs;
94094 /* number of interfaces with corresponding FIF_ flags */
94095 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
94096diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
94097index cc11759..11d5541 100644
94098--- a/net/mac80211/iface.c
94099+++ b/net/mac80211/iface.c
94100@@ -511,7 +511,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
94101 break;
94102 }
94103
94104- if (local->open_count == 0) {
94105+ if (local_read(&local->open_count) == 0) {
94106 res = drv_start(local);
94107 if (res)
94108 goto err_del_bss;
94109@@ -558,7 +558,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
94110 res = drv_add_interface(local, sdata);
94111 if (res)
94112 goto err_stop;
94113- } else if (local->monitors == 0 && local->open_count == 0) {
94114+ } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
94115 res = ieee80211_add_virtual_monitor(local);
94116 if (res)
94117 goto err_stop;
94118@@ -666,7 +666,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
94119 atomic_inc(&local->iff_promiscs);
94120
94121 if (coming_up)
94122- local->open_count++;
94123+ local_inc(&local->open_count);
94124
94125 if (hw_reconf_flags)
94126 ieee80211_hw_config(local, hw_reconf_flags);
94127@@ -704,7 +704,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
94128 err_del_interface:
94129 drv_remove_interface(local, sdata);
94130 err_stop:
94131- if (!local->open_count)
94132+ if (!local_read(&local->open_count))
94133 drv_stop(local);
94134 err_del_bss:
94135 sdata->bss = NULL;
94136@@ -841,7 +841,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
94137 }
94138
94139 if (going_down)
94140- local->open_count--;
94141+ local_dec(&local->open_count);
94142
94143 switch (sdata->vif.type) {
94144 case NL80211_IFTYPE_AP_VLAN:
94145@@ -908,7 +908,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
94146 }
94147 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
94148
94149- if (local->open_count == 0)
94150+ if (local_read(&local->open_count) == 0)
94151 ieee80211_clear_tx_pending(local);
94152
94153 /*
94154@@ -948,7 +948,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
94155
94156 ieee80211_recalc_ps(local, -1);
94157
94158- if (local->open_count == 0) {
94159+ if (local_read(&local->open_count) == 0) {
94160 ieee80211_stop_device(local);
94161
94162 /* no reconfiguring after stop! */
94163@@ -959,7 +959,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
94164 ieee80211_configure_filter(local);
94165 ieee80211_hw_config(local, hw_reconf_flags);
94166
94167- if (local->monitors == local->open_count)
94168+ if (local->monitors == local_read(&local->open_count))
94169 ieee80211_add_virtual_monitor(local);
94170 }
94171
94172diff --git a/net/mac80211/main.c b/net/mac80211/main.c
94173index 091088a..daf43c7 100644
94174--- a/net/mac80211/main.c
94175+++ b/net/mac80211/main.c
94176@@ -181,7 +181,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
94177 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
94178 IEEE80211_CONF_CHANGE_POWER);
94179
94180- if (changed && local->open_count) {
94181+ if (changed && local_read(&local->open_count)) {
94182 ret = drv_config(local, changed);
94183 /*
94184 * Goal:
94185diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
94186index 3401262..d5cd68d 100644
94187--- a/net/mac80211/pm.c
94188+++ b/net/mac80211/pm.c
94189@@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
94190 struct ieee80211_sub_if_data *sdata;
94191 struct sta_info *sta;
94192
94193- if (!local->open_count)
94194+ if (!local_read(&local->open_count))
94195 goto suspend;
94196
94197 ieee80211_scan_cancel(local);
94198@@ -59,7 +59,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
94199 cancel_work_sync(&local->dynamic_ps_enable_work);
94200 del_timer_sync(&local->dynamic_ps_timer);
94201
94202- local->wowlan = wowlan && local->open_count;
94203+ local->wowlan = wowlan && local_read(&local->open_count);
94204 if (local->wowlan) {
94205 int err = drv_suspend(local, wowlan);
94206 if (err < 0) {
94207@@ -116,7 +116,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
94208 WARN_ON(!list_empty(&local->chanctx_list));
94209
94210 /* stop hardware - this must stop RX */
94211- if (local->open_count)
94212+ if (local_read(&local->open_count))
94213 ieee80211_stop_device(local);
94214
94215 suspend:
94216diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
94217index 30d58d2..449ac8e 100644
94218--- a/net/mac80211/rate.c
94219+++ b/net/mac80211/rate.c
94220@@ -718,7 +718,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
94221
94222 ASSERT_RTNL();
94223
94224- if (local->open_count)
94225+ if (local_read(&local->open_count))
94226 return -EBUSY;
94227
94228 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
94229diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
94230index c97a065..ff61928 100644
94231--- a/net/mac80211/rc80211_pid_debugfs.c
94232+++ b/net/mac80211/rc80211_pid_debugfs.c
94233@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
94234
94235 spin_unlock_irqrestore(&events->lock, status);
94236
94237- if (copy_to_user(buf, pb, p))
94238+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
94239 return -EFAULT;
94240
94241 return p;
94242diff --git a/net/mac80211/util.c b/net/mac80211/util.c
94243index 2265445..ba14971 100644
94244--- a/net/mac80211/util.c
94245+++ b/net/mac80211/util.c
94246@@ -1452,7 +1452,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
94247 }
94248 #endif
94249 /* everything else happens only if HW was up & running */
94250- if (!local->open_count)
94251+ if (!local_read(&local->open_count))
94252 goto wake_up;
94253
94254 /*
94255@@ -1677,7 +1677,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
94256 local->in_reconfig = false;
94257 barrier();
94258
94259- if (local->monitors == local->open_count && local->monitors > 0)
94260+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
94261 ieee80211_add_virtual_monitor(local);
94262
94263 /*
94264diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
94265index 56d22ca..87c778f 100644
94266--- a/net/netfilter/Kconfig
94267+++ b/net/netfilter/Kconfig
94268@@ -958,6 +958,16 @@ config NETFILTER_XT_MATCH_ESP
94269
94270 To compile it as a module, choose M here. If unsure, say N.
94271
94272+config NETFILTER_XT_MATCH_GRADM
94273+ tristate '"gradm" match support'
94274+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
94275+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
94276+ ---help---
94277+ The gradm match allows to match on grsecurity RBAC being enabled.
94278+ It is useful when iptables rules are applied early on bootup to
94279+ prevent connections to the machine (except from a trusted host)
94280+ while the RBAC system is disabled.
94281+
94282 config NETFILTER_XT_MATCH_HASHLIMIT
94283 tristate '"hashlimit" match support'
94284 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
94285diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
94286index a1abf87..dbcb7ee 100644
94287--- a/net/netfilter/Makefile
94288+++ b/net/netfilter/Makefile
94289@@ -112,6 +112,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
94290 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
94291 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
94292 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
94293+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
94294 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
94295 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
94296 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
94297diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
94298index f771390..145b765 100644
94299--- a/net/netfilter/ipset/ip_set_core.c
94300+++ b/net/netfilter/ipset/ip_set_core.c
94301@@ -1820,7 +1820,7 @@ done:
94302 return ret;
94303 }
94304
94305-static struct nf_sockopt_ops so_set __read_mostly = {
94306+static struct nf_sockopt_ops so_set = {
94307 .pf = PF_INET,
94308 .get_optmin = SO_IP_SET,
94309 .get_optmax = SO_IP_SET + 1,
94310diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
94311index 4c8e5c0..5a79b4d 100644
94312--- a/net/netfilter/ipvs/ip_vs_conn.c
94313+++ b/net/netfilter/ipvs/ip_vs_conn.c
94314@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
94315 /* Increase the refcnt counter of the dest */
94316 ip_vs_dest_hold(dest);
94317
94318- conn_flags = atomic_read(&dest->conn_flags);
94319+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
94320 if (cp->protocol != IPPROTO_UDP)
94321 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
94322 flags = cp->flags;
94323@@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
94324
94325 cp->control = NULL;
94326 atomic_set(&cp->n_control, 0);
94327- atomic_set(&cp->in_pkts, 0);
94328+ atomic_set_unchecked(&cp->in_pkts, 0);
94329
94330 cp->packet_xmit = NULL;
94331 cp->app = NULL;
94332@@ -1188,7 +1188,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
94333
94334 /* Don't drop the entry if its number of incoming packets is not
94335 located in [0, 8] */
94336- i = atomic_read(&cp->in_pkts);
94337+ i = atomic_read_unchecked(&cp->in_pkts);
94338 if (i > 8 || i < 0) return 0;
94339
94340 if (!todrop_rate[i]) return 0;
94341diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
94342index 4f69e83..da2d8bf 100644
94343--- a/net/netfilter/ipvs/ip_vs_core.c
94344+++ b/net/netfilter/ipvs/ip_vs_core.c
94345@@ -559,7 +559,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
94346 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
94347 /* do not touch skb anymore */
94348
94349- atomic_inc(&cp->in_pkts);
94350+ atomic_inc_unchecked(&cp->in_pkts);
94351 ip_vs_conn_put(cp);
94352 return ret;
94353 }
94354@@ -1711,7 +1711,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
94355 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
94356 pkts = sysctl_sync_threshold(ipvs);
94357 else
94358- pkts = atomic_add_return(1, &cp->in_pkts);
94359+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
94360
94361 if (ipvs->sync_state & IP_VS_STATE_MASTER)
94362 ip_vs_sync_conn(net, cp, pkts);
94363diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
94364index c8148e4..eff604f 100644
94365--- a/net/netfilter/ipvs/ip_vs_ctl.c
94366+++ b/net/netfilter/ipvs/ip_vs_ctl.c
94367@@ -789,7 +789,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
94368 */
94369 ip_vs_rs_hash(ipvs, dest);
94370 }
94371- atomic_set(&dest->conn_flags, conn_flags);
94372+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
94373
94374 /* bind the service */
94375 if (!dest->svc) {
94376@@ -1657,7 +1657,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
94377 * align with netns init in ip_vs_control_net_init()
94378 */
94379
94380-static struct ctl_table vs_vars[] = {
94381+static ctl_table_no_const vs_vars[] __read_only = {
94382 {
94383 .procname = "amemthresh",
94384 .maxlen = sizeof(int),
94385@@ -2078,7 +2078,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
94386 " %-7s %-6d %-10d %-10d\n",
94387 &dest->addr.in6,
94388 ntohs(dest->port),
94389- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
94390+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
94391 atomic_read(&dest->weight),
94392 atomic_read(&dest->activeconns),
94393 atomic_read(&dest->inactconns));
94394@@ -2089,7 +2089,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
94395 "%-7s %-6d %-10d %-10d\n",
94396 ntohl(dest->addr.ip),
94397 ntohs(dest->port),
94398- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
94399+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
94400 atomic_read(&dest->weight),
94401 atomic_read(&dest->activeconns),
94402 atomic_read(&dest->inactconns));
94403@@ -2567,7 +2567,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
94404
94405 entry.addr = dest->addr.ip;
94406 entry.port = dest->port;
94407- entry.conn_flags = atomic_read(&dest->conn_flags);
94408+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
94409 entry.weight = atomic_read(&dest->weight);
94410 entry.u_threshold = dest->u_threshold;
94411 entry.l_threshold = dest->l_threshold;
94412@@ -3110,7 +3110,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
94413 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
94414 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
94415 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
94416- (atomic_read(&dest->conn_flags) &
94417+ (atomic_read_unchecked(&dest->conn_flags) &
94418 IP_VS_CONN_F_FWD_MASK)) ||
94419 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
94420 atomic_read(&dest->weight)) ||
94421@@ -3700,7 +3700,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
94422 {
94423 int idx;
94424 struct netns_ipvs *ipvs = net_ipvs(net);
94425- struct ctl_table *tbl;
94426+ ctl_table_no_const *tbl;
94427
94428 atomic_set(&ipvs->dropentry, 0);
94429 spin_lock_init(&ipvs->dropentry_lock);
94430diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
94431index 1383b0e..a486da1 100644
94432--- a/net/netfilter/ipvs/ip_vs_lblc.c
94433+++ b/net/netfilter/ipvs/ip_vs_lblc.c
94434@@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
94435 * IPVS LBLC sysctl table
94436 */
94437 #ifdef CONFIG_SYSCTL
94438-static struct ctl_table vs_vars_table[] = {
94439+static ctl_table_no_const vs_vars_table[] __read_only = {
94440 {
94441 .procname = "lblc_expiration",
94442 .data = NULL,
94443diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
94444index 3cd85b2..dfab2b8 100644
94445--- a/net/netfilter/ipvs/ip_vs_lblcr.c
94446+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
94447@@ -299,7 +299,7 @@ struct ip_vs_lblcr_table {
94448 * IPVS LBLCR sysctl table
94449 */
94450
94451-static struct ctl_table vs_vars_table[] = {
94452+static ctl_table_no_const vs_vars_table[] __read_only = {
94453 {
94454 .procname = "lblcr_expiration",
94455 .data = NULL,
94456diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
94457index f448471..995f131 100644
94458--- a/net/netfilter/ipvs/ip_vs_sync.c
94459+++ b/net/netfilter/ipvs/ip_vs_sync.c
94460@@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
94461 cp = cp->control;
94462 if (cp) {
94463 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
94464- pkts = atomic_add_return(1, &cp->in_pkts);
94465+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
94466 else
94467 pkts = sysctl_sync_threshold(ipvs);
94468 ip_vs_sync_conn(net, cp->control, pkts);
94469@@ -771,7 +771,7 @@ control:
94470 if (!cp)
94471 return;
94472 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
94473- pkts = atomic_add_return(1, &cp->in_pkts);
94474+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
94475 else
94476 pkts = sysctl_sync_threshold(ipvs);
94477 goto sloop;
94478@@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
94479
94480 if (opt)
94481 memcpy(&cp->in_seq, opt, sizeof(*opt));
94482- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
94483+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
94484 cp->state = state;
94485 cp->old_state = cp->state;
94486 /*
94487diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
94488index b75ff64..0c51bbe 100644
94489--- a/net/netfilter/ipvs/ip_vs_xmit.c
94490+++ b/net/netfilter/ipvs/ip_vs_xmit.c
94491@@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
94492 else
94493 rc = NF_ACCEPT;
94494 /* do not touch skb anymore */
94495- atomic_inc(&cp->in_pkts);
94496+ atomic_inc_unchecked(&cp->in_pkts);
94497 goto out;
94498 }
94499
94500@@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
94501 else
94502 rc = NF_ACCEPT;
94503 /* do not touch skb anymore */
94504- atomic_inc(&cp->in_pkts);
94505+ atomic_inc_unchecked(&cp->in_pkts);
94506 goto out;
94507 }
94508
94509diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
94510index 2d3030a..7ba1c0a 100644
94511--- a/net/netfilter/nf_conntrack_acct.c
94512+++ b/net/netfilter/nf_conntrack_acct.c
94513@@ -60,7 +60,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
94514 #ifdef CONFIG_SYSCTL
94515 static int nf_conntrack_acct_init_sysctl(struct net *net)
94516 {
94517- struct ctl_table *table;
94518+ ctl_table_no_const *table;
94519
94520 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
94521 GFP_KERNEL);
94522diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
94523index 0283bae..5febcb0 100644
94524--- a/net/netfilter/nf_conntrack_core.c
94525+++ b/net/netfilter/nf_conntrack_core.c
94526@@ -1614,6 +1614,10 @@ void nf_conntrack_init_end(void)
94527 #define DYING_NULLS_VAL ((1<<30)+1)
94528 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
94529
94530+#ifdef CONFIG_GRKERNSEC_HIDESYM
94531+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
94532+#endif
94533+
94534 int nf_conntrack_init_net(struct net *net)
94535 {
94536 int ret;
94537@@ -1628,7 +1632,11 @@ int nf_conntrack_init_net(struct net *net)
94538 goto err_stat;
94539 }
94540
94541+#ifdef CONFIG_GRKERNSEC_HIDESYM
94542+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
94543+#else
94544 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
94545+#endif
94546 if (!net->ct.slabname) {
94547 ret = -ENOMEM;
94548 goto err_slabname;
94549diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
94550index 1df1761..ce8b88a 100644
94551--- a/net/netfilter/nf_conntrack_ecache.c
94552+++ b/net/netfilter/nf_conntrack_ecache.c
94553@@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
94554 #ifdef CONFIG_SYSCTL
94555 static int nf_conntrack_event_init_sysctl(struct net *net)
94556 {
94557- struct ctl_table *table;
94558+ ctl_table_no_const *table;
94559
94560 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
94561 GFP_KERNEL);
94562diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
94563index 974a2a4..52cc6ff 100644
94564--- a/net/netfilter/nf_conntrack_helper.c
94565+++ b/net/netfilter/nf_conntrack_helper.c
94566@@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
94567
94568 static int nf_conntrack_helper_init_sysctl(struct net *net)
94569 {
94570- struct ctl_table *table;
94571+ ctl_table_no_const *table;
94572
94573 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
94574 GFP_KERNEL);
94575diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
94576index 0ab9636..cea3c6a 100644
94577--- a/net/netfilter/nf_conntrack_proto.c
94578+++ b/net/netfilter/nf_conntrack_proto.c
94579@@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
94580
94581 static void
94582 nf_ct_unregister_sysctl(struct ctl_table_header **header,
94583- struct ctl_table **table,
94584+ ctl_table_no_const **table,
94585 unsigned int users)
94586 {
94587 if (users > 0)
94588diff --git a/net/netfilter/nf_conntrack_proto_dccp.c b/net/netfilter/nf_conntrack_proto_dccp.c
94589index a99b6c3..cb372f9 100644
94590--- a/net/netfilter/nf_conntrack_proto_dccp.c
94591+++ b/net/netfilter/nf_conntrack_proto_dccp.c
94592@@ -428,7 +428,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
94593 const char *msg;
94594 u_int8_t state;
94595
94596- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
94597+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
94598 BUG_ON(dh == NULL);
94599
94600 state = dccp_state_table[CT_DCCP_ROLE_CLIENT][dh->dccph_type][CT_DCCP_NONE];
94601@@ -457,7 +457,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
94602 out_invalid:
94603 if (LOG_INVALID(net, IPPROTO_DCCP))
94604 nf_log_packet(net, nf_ct_l3num(ct), 0, skb, NULL, NULL,
94605- NULL, msg);
94606+ NULL, "%s", msg);
94607 return false;
94608 }
94609
94610@@ -486,7 +486,7 @@ static int dccp_packet(struct nf_conn *ct, const struct sk_buff *skb,
94611 u_int8_t type, old_state, new_state;
94612 enum ct_dccp_roles role;
94613
94614- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
94615+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
94616 BUG_ON(dh == NULL);
94617 type = dh->dccph_type;
94618
94619@@ -577,7 +577,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
94620 unsigned int cscov;
94621 const char *msg;
94622
94623- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
94624+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
94625 if (dh == NULL) {
94626 msg = "nf_ct_dccp: short packet ";
94627 goto out_invalid;
94628@@ -614,7 +614,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
94629
94630 out_invalid:
94631 if (LOG_INVALID(net, IPPROTO_DCCP))
94632- nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, msg);
94633+ nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, "%s", msg);
94634 return -NF_ACCEPT;
94635 }
94636
94637diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
94638index f641751..d3c5b51 100644
94639--- a/net/netfilter/nf_conntrack_standalone.c
94640+++ b/net/netfilter/nf_conntrack_standalone.c
94641@@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
94642
94643 static int nf_conntrack_standalone_init_sysctl(struct net *net)
94644 {
94645- struct ctl_table *table;
94646+ ctl_table_no_const *table;
94647
94648 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
94649 GFP_KERNEL);
94650diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
94651index 902fb0a..87f7fdb 100644
94652--- a/net/netfilter/nf_conntrack_timestamp.c
94653+++ b/net/netfilter/nf_conntrack_timestamp.c
94654@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
94655 #ifdef CONFIG_SYSCTL
94656 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
94657 {
94658- struct ctl_table *table;
94659+ ctl_table_no_const *table;
94660
94661 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
94662 GFP_KERNEL);
94663diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
94664index 85296d4..8becdec 100644
94665--- a/net/netfilter/nf_log.c
94666+++ b/net/netfilter/nf_log.c
94667@@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
94668
94669 #ifdef CONFIG_SYSCTL
94670 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
94671-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
94672+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
94673
94674 static int nf_log_proc_dostring(struct ctl_table *table, int write,
94675 void __user *buffer, size_t *lenp, loff_t *ppos)
94676@@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
94677 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
94678 mutex_unlock(&nf_log_mutex);
94679 } else {
94680+ ctl_table_no_const nf_log_table = *table;
94681+
94682 mutex_lock(&nf_log_mutex);
94683 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
94684 lockdep_is_held(&nf_log_mutex));
94685 if (!logger)
94686- table->data = "NONE";
94687+ nf_log_table.data = "NONE";
94688 else
94689- table->data = logger->name;
94690- r = proc_dostring(table, write, buffer, lenp, ppos);
94691+ nf_log_table.data = logger->name;
94692+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
94693 mutex_unlock(&nf_log_mutex);
94694 }
94695
94696diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
94697index f042ae5..30ea486 100644
94698--- a/net/netfilter/nf_sockopt.c
94699+++ b/net/netfilter/nf_sockopt.c
94700@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
94701 }
94702 }
94703
94704- list_add(&reg->list, &nf_sockopts);
94705+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
94706 out:
94707 mutex_unlock(&nf_sockopt_mutex);
94708 return ret;
94709@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
94710 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
94711 {
94712 mutex_lock(&nf_sockopt_mutex);
94713- list_del(&reg->list);
94714+ pax_list_del((struct list_head *)&reg->list);
94715 mutex_unlock(&nf_sockopt_mutex);
94716 }
94717 EXPORT_SYMBOL(nf_unregister_sockopt);
94718diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
94719index d92cc31..e46f350 100644
94720--- a/net/netfilter/nfnetlink_log.c
94721+++ b/net/netfilter/nfnetlink_log.c
94722@@ -82,7 +82,7 @@ static int nfnl_log_net_id __read_mostly;
94723 struct nfnl_log_net {
94724 spinlock_t instances_lock;
94725 struct hlist_head instance_table[INSTANCE_BUCKETS];
94726- atomic_t global_seq;
94727+ atomic_unchecked_t global_seq;
94728 };
94729
94730 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
94731@@ -563,7 +563,7 @@ __build_packet_message(struct nfnl_log_net *log,
94732 /* global sequence number */
94733 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
94734 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
94735- htonl(atomic_inc_return(&log->global_seq))))
94736+ htonl(atomic_inc_return_unchecked(&log->global_seq))))
94737 goto nla_put_failure;
94738
94739 if (data_len) {
94740diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
94741new file mode 100644
94742index 0000000..c566332
94743--- /dev/null
94744+++ b/net/netfilter/xt_gradm.c
94745@@ -0,0 +1,51 @@
94746+/*
94747+ * gradm match for netfilter
94748